Sunday 8 April 2012

NaV-1 Arduino Soundgin-Babblebot Synth - Part 2

Adding a MIDI Input

Please go back and read Part 1 of the NaV-1 Soundgin Synth project if you haven't already. If you want to skip ahead and start building the final hardware go HERE.

Now that we have the basic circuit built and have verified that the Arduino can control the Soundgin chip, we are going to add the circuitry for a MIDI Input. This is going to turn this project from a mere noisemaker into an actual playable instrument!

I have already covered the basics of adding MIDI control to an Arduino in This Article. Give it a quick read to get up to speed.


*NOTE* From this point on you will need to power your Arduino from an external power supply. I am using a 9v DC Lab Supply. At this stage, the circuit is drawing around 50-70mA of current. We need to remove the USB cable when we are running the Synth so it does not conflict with the incoming Midi Data

To Start, look at this schematic for a standard MIDI INPUT circuit below.

MIDI Input circuit
Now add this circuit to the NaV-1 synth.


Here is the circuit on a breadboard.

On the BreadBoard

Midi input circuit

** Notice that the Midi components are kept away from the Audio output. If they get too close, you can pick up Midi noise on the Audio line. **


*NOTE* - The Midi Library requires Arduino IDE version 0023 or earlier. You will get errors if you try to compile in a later version. Also, you need to make sure no powered Midi devices are connected when you upload the program to the Arduino Board. Removing the wire from "Pin 0-RX" on the Arduino board is a quick way to insure this. Remember to replace the wire and remove the USB cable when you are ready to run the Synth.

First download and install the MIDI Library and run the Midi Test as described Here. The program also uses the SoftwareSerial Library to communicate with the Soundgin chip using pins 2,3, and 4.

The program file can be downloaded HERE. It is in the folder named "NaV1_MIDI_Test". Open the enclosed PDE file in the Arduino IDE (version 0023 or earlier).

The program starts by creating a SoftwareSerial object named "soundgin", starting the Midi Library and setting its callback function, and initializing some Arduino pins.

It then calls the "patch" function which initializes the Soundgin and sets up a basic Saw Wave in Oscillator A. An array called "sgInit" contains this list of commands to accomplish this. Notice that Soundgin commands begin with a "27" as an escape character followed by the command byte. The command "27,1" tells the Soundgin to store a byte in a memory location. Read through the commented code to see the commands.

Once the Soundgin is ready, the program sits and waits for incoming Midi Data. When it receives a valid Midi note command, the function "MyHandleNoteOn" is called by the Midi Library to deal with it.

This function takes the incoming note number and uses a Lookup Table to convert the Midi note data into the correct note number used by the Soundgin "Load & Play a musical note in Oscillator A" command.

There are two Global Variables named "currentNote" and "newNote". When a key is pressed, its note value is stored in currentNote. If a second key is hit before currentNote is released, it is stored in the newNote variable. That way currentNote can be retriggered if newNote is the first to be released. If this is not done, you will find notes mysteriously cutting out while you are playing faster passages.

By this point you should have a pretty cool little synth to play with. Have fun with it!

Next Part: Building the User Interface


  1. I’d have to check with you here. Which is not something I usually do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!
    Click Here
    Visit Web