SAMD21E piano and synthesizer

This project demonstrates capacitive touch included in the SAMD21E, as well as a realtime synthesizer running at 44.1kHz in an interrupt.

A total of 5 capacitive pads are available, and the sound is produced by a piezo buzzer on the back:


Design

Schematic

The schematic is the bare minimal to get the SAMD21E to work. Note that I put a pull-up resistor and decoupling capacitor on the RESET pin, as advised in the datasheet. An RGB LED is a great device for user feedback, I made sure to connect it to 3 PWM-capable pins.

The piezo buzzer is connected to the only DAC-capable pin of the D21E, namely PA02.

Board layout

The layout is straightforward, but I wanted an organic connection to the pads, so I left them out in the design then completed them in inkscape.

After exporting the .svg files of the board, I added the missing traces as bezier splines:

Making

Milling

The milling was performed in around 30 minutes with the following operations:

  • Two isolation passes with a 0.4mm flat end mill
  • A copper clearing pass with a 0.8mm flat end mill
  • Edge cut and drills with the 0.8mm mill

After a cleanup with soap, the copper shines and the clarity of the traces becomes clear. Note the difference height between 0.4mm and 0.8mm mill passes, that is not wanted but hard to calibrate right.

Soldering

Before soldering, I always look at my boards with a backlight. This makes potential shorts very obvious. In this case, I’m satisfied with the contrast between traces and clear regions:

I proceed to soldering the components. I add a generous amount of flux in tight pitch areas such as the SAMD21’s legs.

A microscope always helps to check for solder bridges.

The soldering is complete:

The back shows the piezo and a shim for the USB plug

Code

Before programming the board through Arduino IDE, I flash the SAM BA bootloader using a SWD programmer and edbg. Note the connection: the dot on the 2x2 plug is on the same orientation on both the programmer and target:

The bootloaders can be found in the Fab SAM Arduino Core at this location. For a SAMD21E17, the edbg command is:

edbg -ebpv -t samd21 -f sam_ba_SAMD21E17A.bin

After installing the Arduino core, the board can be flashed through Arduino IDE.

Adafruit Freetouch

The code makes intensive use of the Adafruit Freetouch library, which is a clever reverse engineering of the Qtouch hardware included in the SAMD family. The library must be installed separately, you can find more information here.

Synthesizer

The synthesizer is a simple low-passed square wave, with attack and release effects. This is all computed within an interrupt running at 44.1kHz, producing 10-bit samples sent to the DAC.

Demo

The piezo signal shows the attack/release of the synthesizer:

Zoomed out, the linearity of the attack/release is obvious, note how the release is 3 times longer on purpose:

Downloads

PNG files (1000 DPI)

Traces:


Interior:


Traces + exterior:


Composite:


KiCAD 6 files

Code

Full synthesizer:

Simplified version, square wave only:

License

This project is provided under the MIT License.