Circuit Python at Noisebridge

From Noisebridge
Jump to navigation Jump to search

Circuit Python at Noisebridge[edit | edit source]

Welcome to this page, which will get you started with Circuit Python. You can do this any time, or with a group at Circuit Hacking Monday

Some links to get started:

Getting Started with Programming[edit | edit source]

Your board will automatically run the code found in the file code.py. Change the contents of that file to run different code. To use most hardware like NeoPixel LEDs, sensors, or motor drivers, you will need to install the appropriate library. Here's how to do that: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries. If you are OK using the CLI you can use circup. Remember to put the libraries you need in the /lib directory.


Documentation Links (thanks to todbot's Circuit Python Tricks!)[edit | edit source]

Things to Try![edit | edit source]

Having problems? Working examples of code for several suggestions can be found here: https://codeberg.org/headrotor/circuitpython-examples

Hooking up Hardware[edit | edit source]

We have soldering equipment so you can install the headers that came with your board. A good tip is to put the headers into a solderless breadboard before soldering so they are straight and even. Only install the outside headers (odd pins) if you want to use this in a solderless breadboard otherwise they will short! We have lots of hardware to play with including sensors and Neopixel LEDs; you will need the Adafruit library: https://learn.adafruit.com/circuitpython-essentials/circuitpython-neopixel

Tips and Tricks[edit | edit source]

Fun code examples from todbot's Circuit Python Tricks and QT Py Tricks

Note the button needs a pullup so be sure to set

switch = DigitalInOut(board.button)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

To see the names of the pins available, enter the REPL (using Mu or a terminal program

import board
dir(board)
  • For the LED library, pin 1 = IO1 and so forth... If you have installed only the outside headers, use pin IO3 (or odd numbered pins) so that there's something to connect to.
  • It is possible that the silkscreen labels for pins 12 and 13 have been swapped. Test to make sure!
  • Todbot has some fun code to play with, like synthesizers! https://gist.github.com/todbot/

Lolin S2 Mini pinout[edit | edit source]

Here is a mapping of Python pin names to the board pins (labeled in white on the bottom of the board). a "YES" in the "Touch" column means that touchio capacitive sensing can be used for that pin.

Lolin D2 Mini Pinout
Python Name Alternate Name Pin Number Touch
board.IO0 board.BUTTON (button)
board.IO1 1 YES
board.IO2 2 YES
board.IO3 3 YES
board.IO4 4 YES
board.IO5 5 YES
board.IO6 6 YES
board.IO7 board.SCK 7 YES
board.IO8 8 YES
board.IO9 board.MISO 9 YES
board.IO10 10 YES
board.IO11 board.MOSI 11 YES
board.IO12 12 YES
board.IO13 13 YES
board.IO14 14 YES
board.IO15 board.LED (LED)
board.IO16 16
board.IO17 17
board.IO18 18
board.IO21 21
board.IO33 board.SDA 33
board.IO34 34
board.IO35 board.SCL 35
board.IO36 36
board.IO37 37
board.IO38 38
board.IO39 39
board.IO40 40

Some alternate pin names are available, these don't correspond to anything on the board so no need to use them.

board.A0 board.IO3
board.D0 board.IO5
board.D1 board.IO35 
board.D2 board.IO33 
board.D3 board.IO18
board.D4 board.IO16
board.D5 board.IO7 
board.D6 board.IO9 
board.D7 board.IO11 
board.D8 board.IO13

Installing Circuit Python on Lolin S2 Mini boards[edit | edit source]

We have already done this for you! But you might need to do it again, or if you get your own boards, this is how we do it.


  1. Download the latest Circuit Python binary from here: https://circuitpython.org/board/lolin_s2_mini/
  2. Put the Lolin S2 board into tty mode: while holding down the "0" button, press and release the "RESET" button. Make sure there's a tty (com port) available.
  3. Install esptool.py frop PIP: python -m pip install esptool
  4. At the command line, enter
     esptool.py -p /dev/ttyACM0 --chip esp32s2 --baud 1000000 write_flash -z 0x0 adafruit-circuitpython-lolin_s2_mini-en_US-8.0.0-beta.6.bin
    (use the right serial port if not ttyACM0, also use filename of the binary you just downloaded: it will be more recent than 8.0.0)
  5. (if this doesn't work at first, try erasing flash with esptool.py --port PORT_NAME erase_flash, and/or repeat until it enumerates as /dev/ttyACM1)
  6. You can also do the previous 2 steps using https://adafruit.github.io/Adafruit_WebSerial_ESPTool/ or https://espressif.github.io/esptool-js/ but only on Chrome browsers. This can fix problems if esptool is not working.
  7. Reconnect your S2 Mini board, you should see a removable drive appear labeled CIRCUITPY
  8. You are now able to edit code.py, add libraries to /lib, and connect to the serial port (usually /dev/ttyACM0 on Mac/Linux or COM3 on Windows