GEMMA M0 boards can run CircuitPython — a different approach to programming compared to Arduino sketches. In fact, CircuitPython comes factory pre-loaded on GEMMA M0. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained in the Adafruit GEMMA M0 guide.

These directions are specific to the “M0” GEMMA board. The original GEMMA with an 8-bit AVR microcontroller doesn’t run CircuitPython…for those boards, use the Arduino sketch on the “Arduino code” page of this guide.

Below is CircuitPython code that works similarly (though not exactly the same) as the Arduino sketch shown on a prior page. To use this, plug the GEMMA M0 into USB…it should show up on your computer as a small flash drive…then edit the file “main.py” with your text editor of choice. Select and copy the code below and paste it into that file, entirely replacing its contents (don’t mix it in with lingering bits of old code). When you save the file, the code should start running almost immediately (if not, see notes at the bottom of this page).

If GEMMA M0 doesn’t show up as a drive, follow the GEMMA M0 guide link above to prepare the board for CircuitPython.

# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time

import board
from digitalio import DigitalInOut, Direction, Pull

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

led = DigitalInOut(board.D2)
led.direction = Direction.OUTPUT

while True:
    if button.value:
        led.value = True  # check if the pushbutton is pressed.
    else:
        led.value = False  # turn LED off

    time.sleep(0.01)  # debounce delay

This guide was first published on Apr 30, 2014. It was last updated on Apr 30, 2014.

This page (CircuitPython Code) was last updated on Sep 18, 2023.

Text editor powered by tinymce.