Want more of a challenge? If you code the board in CircuitPython, you can access the hidden temperature sensor and use it to control the colors of your pixels!

Adafruit's Anne Berela has written code that will turn the lights red if the temperature is above 65 degrees and blue if it goes below that. 

If you are new to CircuitPython, there are few steps to go through to use this code. Follow the instructions below or go here to learn more about installing and programming in CircuitPython.

Loading CircuitPython on Your Gemma M0

This project was tested using CircuitPython 4. If you're not sure if that's what you are running on your Gemma M0, plug in your board, go to CIRCUITPY drive, and check the folder marked boot_out.txt. It will tell you what version is loaded on the board. The latest stable version should be fine.

If you need to install or update CircuitPython, tap the reset button once or twice to enter bootloader mode.

Once successful, the RGB LED on the board will flash red and then stay green. A new drive will show up on your computer called GEMMABOOT.

Then click the button below, which will take you to the download page for the latest version of CircuitPython. Save that file to the GEMMABOOT drive on your computer.

You've now installed CircuitPython on your board! The drive you will be working with from here on is called CIRCUITPY.

Next, you'll need to install some libraries. CircuitPython libraries are separate files designed to work with CircuitPython code. CircuitPython programs require a lot of information to run. CircuitPython is so simple to use because most of this information is processed in the background and stored in libraries. Some libraries are built into CircuitPython. Others are downloaded and stored on your CIRCUITPY drive in a folder called lib.

Click the button below and download the bundle for use with your version of CircuitPython. Save it on your computer, not the board! You'll only need two files from this huge folder.

Look for these two files -- neopixel.mpy and adafruit_dotstar.mpy -- and drag them to the lib folder on the Gemma M0.

Install the Mu Editor

Adafruit recommends using the Mu editor on your computer to work with CircuitPython code. Instructions for downloading it to your computer can be found here or the button below.

Once you've got it installed, open it up. You're ready to copy the code to make your temperature sensor lights work!

Temperature Sensor Code

Copy and paste the code below into your editor or click the download link.

# Gemma M0 Onchip Temperature Sensor
# Project by Kathy Ceceri
# CircuitPython by Anne Barela
# Adafruit Industries, 2019

import time
import board
import microcontroller
import neopixel
import adafruit_dotstar

ROOM_TEMP = 65.0  # Set this to the temp to change from blue to red (F)

# Set up NeoPixel strand
pixels = neopixel.NeoPixel(board.D1,  # NeoPixels on pin D1
                           4,         # Number of Pixels
                           brightness=0.2)   # Change from 0.0 to 1.0

# For the Gemma M0 onboard DotStar LED
dotstar = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

def deg_f(deg_c):  # Convert Celcius to Fahrenheit
    return(deg_c * 9 / 5) + 32.0

while True:
    temp = deg_f(microcontroller.cpu.temperature)
    if temp > ROOM_TEMP:
        pixels.fill((255, 0, 0))   # (255,0,0) is red
        dotstar.fill((255, 0, 0))  # Set to red
    else:
        pixels.fill((0, 0, 255))   # (0,0,255) is blue
        dotstar.fill((0, 0, 255))  # Set to blue

    time.sleep(1.0)  # Wait 1 second

If you need to make any adjustments, such as changing the "room temperature" cut-off that triggers the colors (ROOM_TEMP), or you have a different number of pixels attached to your Gemma M0, you can type them right into the code.

Then click the Save button at the top of the Mu editor and save this file as code.py on your CIRCUITPY drive.

If everything is working, the onboard LED (and the external NeoPixels if they're connected) will turn red.

Test Your Code

Now disconnect the Gemma from the computer and connect it to the battery holder. Take the board outside (if it's chilly), place a bag of frozen veggies on the board, or just toss it in the freezer. If it's working, the lights should go from red to blue and back again as it cools down and warms up.

If it's not, or if it's working but a little wonky, check your conductive thread connections or your batteries.

Like any tech project, it takes some fiddling to make the hardware and software cooperate. Enjoy playing with your temp-sensing headgear!

This guide was first published on Dec 25, 2019. It was last updated on Dec 25, 2019.

This page (Advanced Version - CircuitPython Chill Sensor) was last updated on Oct 12, 2021.

Text editor powered by tinymce.