Arduino MIDI R2R Digital Audio

With all the excitement of experimenting with Mozzi, I never really finished my R2R digital audio series.  This final part adds MIDI to the R2R shield I built in Arduino R2R Digital Audio – Part 3.

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

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

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

Parts list

The Circuit

With great foresight (honest) I designed the R2R circuit to avoid using pins 0 and 1 (the built-in serial port).  This is massively handy now as these are the pins used by the MIDI library.  So all that is needed is the addition of a set of header pins on the shield to make these easily available as follows.

2020-08-30 14.20.50

The Code

To MIDI-fy the R2R code requires the following:

  • Include the Arduino MIDI Library and set up call-back functions for note on and off.
  • Replace the reading of potentiometer A0 with a frequency determined by the MIDI note being played.  I’ve used the table of frequencies from the toneMelody example yet again.
  • Set up a simple system for note on/off handling.  I use the fact that setting the frequency to zero basically turns the sound generation off.

I’ve also added a compile-time option to preset the waveform so this could actually function without potentiometers at all.

Find it on GitHub here.

Update: There is now a slightly more sophisticated version of this code that applies a simple envelope to remove some of the clicks and pops that were produced by the original.

Full details can be found here: Arduino MIDI R2R Digital Audio – Part 2.

Closing Thoughts

The shield itself has two potentiometers and one can optionally change the wave form in use.  It might be nice to use the other (now unused) potentiometer to adjust the synthesis somehow – maybe to add in a low-frequency adjustment somehow, or a volume control, or maybe to detune a second waveform for combining with the first…

But at this point we are getting close to reimplementing what Mozzi allows us to do, so that is probably as far as I’ll take this now.

Kevin

Leave a comment