XIAO SAMD21, Arduino and MIDI

I’ve had a few Seeedstudio XIAO SAMD21 boards (previously known as the Seeeduino XIAO) for a while but haven’t really done much with them.  I had a brief go with Circuitpython to build a CircuitPython USB to Serial MIDI Router but that is all so far.  Having been inspired by a recent post on the Seeed blog about using the XIAO in music projects, I thought it was about time I had a proper look.

In this first post I’ve had a bit of a play with the XIAO from within Arduino.  More specifically I’ve had a look at which of my previous projects might run with minimal changes on the XIAO SAMD21 with the XIAO Expansion Board.

Other parts in this series:

  • Part 1 – Introduction to the XIAO SAMD21 and some projects to get started.
  • Part 2 – Looking at accessing additional serial ports and using them for MIDI.
  • Part 3 – Mozzi FM synthesis using the DAC on the XIAO.
  • Part 4 – USB MIDI on the XIAO.
  • Part 5 – XIAO as a USB MIDI Host.
  • Part 6 – MIDI control using the expansion board.
  • Part 7 – XIAO Expansion I2C MIDI control.
  • Part 8 – XIAO MIDI PCBs.

Note: Although I’ve had vouchers from Seeed Studio for their Fusion service to support the manufacturing of some of my PCBs, there is no support for my use of the XIAO boards for this post.  I bought these a while ago, bought my own expansion board more recently, and just wanted a bit of a play to see what I could come up with.

IMG_7038

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

If you are new to microcontrollers, see the Getting Started pages.

Parts list

  • Seeed Studio XIAO SAMD21.
  • Seeed Studio XIAO Expansion Board.
  • 3V3 compatible MIDI module, for example one of the Ready-Made MIDI Modules or DIY MIDI Interfaces.
  • MDI devices as required to source or sink MIDI.
  • Breadboard and jumper wires.

Note: If you get into trouble, then it is possible that you might need some means of connecting to the XIAO using the SWD (“software debug”) interface.  I have a cheap “ST Link V2” SWD interface and had to follow the instructions here to “unbrick” my XIAO at least once whilst playing around!

Update: Actually if you perform the serial port renumbering trick described here, then I’ve found uploading after a double-reset-push very reliable.

The Circuit

XIAO-MIDI

There are three options for connecting up a MIDI module:

  • Directly from the XIAO pin headers themselves.  Pins A6/A7 (D6/D7) are TX and RX respectively.
  • Using the GROVE UART connector (bottom right-hand connector in the diagram above).
  • Using the additional pin headers on the far right of the expansion board.

I’m using the last mode as it provides convenient connection points for standard jumper wires.

IMPORTANT NOTE: The XIAO requires 3V3 logic level IO.  The MIDI module to be used has to support 3V3 operation.  Some modules will still require a 5V VCC to do this, but some might be fine with 3V3. I’m using my 3V3 MIDI Module PCB which requires a link to GND and 3V3 in addition to TX/RX.  Hopefully it goes without saying that using a 5V power link when 3V3 is required or a MIDI module that provides 5V logic TX/RX lines, risks damaging your MIDI module, the XIAO or both.

Getting Started with Arduino

The aim of this first experiment is to get up and running with Arduino on the XIAO.  Details of how to get started can be found here: https://wiki.seeedstudio.com/Seeeduino-XIAO/.  Details of how to configure the Arduino environment for use with the XIAO SAMD21 can be found in the “Getting Started – Software” section but the key step is to add the Seeed XIAO SAMD core to your board manager using the following URL:

https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json

The required board support can then be found by searching for Seeed and selecting and installing “Seeed SAMD Boards”.  Then there will be the option to select “Seeeduino XIAO” (it still has the old name in my version) from “Seeed SAMD (32-bits ARM Cortext M0+ and Cortex M4) Boards”.

It is well worth verifying that everything works as expected by finding, compiling and uploading the standard “Blink” sketch.  Note however that with the XIAO the built-in LED is on when the output is LOW!

Note that it can be a little tricky uploading sketches at times!  It is a bit like the Trinket or the ATmega32U4 boards in that regard.  If you start having issues, experiment with the timing of the reset and if all else fails and it stops responding completely then it will be time to break out the SWD link as described here: https://emalliab.wordpress.com/2023/03/12/unbricking-a-seeed-xiao-samd21/

Sample Projects

Here are several of my previous projects that will run with very minimal changes on the XIAO with the expansion board.

Simple MIDI Monitor

This flashes the on-board LED whenever there is MIDI activity detected.  By default software “MIDI THRU” is also active so the input can come from a MIDI keyboard or controller, and the output can be fed into a MIDI sound generator.

Note that the LED will be constantly ON, and MIDI activity is indicated by the LED going OFF.  This can be swapped in the sketch by changing the setting of the HIGH and LOW values.

Find it on GitHub here.

Simple Serial MIDI Monitor

This is a slight advance on the previous project.  The XIAO does not rely on the hardware serial port for USB serial communications, so that means it can be easily used as a MIDI debugger, printing MIDI information to the standard serial port.

This works as the Arduino MIDI Library supports the SAMD architecture by creating the default MIDI serial link using what is effectively “Serial1” in the Arduino environment.  The standard “Serial” is reserved for the USB serial link.

The “out of the box” configuration that enables MIDI INPUT on MIDI_HW_SERIAL2 thus just works.  All other options should remain deselected.

#define MIDI_HW_SERIAL2 1
//#define MIDI_HW_SERIAL3 2
//#define MIDI_HW_SERIAL4 3
//#define MIDI_SW_SERIAL 4
//#define MIDI_SW_SERIAL2 5
//#define MIDI_USB_HOST 6
//#define MIDI_USB_DEVICE 7

Note that MIDI THRU is disabled by default though to keep things simple.

Find it on GitHub here.

Arduino MIDI Tone Module

The expansion board includes a small piezo speaker on A3 so any of the sketches producing tones will work.  A good example is the MIDI tone module which will play tones according to any MIDI notes received.

The speaker needs to be specified at the top of the file:

#define SPEAKER 3

Note – the output is very quiet, but it is there and works!

Find it on GitHub here.

SSD1306 Mini OLED MIDI Display

The expansion board includes a I2C connected SSD1306 128×64 OLED display using the standard I2C address of 0x3C.  The Seeed examples suggest the use of a specific library, but actually my previous projects also work too completely unchanged.

This example prints out MIDI note messages to the OLED display when received.  No changes are required to the code for it to “just work”.

Find it on GitHub here.

Closing Thoughts

For this first set of experiments I’ve kept to things that just use the expansion board “as is”, with the addition of the MIDI module. But there are many other things to try now. If it wasn’t for the quirkiness of the upload process, I’d be happy to place this in my “beginners” category – everything else is fairly straightforward!  But due to the somewhat unpredictable nature I’ve decided it is at least “intermediate” and possibly verging over into “advanced” if you end up having to “unbrick” your board!

Update: Having performed the serial port renumbering trick described here I’ve found uploading is a lot more reliable especially when used with a reset button for forcing the device back into bootloader mode. This is how I upload all my code now – so I really recommend wiring up a reset button!

Having said all that, there is lots of potential here.  Some examples of future experiments I’m thinking about:

  • Hook the board up to some analog inputs and build a MIDI controller.
  • Investigate the SAMD21 USB functionality to see if MIDI USB is a possibility.
  • Try the board with my Touch Keyboard PCB.
  • Consider building some “GROVE” compatible add-on modules – e.g. a “GROVE” UART MIDI module or IO board.

And there is also a lot of scope still for more Circuitpython experiments in addition to Arduino and I’m now starting to think about some XIAO specific PCBs.  I also have a XIAO RP2040 to get out at some point too!

Kevin

Leave a comment