This lesson uses the Gemma M0, Adafruit's current wearable microcontroller. The Gemma M0 is more powerful and easier to use than the original Gemma, with support for both CircuitPython and Arduino.

Kit List

  • Gemma M0 (or Gemma M0 Starter Pack)
  • USB cable (Micro-B)
  • Lithium polymer battery (3.7V 150mAh or similar) with JST connector
  • Conductive thread (2-ply or 3-ply stainless steel)
  • 3-5 x Flora NeoPixels (sewable RGB LEDs)
  • Needles (embroidery needles work well)
  • Scissors
  • Alligator/crocodile clips (for prototyping)
  • Fabric or garment to stitch onto
Alternative boards: This lesson also works with the Circuit Playground Express (great for beginners - has built-in NeoPixels and sensors) or QT Py (smaller form factor).

Starter: Understanding Microcontrollers (10 mins)

What is a Microcontroller?

A microcontroller is a small computer on a single chip. Unlike a full computer, it's designed to do one specific task - running the code you upload to it. Microcontrollers are everywhere: in washing machines, cars, toys, and of course, wearable technology!

What is Gemma M0?

The Gemma M0 is a tiny, sewable microcontroller designed for wearable projects. Key features:

  • Processor: ATSAMD21E18 (32-bit ARM Cortex M0+) running at 48MHz
  • Memory: 256KB Flash, 32KB RAM - enough for complex projects
  • Programming: CircuitPython (recommended for beginners) or Arduino
  • Power: USB or 3.7V LiPo battery via JST connector
  • Size: 27mm diameter - perfect for wearables
  • Built-in: Red LED, RGB DotStar LED, on/off switch

Gemma M0 vs Original Gemma

Feature Gemma M0 (Current) Original Gemma (Legacy)
Processor 32-bit ARM (48MHz) 8-bit ATtiny85 (8MHz)
Memory 256KB Flash / 32KB RAM 8KB Flash / 512B RAM
CircuitPython Yes No
NeoPixels supported Hundreds ~40-100

Setting Up Your Gemma M0

Option A: CircuitPython (Recommended for beginners)

CircuitPython lets you code by simply editing a file - no compiling needed!

  1. Connect Gemma M0 to your computer via USB
  2. It should appear as a drive called CIRCUITPY
  3. If not, visit the CircuitPython download page and follow the installation instructions
  4. Download the CircuitPython Library Bundle and copy the neopixel.mpy file to the lib folder on your CIRCUITPY drive

Option B: Arduino IDE

  1. Install the Arduino IDE
  2. Add Adafruit board support: Go to Preferences → Additional Board Manager URLs, add: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
  3. Install "Adafruit SAMD Boards" from Board Manager
  4. Install "Adafruit NeoPixel" library from Library Manager
  5. Select "Adafruit Gemma M0" from Tools → Board

Test Your Board: Blinky

Before starting your project, let's make sure everything works!

CircuitPython Version

Save this as code.py on your CIRCUITPY drive:

import board
import digitalio
import time

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)

Arduino Version

// Blink the built-in red LED on Gemma M0
const int LED_PIN = 13;

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

NeoPixel Basics

NeoPixels are individually addressable RGB LEDs - each pixel can be any colour! The sewable Flora NeoPixels are perfect for wearables.

Wiring NeoPixels

  • + (Power) → Gemma 3V or Vout
  • - (Ground) → Gemma GND
  • → (Data In) → Gemma D1 (first pixel only)
  • → (Data Out) → Next pixel's Data In (chain them together)
Tip: Always prototype with alligator clips before sewing! It's much easier to fix mistakes.

NeoPixel Code - CircuitPython

import board
import neopixel
import time

# Set up NeoPixels on pin D1, with 3 pixels
pixels = neopixel.NeoPixel(board.D1, 3, brightness=0.3)

while True:
    # Red
    pixels.fill((255, 0, 0))
    time.sleep(1)

    # Green
    pixels.fill((0, 255, 0))
    time.sleep(1)

    # Blue
    pixels.fill((0, 0, 255))
    time.sleep(1)

    # Rainbow cycle
    for i in range(len(pixels)):
        pixels[i] = (255, 0, 0)
        time.sleep(0.2)
    for i in range(len(pixels)):
        pixels[i] = (0, 255, 0)
        time.sleep(0.2)
    for i in range(len(pixels)):
        pixels[i] = (0, 0, 255)
        time.sleep(0.2)

NeoPixel Code - Arduino

#include <Adafruit_NeoPixel.h>

#define PIN        1    // Data pin connected to NeoPixels
#define NUMPIXELS  3    // Number of NeoPixels

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.setBrightness(50);  // 0-255, keep low for battery life
}

void loop() {
  // Red
  pixels.fill(pixels.Color(255, 0, 0));
  pixels.show();
  delay(1000);

  // Green
  pixels.fill(pixels.Color(0, 255, 0));
  pixels.show();
  delay(1000);

  // Blue
  pixels.fill(pixels.Color(0, 0, 255));
  pixels.show();
  delay(1000);
}

Main Activity: Create Your Wearable (45+ mins)

Task 1: Design Your Circuit (10 mins)

Before sewing, plan your project on paper:

  1. Sketch your design - Where will the Gemma go? Where will each NeoPixel be?
  2. Draw the connections - Use different colours for power (+), ground (-), and data
  3. Check for crossings - Conductive thread can't cross itself without causing a short circuit!
  4. Measure distances - Make sure you have enough thread
Design tip: Keep the Gemma somewhere accessible (e.g., inside pocket or hem) so you can easily connect USB for reprogramming.

Task 2: Prototype with Clips (10 mins)

Use alligator clips to build your circuit temporarily:

  1. Connect your NeoPixels to the Gemma using alligator clips
  2. Upload your code and test that all pixels light up
  3. Fix any issues before you start sewing

Task 3: Sew Your Circuit (25+ mins)

Now for the fun part - stitching with conductive thread!

Sewing Tips:

  • Use a running stitch - small, even stitches work best
  • Loop through holes multiple times - at least 3 times for good electrical contact
  • Tie secure knots - dab with clear nail polish to prevent unraveling
  • Keep threads separated - at least 3mm apart to avoid shorts
  • Test as you go - connect power after each connection to verify
  • Cut threads cleanly - loose ends can cause shorts

Task 4: Customise Your Code

Once your circuit is sewn and working, experiment with different patterns:

  • Fade colours in and out
  • Create a rainbow animation
  • React to button presses (Gemma M0 has a built-in button!)
  • Change patterns with different gestures

Extension Ideas

  • Add sensors: Connect a light sensor to make pixels respond to ambient light
  • Sound reactive: Add a microphone to pulse with music
  • Motion activated: Use an accelerometer to change colours when you move
  • Wireless control: Upgrade to a Feather board with Bluetooth for app control

Troubleshooting

Problem Solution
NeoPixels won't light up Check power and ground connections. Ensure data wire goes to Data IN (arrow pointing away from Gemma)
Only first pixel works Check data connection between first and second pixel
Wrong colours Some NeoPixels are RGB, others are GRB - check the library settings
Flickering Usually a loose connection - check all stitched joints
CIRCUITPY drive not appearing Double-click the reset button on Gemma M0 to enter bootloader mode