Free shipping within Canada on orders over $150

Trinket M0: so #smol, so #blinky …

What's smaller than an SD card, runs MicroPython from its own tiny flash storage and has a greatbighuge bright Dotstar in the middle? The Adafruit Trinket M0 , of course!

Apart from the hard-wired DotStar colour LED in the middle, it's got a lot going on: capacitive touch sensors, analogue inputs (and one analogue output), USB mouse/keyboard emulation, built-in temperature sensor … I'm sure there's something I've missed.

Programming is easy: plug it into a USB port, and it appears as a flash drive. Open the main.py file, edit it, save it, and your new program's running!

Here's an entirely inessential script to indicate how I feel about anything other than spring and autumn temperatures. I'm at my best when this script's glowing green:

# Trinket M0 - scruss's perpetual Scottish thermometer
# for elmwood electronics - https://elmwood.to/
# CircuitPython 2.0.0

import board
import adafruit_dotstar as dotstar
import microcontroller
import time

# One pixel connected internally
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

######################### MAIN LOOP ##############################

message=''
colour=0x000000

while True:
    temperature=microcontroller.cpu.temperature
    # my own very grumpy temperature scale, in deg C
    if (temperature > 23.0):
        message='far too hot'
        colour=0xff0000     # red
    elif (temperature > 5.0):
        message='just right'
        colour=0x00ff00     # green
    else:
        message='a tad chilly'
        colour=0x0000ff     # blue
    
    dot[0]=colour               # display colour scale
    # send message to serial port with temperature
    print("Temperature: %5.1f deg C : %s" % (temperature, message))
    time.sleep(0.5)

CircuitPython, Adafruit's fork of MicroPython, is changing pretty quickly, so you'll probably want to look at updating CircuitPython to the latest version. That's easy as double-clicking the Trinket's reset button and dragging the new firmware file onto the board's icon.

For all its awesomeness, CircuitPython isn't exactly quick on the Trinket M0: expect reading sensors a few times a second. But you can also program the M0 in the Arduino IDE, and that's where you'd get real speed out of its ARM core.


Stewart Russell
Stewart Russell

Author

mostly harmless



Leave a comment

Comments will be approved before showing up.