The Python Game Book

code games. learn Python.

User Tools

Site Tools




circuit python

python dialect for microcontrollers, especially from Adafruit. Based on Python and micropython

Adafruit Bluefruit


2MB Flash disk storage

connection to serial console from linux

(because i did not get the MU editor running on linux)

  1. open a terminal using CTRL+ALT+T
  2. type ls /dev/ttyACM*
  3. read the ouput of this command and remember it. in my case, it was: /dev/ttyACM0 (in yellow font). The part to remember is therefore: ttyACM0
  4. check if screen is properly installed by typing screen in a console. if not installed, install it by typing sudo apt install screen
  5. make sure the adafruit device is connected via usb
  6. type in the console: sudo screen /dev/ttyACM0 115200 (this line must be repeated if you loose the connection to adafruit or reboot the computer)

code examples from github

find examples

  1. download the libs and examples folder (zpi archive:
  2. find those examples where the names begins with 'circuit' (matching the name of your board)
  3. make sure on your board is a lib folder and all necessary python libraries (see the import statements of the code example) are inside this lib folder
  4. those examples that only importing the “cp” should work without problems. Other examples may need other boards or additional hardware

examples that work with Bluefruit

rainbow light cycle

import board
import digitalio
import time
import neopixel
# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
pixel_pin = board.NEOPIXEL
# On a Raspberry pi, use this instead, not all pins are supported
# pixel_pin = board.D18
# The number of NeoPixels
num_pixels = 10
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(
    pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER
def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if pos < 0 or pos > 255:
        r = g = b = 0
    elif pos < 85:
        r = int(pos * 3)
        g = int(255 - pos * 3)
        b = 0
    elif pos < 170:
        pos -= 85
        r = int(255 - pos * 3)
        g = 0
        b = int(pos * 3)
        pos -= 170
        r = 0
        g = int(pos * 3)
        b = int(255 - pos * 3)
    return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
def rainbow_cycle(wait):
    for j in range(255):
        for i in range(num_pixels):
            pixel_index = (i * 256 // num_pixels) + j
            pixels[i] = wheel(pixel_index & 255)
while True:
    rainbow_cycle(0.001)  # rainbow cycle with 1ms delay per step

en/glossary/c/circuitpython.txt · Last modified: 2020/09/26 10:35 by horst