Feather M0 Express comes preloaded with CircuitPython. If you've since used it to run Arduino code, or you'd like to upgrade to the latest version, follow the instructions here to install the latest CircuitPython.
Connect to computer
Connect Feather M0 Express to your computer using a micro USB Cable. A drive named CIRCUITPY should appear on your computer.
Open the CIRCUITPY drive and create a folder named lib inside (if it doesn't already exist).
Libraries
The code for this project requires four software libraries. Click the link below to download the CircuitPython library bundle which matches the version of CircuitPython you are running. You can check the boot_out.txt file on the CIRCUITPY drive to determine the major version of CircuitPython you are using.
Unzip the library bundle, and open the lib folder inside.
You'll need to copy four libraries from this folder to the CIRCUITPY drive's lib folder:
- Locate the folder named adafruit_bitmap_font and copy it to the CIRCUITPY drive's lib folder.
- Locate the file named adafruit_debouncer.mpy and copy it to the CIRCUITPY drive's lib folder.
- Locate the folder named adafruit_display_text and copy it to the CIRCUITPY drive's lib folder.
- Locate the file named adafruit_displayio_ssd1306.mpy and copy it to the CIRCUITPY drive's lib folder.
Your CIRCUITPY drive's file structure should now look like this:
Copy the code below and paste it into a new text file.
Save the text file as code.py to the root of the CIRCUITPY drive, overwriting any preexisting file.
# SPDX-FileCopyrightText: 2020 Collin Cunningham for Adafruit Industries # # SPDX-License-Identifier: MIT import board from adafruit_debouncer import Debouncer import digitalio import displayio from adafruit_display_text import label import adafruit_displayio_ssd1306 from adafruit_bitmap_font import bitmap_font displayio.release_displays() # Set up button pins pin_a = digitalio.DigitalInOut(board.D9) pin_a.direction = digitalio.Direction.INPUT pin_a.pull = digitalio.Pull.UP pin_b = digitalio.DigitalInOut(board.D6) pin_b.direction = digitalio.Direction.INPUT pin_b.pull = digitalio.Pull.UP pin_c = digitalio.DigitalInOut(board.D5) pin_c.direction = digitalio.Direction.INPUT pin_c.pull = digitalio.Pull.UP button_a = Debouncer(pin_a) #9 button_b = Debouncer(pin_b) #6 button_c = Debouncer(pin_c) #5 # Load font font = bitmap_font.load_font('/mround-31.bdf') # Set up display & add group i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller display_bus = displayio.I2CDisplay(i2c, device_address=0x3C) display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32) group = displayio.Group() display.root_group = group # Add content to group default_text = "I VOTE !" text_area = label.Label(font, text=default_text, color=0xFFFFFF, x=0, y=17) group.append(text_area) while True: # Debounce buttons button_a.update() button_b.update() button_c.update() # Check for button presses & set text if button_a.fell: text_area.text = default_text text_area.x = 0 elif button_b.fell: text_area.text = "I VOTED!" text_area.x = 0 elif button_c.fell: text_area.text = "DID U?" text_area.x = 18 display.root_group = group
Usage & customization
Once you've saved code.py to your Feather M0 Express, you should see some white text flash across the screen before the larger I VOTE ! text appears. Use the OLED Featherwing's A, B, & C buttons to control what text appears on the display:
- Button A: I VOTE !
- Button B: I VOTED!
- Button C: DID U?
It's easy to customize these strings if you want the display to say something different. Open the code.py file and find line 43:
default_text = "I VOTE !" text_area = label.Label(font, text=default_text, color=0xFFFFFF, x=0, y=17) group.append(text_area)
This is where the initial I VOTE ! text is defined as default_text
. You can change the default text by editing the string within the quotation marks on line 43. This initial text is defined separately from the others because it's used in two different places – when defining the text_area
you see first, and when button A is pressed by the user.
Speaking of buttons, go to line 54 to see the code which executes when each of the buttons are pressed:
if button_a.fell: text_area.text = default_text text_area.x = 0 elif button_b.fell: text_area.text = "I VOTED!" text_area.x = 0 elif button_c.fell: text_area.text = "DID U?" text_area.x = 18
Whenever a button press or fell
is detected, the text_area.text
variable is changed.
The text for button B can be changed on line 58 & the text for button C can be changed on line 61.
Learn More
Of course, this is just the beginning of what you can do with Feather and the OLED Featherwing. If you're interested in learning more about CircuitPython, check out the full guide here. Or to jump right into learning about how to control the OLED Featherwing, head over to the Displayio library guide for all the details.
Text editor powered by tinymce.