After an initial play with the XIAO ESP32-C3 MIDI Synthesizer the first thing I wanted to try was to swap out the ESP32-C3 for something else, just to see what could be done.
The XIAO range of boards support a range of options and Adafruit's QTPy boards are also pin-compatible. For me, I have the following as possibilities:
- XIAO SAMD21
- XIAO RP2040
- QTPy SAMD21
- QTPy ESP32-C3
I also already have a range of projects that have looked at some of the above: https://diyelectromusic.com/tag/xiao/
So before I get too far into what the SAM2695 itself can do, I thought I'd try a few alternative options right from the start. This post looks at how to use the XIAO SAMD21 to support USB access to the Synth.
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.
XIAO SAMD21 as a USB Device
My CircuitPython USB to Serial MIDI Router uses a XIAO SAMD21 in USB Device mode, so replacing the ESP32C3 with a SAMD21, should allow it to be used as a USB MIDI device.
The principle is exactly the same as the previous project but instead of a serial MIDI interface connected to the XIAO UART, it is connected directly to the SAMD21.
This should work just as well with a QTPy SAMD21 too.
There are two options for USB MIDI device support:
Using CircuitPython
The following steps are required for the CircuitPython version which, when it works, is the simplest:
When I first tried this, everything hung up. It turned out that the XIAO needs to use board.LED_INVERTED as the built-in LED label. Once that was updated all was good.
I also, as a precaution, added the following to boot.py:
import usb_hid, usb_midi
usb_hid.disable()
usb_midi.enable()
But this is probably unnecessary for the XIAO SAMD21.
The XIAO pops up as a USB MIDI device called "CircuitPython Audio" and any MIDI commands (such as note, Program Change, or control messages) sent to the device are forwarded directly onto the SAM2695 synth.
Whilst this is the simplest way to do this, it isn't the most performant! Will a lot of notes (like my Rite of Spring example) some MIDI messages might not be accurately processed in time and others might get lost.
Using Arduino
It just so happens that the code I used for XIAO SAMD21, Arduino and MIDI – Part 4 "just works". It is a little over the top, in that it sets up three serial ports, so will almost certainly clash with something else on the synth, but it does work if no buttons are pressed!
Use the code from: https://github.com/diyelectromusic/sdemp/tree/main/src/SDEMP/XiaoSimpleUSBMIDIMerge
Download this using the "Seeeduino XIAO" board setting in the Arduino IDE and it should appear as a USB MIDI device called "Seeed XIAO M0" or something like that.
Performance wise, this passes the Rite of Spring test very well.
XIAO SAMD21 as USB Host
In the post XIAO SAMD21, Arduino and MIDI – Part 5 I used the SAMD21 as a USB host. By providing an external power supply this allow the use of a USB MIDI controller with the SAM2695.
To plug anything in however will require an adaptor or two. This needs to go from an original "USB A" plug to a USB-C socket. For me, this involved using a "USB-C to USB-micro" adaptor and then a "USB OTG adaptor" as shown below.
Then I needed a 5V power source, so I cheated and use the 5V and GND from the original XIAO ESP32-C3 that I'd replaced with the XIAO SAMD21 and just jumpered them across to 5V and GND from the breakout headers on the synth.
I stayed away from the code I used as part of XIAO SAMD21, Arduino and MIDI – Part 4 directly, but instead used one of the sample applications from the SAMD21 USB Host Library.
I turns out the "USB_MIDI_Converter" sketch works really well. This can be found here: https://github.com/gdsports/USB_Host_Library_SAMD/blob/master/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino
Closing Thoughts
Similar tricks should also be possible using the RP2040 based boards, and as already mentioned it is also possible to use the Grove connector. One of the options for Grove is as a UART, and this is supported, for example, on the original XIAO breakout board: https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/
I believe the UART Grove socket would connect directly to the Synth Grove connector allowing use of the synth from the expansion board too.
Kevin
No comments:
Post a Comment