Overview

The Gemma M0 is a super small microcontroller board, with just enough to build many simple projects. It may look small and cute: round, about the size of a quarter, with friendly alligator-clip sew pads. But do not be fooled! The Gemma M0 is incredibly powerful! We've taken the same form factor we used for the original ATtiny85-based Gemma and gave it a power up. The Gemma M0 has swapped out the lightweight ATtiny85 for a ATSAMD21E18 powerhouse.

It will super-charge your wearables! It's just as small, and it's easier to use, so you can do more.

The most exciting part of the Gemma M0 is that while you can use it with the Arduino IDE, we are shipping it with CircuitPython on board. When you plug it in, it will show up as a very small disk drive with main.py on it. Edit main.py with your favorite text editor to build your project using Python, the most popular programming language. No installs, IDE or compiler needed, so you can use it on any computer, even ChromeBooks or computers you can't install software on. When you're done, unplug the Gemma M0 and your code will go with you.

Here are some of the updates you can look forward to when using Gemma M0:

  • Same size, form-factor, and pinout as classic Gemma
  • Updating ATtiny85 8-bit AVR for ATSAMD21E18 32-bit Cortex M0+
  • 256KB Flash - 8x as much as 8 KB on ATtiny85
  • 32 KB RAM - 64x as much as 512 bytes on ATtiny85
  • 48 MHz 32 bit processor - 6x as fast as ATtiny85 (not even taking into account 32-bit speedups)
  • Native USB supported by every OS - can be used in Arduino or CircuitPython as USB serial console, Keyboard/Mouse HID, even a little disk drive for storing Python scripts. (ATtiny85 does not have native USB)
  • Can be used with Arduino IDE or CircuitPython
  • Built in RGB DotStar LED
  • Three big-hole sew-pads can be used for conductive thread or alligator-clips for fast prototyping
    • Each I/O pad can be used for 12-bit analog input, or digital input/output with internally connected pullups or pulldowns
    • We gave the M0 pads the exact same names as the original Gemma so all your existing Arduino code will work exactly the same as-is without changes
    • True analog output on one I/O pad - can be used to play 10-bit quality audio clips
    • Two high speed PWM outputs on other two I/O Pads - for servos, LEDs, etc
    • All three pads can also be used as hardware capacitive touch sensors with no additional components required
    • Can drive NeoPixels or DotStars on any pins, with enough memory to drive 8000+ pixels. DMA-NeoPixel support on one pin so you can drive pixels without having to spend any processor time on it.
    • Native hardware I2C or Serial available on two pads so you can connect to any I2C or Serial device with true hardware support (no annoying bit-banging)
  • Same Reset switch for starting your project code over
  • On/Off switch built in
  • JST battery connector for plugging in AAA's or LiPoly battery (no built-in LiPoly charging so it is safe to use with NiMH/Alkalines)

Each order comes with one fully assembled and tested Gemma M0 with CircuitPython & example code programmed in.

So what are you waiting for? Pick up a Gemma M0 today and be amazed at how easy and fast it is to get started with Gemma and CircuitPython!

Guided Tour

Let me take you on a tour of your Gemma M0! Each Gemma M0 is assembled here at Adafruit and comes chock-full of good design to make it a joy to use.

  • Micro B USB connector - We went with the tried and true micro-B USB connector for power and/or USB communication (bootloader, serial, HID, etc). Use with any computer with a standard data/sync cable.
  • RGB DotStar LED - Instead of an always-on green LED we provide a full RGB LED. You can set it to any color in the rainbow. It will also help you know when the bootloader is running (it will turn green) or if it failed to initialize USB when connected to a computer (it will turn green). By default after you boot up the Gemma M0 it will turn a lovely violet color.
  • Red #13 LED - this LED does double duty. Its connected with a series resistor to the digital #13 GPIO pin. It pulses nicely when the Gemma is in bootloader mode, and its also handy for when you want an indicator LED.
  • JST Battery Input - take your Gemma anywhere and power it from an external battery. This pin can take up 6V DC input, and has reverse-polarity, over-curent and thermal protections. The circuitry inside will use either the battery or USB power, safely switching from one to the other. If both are connected, it will use whichever has the higher voltage. Works great with a Lithium Polymer battery or our 3xAAA battery packs with a JST connector on the end. There is no built in battery charging (so that you can use Alkaline or Lithium batteries safely)
  • Vout (Voltage Output) - This pin will give you either the battery power or USB power, whichever has a higher voltage. Its great when you want to power something like NeoPixels, that might use more than the 500mA available from the onboard regulator
  • 3V Regulator - The on-board voltage regulator can supply up to 500mA at a steady 3.3V from up to 6VDC
  • Sewing and Alligator clip friendly pads - You can easily sew to these pads, and they're gold plated so they wont corrode (oxidize). You can also use alligator clips or solder directly to them.
  • 3 General Purpose I/O (GPIO) Pads! - 3 GPIO pins, at 3V logic, check the next section for a detailed pinout guide
  • Reset Button - an onboard reset button will launch the bootloader when pressed and the Gemma is plugged into a computer. If it is not connected to a computer, it's smart enough to go straight to the program.
  • On/Off switch - Lets you turn on/off your project, it will control both the Gemma and the Vout pad. This switch can switch up to about 500mA of current, so if you are driving a huge number of servos or NeoPixels, connect power to those power-greedy parts externally.

Pinouts

JST Battery Input

There is no battery INPUT pin on the Gemma. You can connect a battery via the JST jack. We have found that Lipoly batteries, coin-cells, and AAA's work great. You can also make your own battery input pack using a plain JST cable. And use a JST extension cable if necessary.

You can plug anything from around 4 VDC up to 6 VDC. That means any single-cell LiPoly, or 3-4 AAA or AA batteries. This input is polarity protected. Gemma and DotStar LED light up, you're good to go. You can turn off the battery with the on/off switch, which will completely disconnect power on the Gemma M0.

Power Pads

Half of the pads on the Gemma M0 are related to power in and out: 3Vo , Vout and GND

  • Vout - This is a voltage OUTPUT pin, it will be connected to either the USB power or the battery input, whichever has the higher voltage. This output does not connect to the regulator so you can draw as much current as your USB port / Battery can provide (in general, thats about 500mA)
  • 3Vo - This is the 3.3V OUTPUT pad from the voltage regulator. It can provide up to 500mA at a steady 3.3V. Good for sensors or small LEDs or other 3V devices.
  • GND is the common ground pin, used for logic and power. It is connected to the USB ground and the power regulator, etc. This is the pin you'll want to use for any and all ground connections

Input/Output Pads

Next we will cover the 3 GPIO (General Purpose Input Ouput) pins! For reference you may want to also check out the datasheet-reference in the downloads section for the core ATSAMD21E18 pin. We picked pins that have a lot of capabilities.

Common to all pads

All the GPIO pads can be used as digital inputs, digital outputs, for LEDs, buttons and switches. In additon, all can be used as analog inputs (12-bit ADC) or hardware capacitive touch. All pads can also be used as hardware interrupts inputs.

Each pad can provide up to ~20mA of current. Don't connect a motor or other high-power component directly to the pins! Instead, use a transistor to power the DC motor on/off

On a Gemma M0, the GPIO are 3.3V output level, and should not be used with 5V inputs. In general, most 5V devices are OK with 3.3V output though.

The three pads are completely 'free' pins, they are not used by the USB connection, LEDs, DotStar, etc so you never have to worry about the USB interface interfering with them when programming

Unique pad capabilities

  • Pad #0 / A2  - this is connected to PA04 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, capacitive touch, analog input (use 'A2'),  PWM output, and is also used for I2C data (SDA), and hardware Serial RX.
  • Pad #1 / A0  - this is connected to PA02 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, capacitive touch, analog input (use 'A0'),  and true analog (10-bit DAC) output. It cannot be used as PWM output.
  • Pad #2 / A1  - this is connected to PA05 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, capacitive touch, analog input (use 'A1'),  PWM output, and is also used for I2C clock (SCL), and hardware Serial TX.

Secret SWD and Reset Pads

On the bottom of the Gemma M0 you will see three small pads. These are used for our programming/test but you can use them too.

Starting from the pad closest to the edge there is:

  • SWDIO
  • SWCLK
  • Reset

On the off chance you want to reprogram your Gemma M0 or debug it using a Cortex M0 debug/programmer, you will need to solder/connect to these pads. We use them for testing and you will likely never need it but they are there if you do!

Windows Driver Installation

Mac and Linux do not require drivers, only Windows folks need to do this step

Before you plug in your board, you'll need to possibly install a driver!

Click below to download our Driver Installer

Download and run the installer

Run the installer! Since we bundle the SiLabs and FTDI drivers as well, you'll need to click through the license

Select which drivers you want to install, we suggest selecting all of them so you don't have to do this again!

By default, we install the Feather 32u4 , Feather M0, Flora, Gemma M0, Circuit Playground and Trinket / Pro Trinket / Gemma / USBtinyISP drivers.

You can also, optionally, install the Arduino Gemma (different than the Adafruit Gemma!), Huzzah and Metro drivers

Click Install to do the installin'

Manual Driver Installation

If windows needs the driver files (inf/cat) for some reason you can get all the drivers in a zip by clicking below:

And point windows to the Drivers folder when it asks for the driver location

CircuitPython

CircuitPython is a derivative of MicroPython designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. The Gemma M0 is the first board that comes pre-loaded with CircuitPython. Simply copy and edit files on the CIRCUITPY drive to iterate.

Your Gemma M0 already comes with CircuitPython but maybe there's a new version, or you overwrote your Gemma M0 with Arduino code! In that case, see the below for how to reinstall or update CircuitPython. Otherwise you can skip this and go straight to the next page

Reinstalling and Updating CircuitPython

The latest builds of CircuitPython are available from the GitHub release page. Binaries for different boards are listed under the Downloads section. Pick the one that matches your board such as adafruit-circuitpython-gemma_m0-1.0.0.bin for the Gemma M0.

Files ending in .uf2 can be flashed onto a virtual drive when in bootloader mode. Files that end with .bin can be flashed with esptool.py or bossac.

You will see a list of all available flavors of CircuitPython. Since we support a lot of different hardware, we have a long list of available downloads!

See below for which file to download!

Flashing

Flashing is the process of updating the CircuitPython core. It isn't needed for updating your own code. There are two available methods: UF2 and bossac UF2 flashing is only available on newer boards including the Gemma M0. Flashing via bossac is possible with both the UF2 bootloader and the original "Arduino" one. We recommend using UF2 if you can. If UF2 fails, or is not available, try bossac.

Regardless of what method you use, you must first get the board into the bootloader mode. This is done by double clicking the reset button. The board is in bootloader mode when the red led fades in and out. Boards with the status neopixel will also show USB status while the red led fades. Green means USB worked while red means the board couldn't talk to the computer. The first step to troubleshooting a red neopixel is trying a different USB cable to make sure its not a charge-only cable.

Flashing UF2

The Gemma M0 comes with a new bootloader called UF2 that makes flashing CircuitPython even easier than before. This beta bootloader allows you to drag so-called ".uf2" type files onto the BOOT drive. For more information, check out our UF2 bootloader page.

Start by ejecting or "safely remove" the CIRCUITPY drive if its present, then double-clicking the reset button while it is plugged into your computer. You should see a new disk drive 'pop up' called GEMMABOOT or similar, and the DotStar on your board glow green.

The drive will contain a few files. If you want to make a 'backup' of the current firmware on the device, drag-off and save the CURRENT.UF2 file. Other that that you can ignore the index.htm and info_uf2.txt files. They cannot be deleted and are only for informational purposes.

Next up, find the Gemma M0 UF2 file in the github downloads list:

Click to download and save the file onto your Desktop or somewhere else you can find it

Then drag the uf2 file into the GEMMABOOT drive.

Once the full file has been received, the board will automatically restart into CircuitPython. Your computer may warn about ejecting the drive early, if it does, simply ignore it because the board made sure the file was received ok.

Flashing with BOSSAC

This method is only recommended if you can't use UF2 for some reason!

To flash with bossac (BOSSA's command line tool) first download the latest version from here. The mingw32 version is for Windows, apple-darwin for Mac OSX and various linux options for Linux. Once downloaded, extract the files from the zip and open the command line to the directory with bossac.

bossac -e -w -v -R ~/Downloads/adafruit-circuitpython-gemma_m0-1.0.0.bin

This will erase the chip, write the given file, verify the write and Reset the board. After reset, CircuitPython should be running. Newer boards with the UF2 bootloader may cause a warning of an early eject of a USB drive but just ignore it. Nothing important was being written to the drive.

After flashing

After a successful flash by bossac or UF2 you should see a CIRCUITPY drive appear.

CircuitPython Blinky

Let's get blinky going with CircuitPython to explore the way we can write code and confirm everything is working as expected.

code.py

After plugging in a board with CircuitPython into your computer a CIRCUITPY drive will appear. At first, the drive may be empty but you can create and edit files on it just like you would on a USB drive. On here, you can save a code.py (code.txt and main.py also work) file to run every time the board resets. This is the CircuitPython equivalent of an Arduino sketch. However, all of the compiling is done on the board itself. All you need to do is edit the file.

So, fire up your favorite text editor, such as Notepad on Windows, TextEdit on Mac or download Atom (my favorite), and create a new file. In the file copy this:

import digitalio
import board
import time

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
while True:
    led.value = not led.value
    time.sleep(0.5)

Now, save the file to the drive as code.txt (code.py also works). After a brief time, the board's red LED should begin to flash every second.

Status LED

While code.py is running the status neopixel will be solid green. After it is finished, the neopixel will fade green on success or flash an error code on failure. Red flashes happen when data is written to the drive.

Debugging

Did the status LED flash a bunch of colors at you? You may have an error in your code. Don't worry it happens to everyone. Python code is checked when you run it rather than before like Arduino does when it compiles. To see the CircuitPython error you'll need to connect to the serial output (like Arduino's serial monitor).

See this guide for detailed instructions.

If you are new to Python try googling the error first, if that doesn't find an answer feel free to drop by the support forum.

Libraries

Using libraries with CircuitPython is also super easy. Simply drag and drop libraries onto the CIRCUITPY drive or into a lib folder on the drive to keep it tidy.

Find CircuitPython libraries on GitHub using the topic and through our tutorials.

Make sure the libraries are for CircuitPython and not MicroPython. There are some differences that may cause it to not work as expected.

More info

Serial Console (REPL)

CircuitPython sends the output of the .py files it runs to the connected computer over USB serial. So, to view the output of your code from print statements and any errors that occur you'll need to connect to the serial console.

Also, because CircuitPython is a variant of Python, it too has a read-evaluate-print-loop or  'REPL' for short. The REPL lets you run individual commands and load up code interactively and is therefore great for testing a new idea. However, the code typed into the REPL isn't saved anywhere so make sure and save it elsewhere (like code.py for example.)

Windows

 

Serial Drivers (for Windows 7)

If you are using Windows 7 you will need to install drivers. Click below to download the driver package and install it! This is not necessary for Mac, Linux or Windows 10+.

Determine Your Serial Port

Next you must determine the name of the serial port for your board.  It's easiest to look at the serial ports with the board disconnected (on Windows check Device Manager under the Ports (COM/LPT) node

Install Serial Port Terminal Software

On Windows you'll want to use a tool like PuTTY to connect to the serial port.  Download and run PuTTY, then configure it to use a serial connection to the board's COM port at 115200 baud similar to as shown below:

After clicking Open you should see a new window pop up with the current output from the running code. If no code is running, it may be blank so hit Ctrl - C to get to the REPL prompt.

Mac OSX and Linux

Connecting to the serial terminal on is more straightforward than on Windows. Neither OS requires additional drivers.

First open a terminal program. On Mac OSX, Terminal comes installed and iTerm2 can be downloaded. On Linux there are a variety available such as gnome-terminal (called Terminal) and Konsole on KDE.

Now before plugging in the board, type ls /dev/tty.* to view existing serial connections.

Next, plug in the board. There should be one new serial connection that is for your board. Typically on Mac OSX its something like /dev/tty.usbmodem* and on Linux its /dev/ttyACM*.

Now that we know the device name, the screen command can be used to connect to the serial port. Its installed on Mac OSX by default but Linux users may need to install it using their package manager. Run the following command to connect at 115200 baud:

screen /dev/tty.board_name 115200

Where /dev/tty.board_name is the name of the board's serial port.

When you're done using screen most versions of it allow you to exit by pressing Ctrl-a then k then y or pressing Ctrl-a then typing :quit and pressing enter.

Using the REPL

After you're connected to the serial REPL try pressing enter to confirm you see the >>> prompt.  You can also type help() and press enter on most boards to see basic usage information.

If you can't get a >>> prompt to appear try pressing Ctrl-c a couple times to interrupt any running program on the board.

You might get a Traceback and KeyboardInterrupt that lets you know the current Python program has stopped, and you'll get a prompt:

That's all there is to connecting to the board's serial REPL, you're ready to start typing in and running CircuitPython code!

Installing Libraries

Part of what makes CircuitPython so awesome is its ability to store code separately from the firmware itself. Storing code separately from the firmware makes it easier to update both the code you write and the libraries you depend. So, instead of compiling libraries in, you simply place them into your lib directory on the CIRCUITPY drive.

Your Gemma M0 should come with a lib folder already, its in the base directory of the drive:

CircuitPython libraries work in the same was as regular Python modules so the Python docs are a great reference for how it all should work. In Python terms, we can place our library files in the lib directory because its part of the Python path by default.

One downside of this approach of separate libraries is that they are not built in. To use them, one needs to copy them to the CIRCUITPY drive before they can be used. Fortunately, we provide a bundle full of our libraries.

Our bundle and releases also feature optimized versions of the libraries with the .mpy file extension. These files take less space on the drive and have a smaller memory footprint as they are loaded.

Installing on the Gemma

The Gemma M0's tiny size means we weren't able to fit extra flash memory on the board. Thats why the drive is less that 64kb total! Its the microcontroller itself thats saving the data, in the internal 256KB Flash space - about 192KB for the bootloader and Python interpreter and about 64KB for user code.

We need to be selective about what libraries we load on the Gemma M0 because we can't simply fit them all like we can on an Express board. So, lets take a look at this silly example below which uses a SI7021 I2C temperature sensor.

import adafruit_si7021
import busio
import board

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_si7021.SI7021(i2c)
print("Temperature:", sensor.temperature)
print("Humidity:", sensor.relative_humidity)

After saving that as code.py on the drive we see the status NeoPixel flashes that an error has occurred. Opening up the serial console we see that an ImportError has occurred.

It says that no module exists named adafruit_si7021. Thats the library we need to download! Since we bought the sensor from Adafruit its likely there is a library for in the official Adafruit bundle. If its not an Adafruit part or its missing, we can also check the Community bundle which has libraries contributed by the community.

Visiting the bundle release page will show us information on the latest release including a list of all the versions of the included drivers. Scrolling to the bottom of the page will reveal the downloads. We'll download the first zip file which starts with adafruit-circuitpython-bundle.

After downloading the zip, extract its contents. This is usually done by double clicking on the zip. On Mac OSX as I'm using, it places the file in the same directory as the zip. I usually sort my Downloads by file data so the lib directory that was contained in the zip ends up next to the zip file.

On Express boards, the lib directory can be copied directly to the CIRCUITPY drive. However, the Gemma M0 doesn't have enough space for all of the libraries. So, we'll copy over just what we need as we need it. In the lib folder there is an adafruit_si7021.mpy file. That matches the missing module! Python imports modules based on the filename so they will always match up. Lets drag it over. If this works, skip to the next section. Keep reading if you have an error.

Out of space!

The file system on the Gemma M0 is very tiny. (Smaller than an ancient floppy disk.) So, its likely you'll run out of space but don't panic! There are a couple ways to free up space.

The Gemma M0 ships with the Windows 7 serial driver too! Feel free to delete that if you don't need it or have already installed it. Its ~12KiB or so.

Delete something!

The simplest way of freeing up space is to delete files from the drive. Perhaps there are libraries in the lib that you aren't using anymore or test code that isn't in use.

Use tabs

One unique feature of Python is that the indentation of code matters. Usually the recommendation is to indent code with four spaces for every indent. In general, we recommend that too. However, one trick to storing more human-readable code is to use a single tab character for indentation. This approach uses 1/4 of the space for indentation and can be significant when we're counting bytes.

Mac OSX loves to add extra files.

Luckily you can disable some of the extra hidden files that Mac OSX adds by running a few commands to disable search indexing and create zero byte placeholders. Follow the steps below to maximize the amount of space available on OSX:

Prevent & Remove Mac OSX Hidden Files

First find the volume name for your board.  With the board plugged in run this command in a terminal to list all the volumes:

ls -l /Volumes

Look for a volume with a name like CIRCUITPY (the default for CircuitPython).  The full path to the volume is the /Volumes/CIRCUITPY path.

Now follow the steps from this question to run these terminal commands that stop hidden files from being created on the board:

mdutil -i off /Volumes/CIRCUITPY
cd /Volumes/CIRCUITPY
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index .Trashes
cd -

Replace /Volumes/CIRCUITPY in the commands above with the full path to your board's volume if it's different.  At this point all the hidden files should be cleared from the board and some hidden files will be prevented from being created.

However there are still some cases where hidden files will be created by Mac OSX.  In particular if you copy a file that was downloaded from the internet it will have special metadata that Mac OSX stores as a hidden file.  Luckily you can run a copy command from the terminal to copy files without this hidden metadata file.  See the steps below:

Copy Files on Mac OSX Without Creating Hidden Files

Once you've disabled and removed hidden files with the above commands on Mac OSX you need to be careful to copy files to the board with a special command that prevents future hidden files from being created.  Unfortunately you cannot use drag and drop copy in Finder because it will still create these hidden extended attribute files in some cases (for files downloaded from the internet, like Adafruit's modules).

To copy a file or folder use the -X option for the cp command in a terminal.  For example to copy a foo.mpy file to the board use a command like:

cp -X foo.mpy /Volumes/CIRCUITPY

Or to copy a folder and all of its child files/folders use a command like:

cp -rX folder_to_copy /Volumes/CIRCUITPY

Other Mac OSX Tips

If you'd like to see the amount of space used on the drive and manually delete hidden files here's how to do so.  First list the amount of space used on the CIRCUITPY drive with the df command:

Lets remove the ._ files first.

Whoa! We have 13Ki more than before! Lets continue!

Continuing after copy

Woohoo! Everything copied over just fine. Lets check the serial terminal to see how things are going.

Oops! Another ImportError! Libraries can depend on other libraries so copying one file over may not be enough. Looking in the bundle, there is an adafruit_bus_device directory. In Python terms this is a package. It contains module files. Lets copy the folder over to make sure we get everything.

If that fails due to out of space, see above. If not, continue on.

Lets check the serial connection again. Looks like it worked! We don't have any more ImportErrors and we can see the temperature (in Celsius) and the relative humidity.

CircuitPython Analog In

This quick-start example shows how you can read the analog voltages on all three Gemma M0 pads.

Copy and paste the code block into main.py using your favorite text editor, and save the file, to run the demo

# Gemma IO demo - analog inputs

from digitalio import *
from analogio import *
from board import *
import time

led = DigitalInOut(L)
led.direction = Direction.OUTPUT

analog0in = AnalogIn(A0)
analog1in = AnalogIn(A1)
analog2in = AnalogIn(A2)

def getVoltage(pin):
    return (pin.value * 3.3) / 65536

while True:
    print("A0: %f \t\t A1: %f \t\t A2: %f" %
          (getVoltage(analog0in),
           getVoltage(analog1in),
           getVoltage(analog2in)))

    time.sleep(0.1)

Creating analog inputs

analog0in = AnalogIn(A0)
analog1in = AnalogIn(A1)
analog2in = AnalogIn(A2)

Creates three objects, one for each pad, and connects the objects to A0, A1 and A2 as analog inputs.

GetVoltage Helper

getVoltage(pin) is our little helper program. By default, analog readings will range from 0 (minimum) to 65535 (maximum). This helper will convert the 0-65535 reading from pin.value and convert it a 0-3.3V voltage reading.

Main Loop

The main loop is simple, it will just print out the three voltages as floating point values (the %f indicates to print as floating point) by calling getVoltage on each of our analog objects.

If you connect to the serial port REPL, you'll see the voltages printed out. By default the pins are floating so the voltages will vary. Try touching a wire from A0 to the GND or 3Vo pad to see the voltage change!

CircuitPython Analog Out

This quick-start example shows how you can set the DAC (true analog voltage output) on all Gemma M0 pad A0.

Copy and paste the code block into main.py using your favorite text editor, and save the file, to run the demo

# Gemma IO demo - analog output
     
from digitalio import *
from analogio import *
from board import *
import time
    
aout = AnalogOut(A0)
     
while True:
  # Count up from 0 to 65535, with 64 increment
  # which ends up corresponding to the DAC's 10-bit range
  for i in range (0,65535,64):
    aout.value = i

Creating an analog output

aout = AnalogOut(A0)

Creates an object aout that is connected to the only DAC pin available - A0.

Setting the analog output

The DAC on the Gemma M0 is a 10-bit output, from 0-3.3V. So in theory you will have a resolution of 0.0032 Volts per bit. To allow CircuitPython to be general-purpose enough that it can be used with chips with anything from 8 to 16-bit DACs, the DAC takes a 16-bit value and divides it down internally.

E.g. writing 0 will be the same as setting it to 0 - 0 Volts out

Writing 5000 is the same as setting it to 5000 / 64 = 78
And 78 / 1024 * 3.3V = 0.25V output

Writing 65535 is the same as 1023 which is the top range and you'll get 3.3V output

Main Loop

The main loop is fairly simple, it just goes through the entire range of the DAC, from 0 to 65535, but increments 64 at a time so it ends up clicking up one bit for each of the 10-bits of range available.

CircuitPython is not terribly fast, so at the fastest update loop you'll get 4 Hz. The DAC isn't good for audio outputs as-is.

Bigger boards like the Metro or Feather M0 have more code space and can perform audio playback capabilities via the DAC.

CircuitPython Cap Touch

This quick-start example shows how you can read the capacitive touch sensors built into on all three Gemma M0 pads.

Copy and paste the code block into main.py using your favorite text editor, and save the file, to run the demo

# Gemma IO demo - captouch

import touchio
from board import *
import time

touch0 = touchio.TouchIn(A0)
touch1 = touchio.TouchIn(A1)
touch2 = touchio.TouchIn(A2)

while True:
    if touch0.value:
        print("A0 touched!")
    if touch1.value:
        print("A1 touched!")
    if touch2.value:
        print("A2 touched!")
    time.sleep(0.01)

You can open up the serial console to see the touches detected and printed out.

Creating an capacitive touch input

All three pads can be used as capacitive TouchIn devices:

touch0 = touchio.TouchIn(A0)
touch1 = touchio.TouchIn(A1)
touch2 = touchio.TouchIn(A2)

Creates three objects, one connected to each of the Gemma M0 pads.

Main Loop

The main loop checks each sensor one after the other, to determine if it has been touched. If touch0.value returns True, that means that that pad, A0, detected a touch. For each pad, if it has been touched, a message will print.

A small sleep delay is added at the end so the loop doesn't run too fast. You may want to change the delay from 0.1 seconds to 0 seconds to slow it down or speed it up.

Note that no extra hardware is required, you can touch the pads directly, but you may want to attach alligator clips or foil tape to metallic or conductive objects. Try silverware, fruit or other food, liquid, aluminum foil, and items around your desk!

You may need to restart your code/board after changing the attached item because the capacitive touch code 'calibrates' based on what it sees when it first starts up. So if you get too many touch-signals or not enough, hit that reset button!

Copper Foil Tape with Conductive Adhesive - 6mm x 15 meter roll

PRODUCT ID: 1128
Copper tape can be an interesting addition to your toolbox. The tape itself is made of thin pure copper so its extremely flexible and can take on nearly any shape. You can easily solder...
$5.95
IN STOCK

Copper Foil Tape with Conductive Adhesive - 25mm x 15 meter roll

PRODUCT ID: 1127
Copper tape can be an interesting addition to your toolbox. The tape itself is made of thin pure copper so its extremely flexible and can take on nearly any shape. You can easily solder...
$19.95
IN STOCK

Small Alligator Clip Test Lead (set of 12)

PRODUCT ID: 1008
Connect this to that without soldering using these handy mini alligator clip test leads. 15" cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors....
$3.95
IN STOCK

Arduino IDE Setup

The first thing you will need to do is to download the latest release of the Arduino IDE. You will need to be using version 1.8 or higher for this guide

After you have downloaded and installed the latest version of Arduino IDE, you will need to start the IDE and navigate to the Preferences menu. You can access it from the File menu in Windows or Linux, or the Arduino menu on OS X.

A dialog will pop up just like the one shown below.

We will be adding a URL to the new Additional Boards Manager URLs option. The list of URLs is comma separated, and you will only have to add each URL once. New Adafruit boards and updates to existing boards will automatically be picked up by the Board Manager each time it is opened. The URLs point to index files that the Board Manager uses to build the list of available & installed boards.

To find the most up to date list of URLs you can add, you can visit the list of third party board URLs on the Arduino IDE wiki. We will only need to add one URL to the IDE in this example, but you can add multiple URLS by separating them with commas. Copy and paste the link below into the Additional Boards Manager URLs option in the Arduino IDE preferences.

https://adafruit.github.io/arduino-board-index/package_adafruit_index.json

Here's a short description of each of the Adafruit supplied packages that will be available in the Board Manager when you add the URL:

  • Adafruit AVR Boards - Includes support for Flora, Gemma, Feather 32u4, Trinket, & Trinket Pro.
  • Adafruit SAMD Boards - Includes support for Feather M0, Metro M0, Circuit Playground Express, Gemma M0 and Trinket M0
  • Arduino Leonardo & Micro MIDI-USB - This adds MIDI over USB support for the Flora, Feather 32u4, Micro and Leonardo using the arcore project.

If you have multiple boards you want to support, say ESP8266 and Adafruit, have both URLs in the text box separated by a comma (,)

Once done click OK to save the new preference settings. Next we will look at installing boards with the Board Manager.

Now continue to the next step to actually install the board support package!

Using with Arduino IDE

Since the Feather/Metro/Gemma/Trinket M0 use an ATSAMD21 chip running at 48 MHz, you can pretty easily get it working with the Arduino IDE. Most libraries (including the popular ones like NeoPixels and display) will work with the M0, especially devices & sensors that use i2c or SPI.

Now that you have added the appropriate URLs to the Arduino IDE preferences in the previous page, you can open the Boards Manager by navigating to the Tools->Board menu.

Once the Board Manager opens, click on the category drop down menu on the top left hand side of the window and select Contributed. You will then be able to select and install the boards supplied by the URLs added to the prefrences.

Install SAMD Support

First up, install the Arduino SAMD Boards version 1.6.15 or later

You can type Arduino SAMD in the top search bar, then when you see the entry, click Install

Install Adafruit SAMD

Next you can install the Adafruit SAMD package to add the board file definitions

You can type Adafruit SAMD in the top search bar, then when you see the entry, click Install

Even though in theory you don't need to - I recommend rebooting the IDE

Quit and reopen the Arduino IDE to ensure that all of the boards are properly installed. You should now be able to select and upload to the new boards listed in the Tools->Board menu.

Select the matching board, the current options are:

  • Feather M0 (for use with any Feather M0 other than the Express)
  • Feather M0 Express
  • Metro M0 Express
  • Circuit Playground Express
  • Gemma M0

Install Drivers (Windows 7 Only)

When you plug in the board, you'll need to possibly install a driver

Click below to download our Driver Installer

Download and run the installer

Run the installer! Since we bundle the SiLabs and FTDI drivers as well, you'll need to click through the license

Select which drivers you want to install, the defaults will set you up with just about every Adafruit board!

Click Install to do the installin'

Blink

Now you can upload your first blink sketch!

Plug in the Gemma M0, Trinket M0, Metro M0 or Feather M0 and wait for it to be recognized by the OS (just takes a few seconds). It will create a serial/COM port, you can now select it from the dropdown, it'll even be 'indicated' as Gemma/Metro/Feather M0!

Now load up the Blink example

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

And click upload! That's it, you will be able to see the LED blink rate change as you adapt the delay() calls.

If you are having issues, make sure you selected the matching Board in the menu that matches the hardware you have in your hand.

Sucessful Upload

If you have a successful upload, you'll get a bunch of red text that tells you that the device was found and it was programmed, verified & reset

Compilation Issues

If you get an alert that looks like

Cannot run program "{runtime.tools.arm-none-eabi-gcc.path}\bin\arm-non-eabi-g++"

Make sure you have installed the Arduino SAMD boards package, you need both Arduino & Adafruit SAMD board packages

Manually bootloading

If you ever get in a 'weird' spot with the bootloader, or you have uploaded code that crashes and doesn't auto-reboot into the bootloader, click the RST button twice (like a double-click)to get back into the bootloader.

The red LED will pulse, so you know that its in bootloader mode.

Once it is in bootloader mode, you can select the newly created COM/Serial port and re-try uploading.

You may need to go back and reselect the 'normal' USB serial port next time you want to use the normal upload.

Ubuntu & Linux Issue Fix

Note if you're using Ubuntu 15.04 (or perhaps other more recent Linux distributions) there is an issue with the modem manager service which causes the Bluefruit LE micro to be difficult to program.  If you run into errors like "device or resource busy", "bad file descriptor", or "port is busy" when attempting to program then you are hitting this issue.

The fix for this issue is to make sure Adafruit's custom udev rules are applied to your system.  One of these rules is made to configure modem manager not to touch the Feather board and will fix the programming difficulty issue.  Follow the steps for installing Adafruit's udev rules on this page.

Adapting Sketches to M0

The ATSAMD21 is a very nice little chip but its fairly new as Arduino-compatible cores go. Most sketches & libraries will work but here's a few things we noticed!

The below note are for all M0 boards, but not all may apply (e.g. Trinket and Gemma M0 do not have ARef so you can skip the Analog References note!)

Analog References

If you'd like to use the ARef pin for a non-3.3V analog reference, the code to use is analogReference(AR_EXTERNAL) (it's AR_EXTERNAL not EXTERNAL)

Pin Outputs & Pullups

The old-style way of turning on a pin as an input with a pullup is to use

pinMode(pin, INPUT)
digitalWrite(pin, HIGH)

This is because the pullup-selection register is the same as the output-selection register.

For the M0, you can't do this anymore! Instead, use

pinMode(pin, INPUT_PULLUP)

which has the benefit of being backwards compatible with AVR.

Serial vs SerialUSB

99.9% of your existing Arduino sketches use Serial.print to debug and give output. For the Official Arduino SAMD/M0 core, this goes to the Serial5 port, which isn't exposed on the Feather. The USB port for the Official Arduino M0 core, is called SerialUSB instead.

In the Adafruit M0 Core, we fixed it so that Serial goes to USB when you use a Feather M0 so it will automatically work just fine.

However, on the off chance you are using the official Arduino SAMD core not the Adafruit version (which really, we recommend you use our version because as you can see it can vary) & you want your Serial prints and reads to use the USB port, use SerialUSB instead of Serial in your sketch

If you have existing sketches and code and you want them to work with the M0 without a huge find-replace, put

#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
  // Required for Serial on Zero based boards
  #define Serial SERIAL_PORT_USBVIRTUAL
#endif

right above the first function definition in your code. For example:

AnalogWrite / PWM on Feather/Metro M0

After looking through the SAMD21 datasheet, we've found that some of the options listed in the multiplexer table don't exist on the specific chip used in the Feather M0.

For all SAMD21 chips, there are two peripherals that can generate PWM signals: The Timer/Counter (TC) and Timer/Counter for Control Applications (TCC). Each SAMD21 has multiple copies of each, called 'instances'.

Each TC instance has one count register, one control register, and two output channels. Either channel can be enabled and disabled, and either channel can be inverted. The pins connected to a TC instance can output identical versions of the same PWM waveform, or complementary waveforms.

Each TCC instance has a single count register, but multiple compare registers and output channels. There are options for different kinds of waveform, interleaved switching, programmable dead time, and so on.

The biggest members of the SAMD21 family have five TC instances with two 'waveform output' (WO) channels, and three TCC instances with eight WO channels:

  • TC[0-4],WO[0-1]
  • TCC[0-2],WO[0-7]

And those are the ones shown in the datasheet's multiplexer tables.

The SAMD21G used in the Feather M0 only has three TC instances with two output channels, and three TCC instances with eight output channels:

  • TC[3-5],WO[0-1]
  • TCC[0-2],WO[0-7]

Tracing the signals to the pins broken out on the Feather M0, the following pins can't do PWM at all:

  • Analog pin A5

The following pins can be configured for PWM without any signal conflicts as long as the SPI, I2C, and UART pins keep their protocol functions:

  • Digital pins 5, 6, 9, 10, 11, 12, and 13
  • Analog pins A3 and A4

If only the SPI pins keep their protocol functions, you can also do PWM on the following pins:

  • TX and SDA (Digital pins 1 and 20)

analogWrite() PWM range

On AVR, if you set a pin's PWM with analogWrite(pin, 255) it will turn the pin fully HIGH. On the ARM cortex, it will set it to be 255/256 so there will be very slim but still-existing pulses-to-0V. If you need the pin to be fully on, add test code that checks if you are trying to analogWrite(pin, 255) and, instead, does a digitalWrite(pin, HIGH)

Missing header files

there might be code that uses libraries that are not supported by the M0 core. For example if you have a line with

#include <util/delay.h>

you'll get an error that says

fatal error: util/delay.h: No such file or directory
  #include <util/delay.h>
                         ^
compilation terminated.
Error compiling.

In which case you can simply locate where the line is (the error will give you the file name and line number) and 'wrap it' with #ifdef's so it looks like:

#if !defined(ARDUINO_ARCH_SAM) && !defined(ARDUINO_ARCH_SAMD) && !defined(ESP8266) && !defined(ARDUINO_ARCH_STM32F2)
 #include <util/delay.h>
#endif

The above will also make sure that header file isn't included for other architectures

If the #include is in the arduino sketch itself, you can try just removing the line.

Bootloader Launching

For most other AVRs, clicking reset while plugged into USB will launch the bootloader manually, the bootloader will time out after a few seconds. For the M0, you'll need to double click the button. You will see a pulsing red LED to let you know you're in bootloader mode. Once in that mode, it wont time out! Click reset again if you want to go back to launching code

Aligned Memory Access

This is a little less likely to happen to you but it happened to me! If you're used to 8-bit platforms, you can do this nice thing where you can typecast variables around. e.g.

uint8_t mybuffer[4];
float f = (float)mybuffer;

You can't be guaranteed that this will work on a 32-bit platform because mybuffer might not be aligned to a 2 or 4-byte boundary. The ARM Cortex-M0 can only directly access data on 16-bit boundaries (every 2 or 4 bytes). Trying to access an odd-boundary byte (on a 1 or 3 byte location) will cause a Hard Fault and stop the MCU. Thankfully, there's an easy work around ... just use memcpy!

uint8_t mybuffer[4];
float f;
memcpy(f, mybuffer, 4)

Floating Point Conversion

Like the AVR Arduinos, the M0 library does not have full support for converting floating point numbers to ASCII strings. Functions like sprintf will not convert floating point.  Fortunately, the standard AVR-LIBC library includes the dtostrf function which can handle the conversion for you.

Unfortunately, the M0 run-time library does not have dtostrf.  You may see some references to using #include <avr/dtostrf.h> to get dtostrf in your code.  And while it will compile, it does not work.

Instead, check out this thread to find a working dtostrf function you can include in your code:

http://forum.arduino.cc/index.php?topic=368720.0

How Much RAM Available?

The ATSAMD21G18 has 32K of RAM, but you still might need to track it for some reason. You can do so with this handy function:

extern "C" char *sbrk(int i);

int FreeRam () {
  char stack_dummy = 0;
  return &stack_dummy - sbrk(0);
}

Storing data in FLASH

If you're used to AVR, you've probably used PROGMEM to let the compiler know you'd like to put a variable or string in flash memory to save on RAM. On the ARM, its a little easier, simply add const before the variable name:

const char str[] = "My very long string";

That string is now in FLASH. You can manipulate the string just like RAM data, the compiler will automatically read from FLASH so you dont need special progmem-knowledgeable functions.

You can verify where data is stored by printing out the address:
Serial.print("Address of str $"); Serial.println((int)&str, HEX);

If the address is $2000000 or larger, its in SRAM. If the address is between $0000 and $3FFFF Then it is in FLASH

UF2 Bootloader Details

This is an information page for advanced users who are curious how we get code from your computer into your Express board!

Adafruit Express and Gemma/Trinket M0 boards feature an improved bootloader that makes it easier than ever to flash different code onto the microcontroller. This bootloader makes it easy to switch between Microsoft MakeCode, CircuitPython and Arduino.

Instead of needing drivers or a separate program for flashing (say, bossac, jlink or avrdude), one can simply drag a file onto a removable drive.

The format of the file is a little special. Due to 'operating system woes' you cannot just drag a binary or hex file (trust us, we tried it, it isn't cross-platform compatible). Instead, the format of the file has extra information to help the bootloader know where the data goes. The format is called UF2 (USB Flashing Format). Microsoft MakeCode generates UF2s for flashing and CircuitPython releases are also available as UF2. You can also create your own UF2s from binary files using uf2tool, available here.

The bootloader is also BOSSA compatible, so it can be used with the Arduino IDE which expects a BOSSA bootloader on ATSAMD-based boards

For more information about UF2, you can read a bunch more at the MakeCode blog, then check out the UF2 file format specification and to build your own bootloader for ATSAMD-based boards, visit Microsoft UF2-SAMD github repository.

The bootloader is not needed when changing your CircuitPython code. Its only needed when upgrading the CircuitPython core or changing between CircuitPython, Arduino and Microsoft MakeCode.

Entering Bootloader Mode

The first step to loading new code onto your board is triggering the bootloader. It is easily done by double tapping the reset button. Once the bootloader is active you will see the small red LED fade in and out and a new drive will appear on your computer with a name ending in BOOT. For example, feathers show up as FEATHERBOOT, while the new CircuitPlayground shows up as CPLAYBOOT, and Gemma M0 will show up as GEMMABOOT

Furthermore, when the bootloader is active, it will change the color of one or more onboard neopixels to indicate the connection status, red for disconnected and green for connected. If the board is plugged in but still showing that its disconnected, try a different USB cable. Some cables only provide power with no communication.

For example, here is a Feather M0 Express running a colorful Neopixel swirl. When the reset button is double clicked (about half second between each click) the NeoPixel will stay green to let you know the bootloader is active. When the reset button is clicked once, the 'user program' (NeoPixel color swirl) restarts.

If the bootloader couldn't start, you will get a red NeoPixel LED.

That could mean that your USB cable is no good, it isn't connected to a computer, or maybe the drivers could not enumerate. Try a new USB cable first. Then try another port on your computer!

The first versions of the Feather M0 Express have a bootloader that may be unreliable, especially when used through a USB Hub. If the board doesn't connect through a USB hub or connects but then disconnects, then please update the bootloader with the instructions below.

Once the bootloader is running, check your computer. You should see a USB Disk drive...

Once the bootloader is successfully connected you can open the drive and browse the virtual filesystem. This isn't the same filesystem as you use with CircuitPython or Arduino. It should have three files:

  •  CURRENT.UF2 - The current contents of the microcontroller flash.
  •  INDEX.HTM - Links to Microsoft MakeCode.
  •  INFO_UF2.TXT - Includes bootloader version info. Please include it on bug reports.

Using the Mass Storage Bootloader

To flash something new, simply drag any UF2 onto the drive. After the file is finished copying, the bootloader will automatically restart. This usually causes a warning about an unsafe eject of the drive. However, its not a problem. The bootloader knows when everything is copied successfully.

You may get an alert from the OS that the file is being copied without it's properties. You can just click Yes

You may also get get a complaint that the drive was ejected without warning. Don't worry about this. The drive only ejects once the bootloader has verified and completed the process of writing the new code

Using the BOSSA Bootloader

As mentioned before, the bootloader is also compatible with BOSSA, which is the standard method of updating boards when in the Arduino IDE. It is a command-line tool that can be used in any operating system. We won't cover the full use of the bossac tool, suffice to say it can do quite a bit! More information is available at ShumaTech.

Windows 7 Drivers

If you are running Windows 7 (or, goodness, something earlier?) You will need a Serial Port driver file. Windows 10 users do not need this so skip this step.

You can download our full driver package here:

Download and run the installer. We recommend just selecting all the serial port drivers available (no harm to do so) and installing them.

Verifying Serial Port in Device Manager

If you're running Windows, its a good idea to verify the device showed up. Open your Device Manager from the control panel and look under Ports (COM & LPT) for a device called Feather M0 or Circuit Playground or whatever!

If you see something like this, it means you did not install the drivers. Go back and try again, then remove and re-plug the USB cable for your board

Running bossac on the command line

If you are using the Arduino IDE, this step is not required. But sometimes you want to read/write custom binary files, say for loading CircuitPython or your own code. We recommend using bossac v 1.7.0 (or greater), which has been tested. The Arduino branch is most recommended.

You can download the latest builds here. The mingw32 version is for Windows, apple-darwin for Mac OSX and various linux options for Linux. Once downloaded, extract the files from the zip and open the command line to the directory with bossac

For example here's the command line you probably want to run:

bossac -e -w -v -R ~/Downloads/adafruit-circuitpython-feather_m0_express-0.9.3.bin

This will -erase the chip, -write the given file, -verify the write and -Reset the board. After reset, CircuitPython should be running. Express boards may cause a warning of an early eject of a USB drive but just ignore it. Nothing important was being written to the drive. A hard power-reset is also  recommended after bossac, just in case.

Updating the bootloader

The UF2 bootloader is still in beta, and while we've done a ton of testing, it may contain bugs. Usually these bugs effect reliability rather than fully preventing the bootloader from working. If the bootloader is flaky then you can try updating the bootloader itself to potentially improve reliability.

Updating the bootloader is as easy as flashing CircuitPython, Arduino or MakeCode. Simply enter the bootloader as above and then drag the update bootloader uf2 file below. This uf2 contains a program which will unlock the bootloader section, update the bootloader, and re-lock it. It will overwrite your existing code such as CircuitPython or Arduino so make sure everything is backed up!

After the file is copied over, the bootloader will be updated and appear again. The INFO_UF2.TXT file should show the newer version number inside.

For example:

UF2 Bootloader v1.20.0 SFHR
Model: Adafruit Feather M0
Board-ID: SAMD21G18A-Feather-v0

Lastly, reload your code from Arduino or MakeCode or flash the latest CircuitPython core.

The latest updater for Feather M0 Express:

Getting Rid of Windows Pop-ups

If you do a lot of development on Windows with the UF2 bootloader, you may get annoyed by the constant "Hey you inserted a drive what do you want to do" pop-ups.

Go to the Control Panel. Click on the Hardware and Sound header

Click on the Autoplay header

Uncheck the box at the top, labeled Use Autoplay for all devices

Making your own UF2

Making your own UF2 is easy! All you need is a .bin file of a program you wish to flash and the Python conversion script. Make sure that your program was compiled to start at 0x2000 (8k) because the bootloader takes the first 8k. CircuitPython's linker script is an example on how to do that.

Once you have a .bin file, you simply need to run the Python conversion script over it. Here is an example from the directory with uf2conv.py:

uf2conv.py -c -o build-circuitplayground_express/revg.uf2 build-circuitplayground_express/revg.bin

This will produce a revg.uf2 file in the same directory as the source revg.bin. The uf2 can then be flashed in the same way as above.

 

Downloads