XIAO SAMD21, Arduino and MIDI – Part 3

In this post I wire up the DAC and start up Mozzi using my Arduino Multi-pot Mozzi FM Synthesis on the Seeedstudio XIAO SAMD21 board (previously known as the Seeeduino XIAO).

Previous 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_7049

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.
  • 3V3 compatible MIDI module, for example one of the Ready-Made MIDI Modules or DIY MIDI Interfaces.
  • Up to 6x 10KΩ potentiometers
  • Optional Output Filter circuit:
    • 1x 470Ω resistor
    • 1x 100nF ceramic capacitor
    • 1x 1uF electrolytic capacitor
  • MDI devices as required to source or sink MIDI.
  • 3.5mm TRS jack breakout or similar connection.
  • Amplification and sound output.
  • Breadboard and jumper wires.

See the notes in part 1 about uploading to the XIAO and what to do if there are issues!

The Circuit

XIAO-Mozzi-FM-Pot_bb

This circuit is using the following pins from the XIAO:

  • A0 – DAC output.
  • A1 through to A5 – first five potentiometers.
  • A8 – last potentiometer.
  • A6/A7 – TX/RX for MIDI module.

I’ve added a simple low-pass filter with a cut-off frequency of around 3.5kHz – although not strictly necessary in this case, it might help in the future if I use a different XIAO variant that has to use PWM rather than a dedicated digital to analog converter on the XIAO SAMD21.  The DAC will output 0-3.3V so after going through a coupling capacitor to remove the DC bias that will result in an approx +/- 1.65V output which should be fine for a “line out” style signal.

The potentiometers each require 3V3 and GND and the MIDI module requires the same.  IMPORTANT: They must NOT use 5V power or it might damage the XIAO.  Note that only three potentiometers are shown in the Fritzing diagram above, but A1-A3 should be connected too as required.

The audio output is fed into both L and R channels of a stereo TRS jack breakout to the RING and TIP1 connections.  RING2 is unconnected and SLEEP is connected to GND.

In the photo at the start of this post, I’ve used my 3V3 MIDI Module PCB and the simpler (passive) part of the Analog IO Board PCB.

The Code

Mozzi supports the SAMD21 directly and correctly configures the library to use the digital to analog converter, DAC, which comes out on D0/A0 for the XIAO SAMD21.

I’ve used the code from Arduino Multi-pot Mozzi FM Synthesis with the following minor changes.

First the potentiometer configuration for A1-A5 and A8 (assuming all six pots are to be used):

#define WAVT_PIN 1 // Wavetable
#define INTS_PIN 2 // FM intensity
#define RATE_PIN 3 // Modulation Rate
#define MODR_PIN 4 // Modulation Ratio
#define AD_A_PIN 5 // ADSR Attack
#define AD_D_PIN 8 // ADSR Delay
//#define FREQ_PIN 5 // Optional Frequency Control

The MIDI configuration in this sketch is hard-coded to use Serial as it adjusts some of the serial port settings.  The XIAO (and other SAMD21 boards) map Serial1 onto the hardware UART so this has to be updated.

To be honest, these adjustments aren’t strictly necessary, so we could scrap this custom settings and swap back to using:

MIDI_CREATE_DEFAULT_INSTANCE();

Then it would basically work on the default hardware UART of whatever board it is being built for.

Find the original on GitHub here then make the above changes.

Closing Thoughts

After using PWM outputs on Arduino for Mozzi for so long, it is a real luxury to see a nice, relatively clean DAC output on my mini oscilloscope.  I can really see the four waveforms and how the FM modulation gets applied.

I’d like to build some kind of synth experimenter board for the XIAO now too.

Kevin

Leave a comment