Arduino MIDI LED Step Sequencer with MCP3008

Having now experimented with an SPI eight-way analog to digital converter in the shape of the MCP3008, I wanted to build a step sequencer where the type of analog input was configurable.  This project allows you to choose between the following options for controller the steps of the sequencer:

  • The native analog inputs on the Uno (6), Nano (8) or other.
  • An 8 (4051) or 16-way (4076) multiplexer.
  • An SPI 8-way ADC (MCP3008).

With options for additional controls too.

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

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

Parts list

  • Arduino Uno
  • 8x 10k potentiometers
  • MCP3008
  • Optional: 2 additional 10k potentiometers
  • Optional: 8 programmable RGB LEDs (“NeoPixels”)
  • Ready-Made MIDI Modules
  • Breadboard and jumper wires

The Circuit

ArduinoMIDIStepSequencer3008_bb

The MCP3008 and potentiometer circuit is the same as in the previous project (details here) but this time I’m expanding to use all 8 potentiometers.  In addition to the MIDI link there are optional additions as follows:

  • A tempo control potentiometer on A0.
  • A “sequencer mode” control potentiometer on A1.
  • A set of 8 programmable RGB LEDs (“neopixels”) on D5.

IMG_5514

The Code

The core code comes from the following projects:

So in principle there isn’t anything new here!  But what I particularly wanted to do was provide options for all three types of analog inputs.  To do that, I’ve used conditional compilation at the top of the source code to choose the method, define the hardware configuration (pins), and select the “setup” and “read” routines for the method chosen.

// Uncomment the method to be used to read the sequence potentiometers
//#define ALG_ADC 1 // Built-in analog inputs
//#define ALG_MUX 1 // Multiplexer
#define ALG_SPI 1 // MCP3008 SPI ADC

#ifdef ALG_MUX
#define MUX_POT A5 // Pin to read the MUX value
#define MUX_S0 2 // Digital IO pins to control the MUX
#define MUX_S1 3
#define MUX_S2 4
#define MUX_S3 5 // HC4067 (16 ports) only, comment out if using a HC4051 (8 ports).
#define ALGSETUP muxSetup
#define ALGREAD muxAnalogRead

#elif ALG_SPI
#include <MCP3XXX.h>
MCP3008 adc;
#define ALGSETUP spiSetup
#define ALGREAD spiAnalogRead

#else // ALG_ADC
#define ALGSETUP algSetup
#define ALGREAD algAnalogRead
#endif

Then in the main body of the code ALGSETUP() is called from the setup() routine and whenever a potentiometer has to be read it will use: int value = ALGREAD(pot) and the code will include the correct function for the chosen method.

All that is required is the three sets of ‘setup’ and ‘read’ functions for each of the three methods, the main body of which is taken from the above linked previous projects.

There is additional code in the main loop to read the tempo and mode potentiometers (if enabled) and adjust the system accordingly.  There are currently three modes for the sequencer:

  • 0 – normal play.
  • 1 – reverse play.
  • 2 – random play.

I’ve chosen to select the mode using a potentiometer for a change rather than button presses, but adding a button should be fairly straight forward if you prefer.  I’m using a tempo-based delay in the loop by counting milliseconds to allow the loop to continue scanning all the IO inbetween playing the MIDI sequence steps.

The final part of the code deals with the programmable LEDs. This is encapsulated in the displaySetup and displayLoop functions and I’ve used the same scaling of colours to MIDI notes that I used last time.

Find it on GitHub here.

Closing Thoughts

In the video I’m driving my MT-32 over MIDI with a marimba patch.  One thing I’d quite like to do is build an 8-step sequencer with LEDs onto a single board somehow.  Perhaps arranging them in an interesting physical pattern to make a fun stand-alone MIDI controller.

Kevin

Leave a comment