Arduino MIDI Slider R2R Waveform Generator

When I first started looking at using fader/slider potentiometers I always anticipated using it to generate waveforms for my Arduino MIDI R2R Digital Audio board.  But as that is currently part of the Lo-Fi Orchestra, I decided I’d build a new one, hence the diversion into using PWM first whilst I decided exactly what to do.

This projects describes my new R2R Arduino DAC shield.

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 projects for the main concepts used in this project:

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

Parts list

  • Arduino Uno
  • Arduino Uno proto board shield or stripboard
  • Multiplexed 16-pot slider/fader board as described here: Arduino Multi-Slider MIDI Controller – Part 3
  • 9x 10kΩ resistors
  • 11x 20kΩ resistors
  • 1x pcb mounted dpdt switch (optional)
  • 3.5mm pcb mounted stereo output jack
  • Amplification and speaker
  • MIDI In interface (such as one of the Ready-Made MIDI Modules)
  • Various headers, jumpers and connecting wires
  • Optional: components for the output stage and filter (will be detailed in a future post)

The Circuit

This is essentially my R2R DAC as described in my previous project here – Arduino R2R Digital Audio but I thought I’d “do it properly” this time and add a buffered output filter stage as described by Brent Edstrom in “Arduino for Musicians”.  This consists of two sections of an OpAmp and a low-pass filter.

For the time being however, I’ve not actually built this part yet, the first build just jumpers the output across to the 3.5mm socket.  I’ll come back to the output stage in a future post.

I have included right-angled headers and a switch to allow a 5V/GND/RX/TX switchable connection to a MIDI interface.

The one slight complication is the splitting up of the 8 outputs for the R2R DAC.  As before they are organised as follows:

  • Bits 0 and 1 = PORTB 0 and 1 (D8, D9)
  • Bits 2 to 7 = PORTD 2 to 7 (D2 to D7)

This is to keep PORT D 0 and 1 (RX, TX) free for the MIDI link.  This means that the R2R ladder has to be split up – it starts at D8, goes up to D9, then drops all the way back down to D2 then continues back up to D7.  It also means the audio output has to link to D7 and that D8 has to link via the last resistor to GND.

I’ve provided a schematic that is laid out this way to show what I mean as well as the Fritzing diagram.

Here are a few photos of my build.

The resistors and ground connections to the test header and socket are added first.  Notice the long link from D9 to D2 on the underside of the board where the “ladder” splits.

Even though I’m not using the output stage yet, I’ve added a socket for the OpAmp so I can check everything looks like it will fit ok.

IMG_5343

The above photo shows the audio output path in yellow – I’ve included a link to the OpAmp ready for the future (this is the only connection I’ve made to the socket at this point).  I’ve wired up the signal end of the 3.5mm socket to the jumper header too in pink.  For now, this allows me to jumper straight across from the R2R output to the 3.5mm socket.  Thinking on this some more, it might be useful to allow this as a future option anyway – to allow the socket to connect either directly to the raw output or the buffered output stage – I’m still deciding…

The initial thinking here was to provide a GND, pre-output stage, and post-output stage test points where I can attach my oscilloscope.

At this point I’ve added in the switch and connecting wires for the MIDI jumper header. It is wired: RX-TX-5V-GND.  As in previous projects, the switch allows the MIDI link to be disabled when uploading new sketches to the Arduino.

Finally a full set of Arduino stacking headers have been added. This will allow me to plug in the multiplexer fader board as shown below.

IMG_5349

The Code

The code is a combination of the timer interrupt and ddsOutput stages from Arduino R2R Digital Audio – Part 2, the MIDI handling added in Arduino MIDI R2R Digital Audio and the multiplexed waveform generation from Arduino MIDI Slider PWM Waveform Generator so it has all been discussed in detail in previous articles.

Find it on GitHub here.

Closing Thoughts

One of the nice things about having an R2R DAC (even one as crude as mine) is that you can really see the output waveform clearly changing on an oscilloscope.  In the video you can I’m driving it from my Pi Pico Toy Keyboard over traditional MIDI once again.

It will be interesting to see what a “proper” output stage does to the signal too.

Now I have the ability to stack something on top of the DAC, I’m seriously considering another shield to house the connections to the fader board and a small I2C or SPI driven display.

And I really do need to look at the note change handling as it is still quite “choppy”.

Kevin

Leave a comment