Arpeggiating Synthesizer (Mosquito I)
by analogsketchbook in Circuits > Audio
5440 Views, 54 Favorites, 0 Comments
Arpeggiating Synthesizer (Mosquito I)
Mosquito I is a small arpeggiating synthesizer that uses an Arduino Nano and the Mozzi sound synthesis library. It can play over twenty 8-step sequences but you can add as many custom sequences as you like. It’s relatively simple to set up and doesn’t require a lot of parts.
Supplies
- Arduino Nano (or any Arduino really should work)
- 5 ea Potentiometers (10K Linear)
- 2 ea Push buttons
- 1 ea LED
- 1 ea Resistor (330 ohm)
- 2 ea Resistor (1K)
- 1 ea Resistor (2K)
- 1 ea Electrolytic Capacitor (100 uF)
- 1 ea Ceramic Capacitor (33 nF)
- 1 ea Stereo Jack
- Hookup wire
- Breadboard
Setting Up the Arduino
First, let's get the Nano on the breadboard and set up our power:
- Place the Nano on the breadboard. Place as shown in the image above. It should straddle the center channel of the breadboard. You'll want it situated towards one end of the breadboard, with the USB port facing that side. This way the cable won't get in the way when we plug it in. If you're using a larger Arduino such as the Uno or Mega, you won't be mounting it on the breadboard of course.
- Connect power rails to Arduino. Connect one of the positive (red) rails of your breadboard to the Arduino's 5V pin using wire or jumper wires. Then connect one of the negative (blue) rails to one of the Nano's GND pins.
- Connect power rails to each other. To get power along the rails on both sides of the breadboard, connect the rails on either side of the breadboard to each other by running a wire from the positive rail on one side to the positive rail on the other side. Repeat this with the negative rails.
Adding the Controls
Mosquito I uses five potentiometers and two buttons for controls.
Potentiometers:
- Place the pots on the breadboard. Place the pots so that each pin is on its own row.
- Connect pots to power rails. Connect the left side pin of each pot (if you're looking at the knob-side) to one of the negative rails on the breadboard. Connect the right side pin of each pot to one of the positive rails of the breadboard.
- Connect pots to Arduino. Connect the center pin of each pot to one of the analog pins on the Arduino. The first pot's center pin connects to A0, the second pot to A1 and so on with the last pot being connected to A4.
Push Buttons:
- Place buttons on the breadboard. Place the two push buttons on the breadboard so that they straddle the center channel.
- Connect positive sides. On one side of the breadboard, connect one of the push-button's pins to the positive rail.
- Connect negative sides. Place one of the 1K resistors on the breadboard so that one end is connected to the push button's unused pin and the other side of the resistor connects to the negative rail.
- Connect button to Arduino. Run a wire on the row that connects the button to the negative rail to the D2 pin. Do the same with the other button but connect it to D3.
Adding Outputs
We're outputting audio from pin 9 as well as flashing an LED on the first step of every sequence. Here's how to set up the hardware for that.
LED
- Place an LED in an empty space on the breadboard.
- Connect the negative (short) leg of the LED to the negative rail.
- Place current-limiting resistor. Connect one side of a 330 ohm resistor to the positive (long) leg of the LED. Connect the other side of the resistor to pin D4 of the Arduino.
Audio Output
- Place the RC network. The output signal from the Arduino is coming from pin 9 but the signal can be a bit hotter than some speakers can handle. To bring it down to something closer to line level, I've added an RC network (based on a design by Notes & Volts). Place the 33nF and 100uF capacitors, along with the 2K resistor as shown in the image/schematic. Make sure that the electrolytic 100uF capacitor is connected with the right polarity (the positive/long leg going to pin 9 on the Arduino and the negative/short leg connected to the jack).
- Connect the negative side of the audio jack to ground. Audio jack connections will vary slightly depending on the type your using, but they generally all work the same. We need to connect the sleeve of the jack to ground. This is sometimes marked with a minus symbol or labeled as "sleeve", "ring", or "gnd". If there are no labels on your audio jack, you may need to consult the datasheet or just do a close inspection of the jack and see if you can determine which pin is connected to the sleeve or outer ring of the jack.
- Connect the positive side of the audio jack to the negative side of the 100uF capacitor. Our audio signal now flows from pin 9 of the Arduino through the RC network and emerges from the negative side of the 100uF capacitor. We'll connect that to the positive side of our audio jack. This is usually marked with a plus symbol or might be labeled "tip". Again, if it's not labeled, you may need to inspect it to figure out which pin will connect to the tip of the jack. Also, if you're using a stereo jack, there may be a L tip and R tip connection. Since we're outputting a mono signal, you can just connect to either one of the tip connections.
Important: If you find that the audio is too quiet you might be able to eliminate the RC network in step 1 and connect directly to the audio from pin 9 of the Arduino. This should be okay if you're connecting the audio to something with a pre-amp like external computer speakers where you have a volume knob, but I wouldn't recommend it for things like headphones, earbuds, or directly wiring to a speaker. If you do decide to eliminate the RC network, I suggest turning the volume on your speakers all the way down before firing up the Arduino, and then gradually increasing the volume to avoid blowing out your speakers.
After you've got everything set up, double-check that all the connections look correct and match the image and schematic above
Uploading the Code
Now that the hardware's all setup, we're ready to tackle the software side:
- Launch the Arduino IDE. On your computer, launch the Arduino IDE (if you don't have it, you can download it from https://www.arduino.cc/en/software).
- Download the Mozzi library. The Mozzi library is what allows us to use our Arduino as a synthesizer. To get this library in your IDE, go to the Mozzi github page https://sensorium.github.io/Mozzi/download/. Click on the green "Code" button and choose Download ZIP.
- Install the Mozzi library from the zip file. In the Arduino IDE, go to Sketch->Include Library->Add .ZIP Library... Navigate to the zip file you downloaded to add it. You should now see Mozzi listed under the Sketch->Include Library section.
- Download the Mosquito I Arduino code. You can get this from my github site https://github.com/analogsketchbook/mosquito_one. (Note the schematics are also available there if you need them for wiring reference.
- Connect the Arduino to the computer and upload the code.
Messing Around
That's it. You should be able to connect your speakers to the audio jack and hear the sweet sound of arpeggiated synthesis from that ittybitty Nano! If you don't hear anything at first, try centering the knobs on all the pots to make sure you're getting decent starting values.
Here's what the controls do:
Pots:
Rate: This controls how fast the sequencer plays back. Turning it down plays discrete notes in sequence. Turning it way up smears the notes together to create completely new waveforms.
Legato: The second pot controls legato or note length. Turning it more to the left produces short, sticatto notes, while turning it to the right produces longer notes.
Pitch: This sets the base pitch for the sequence. The pitch control is setting MIDI values, so it increases/decreases the pitch in semitoness rather than a continuous pitch shift.
Phase: Turning this knob to the right introduces a subtle phasing effect. Technically speaking, this is causing the two oscillators in Mosquito I to be slightly detuned which is what causes the phasing. It's not, however, tracking with the pitch so the phasing effect is probably more noticeable on lower pitch notes.
Filter: This knob controls the cutoff frequency of a Low Pass Filter. Turning it to the left cuts off the high frequencies producing a more muffled sound, while turning it to the right produces a brighter sound.
Buttons:
Mosquito has over twenty different sequences it can play by default. The push buttons allow you to select which sequence is playing. One button moves you up the list of sequences and the other goes down the list.
Customization
I've added a bunch of default sequences, mostly different scales, but you can customize the code fairly easily to change the sequence of notes being played, add new ones, or change the number of notes in a sequence. Below are the details of how that's being done in case you want to customize it.
Changing Notes in Existing Sequence
The sequences are store in an array of arrays called NOTES. Each note is stored as a MIDI note value, so if you want to change notes in a particular sequence, just change the MIDI note numbers for that sequence. The default setup is to play 8 steps per sequence so you can only have 8 MIDI values in a sequence (see below if you want to have different sequence lengths).
One thing to note, the pitch knob adds a note offset to the MIDI values specified in the NOTES array. When the knob is centered, it plays the MIDI notes indicated in the array, but as you turn the pitch knob it adds or subtracts a semi-tone to the notes being played.
Adding New Sequences
You can add new sequences to the NOTES array by simply adding a new 8-note array at the end of the list. If you do this though, you'll also need to change the value of the numSequences variable to match the new number of sequences. For example, the NOTES array has 21 sequences by default so the numSequences variable is set to 21. If you add one new sequence, you'll need to change the numSequences variable to 22.
You can add as many new sequences as you want.
Changing Sequence Length
If you want to change the length of your sequences (if you want say a 4-step or 16-step sequence), you can do that, but the only caveat is that all sequences need to be the same length. You'll also need to set the numNotes variable to match the length of your sequences.
Other Changes
There are a number of other customizations that are possible such as switching waveform types, filter settings/values, which are beyond the scope of this tutorial. Figuring out Mozzi code can be a bit challenging at first, but I've tried to document the code as much as possible to show what the various parts of the code are doing.
There are a few main parts of the code for Mozzi which have fairly specific uses and I've listed them below to give you and idea of what they're used for:
- setup() - If you've programmed for Arduinos before you're familiar with this function and it's pretty much used the same in Mozzi. We use it mostly to setup default settings for oscillators, filters, etc.
- updateControl() - This is where the lion's share of the Mozzi code is doing it's work. It's where we read pot and button values, map and transform those values to feed into the synthesizer, and where the sequencing is being done.
- updateAudio() - This is the final output from the Mozzi library. Typically the code here is kept very small and lean because this function is being used by Mozzi to maximize all of the clock cycles it can. As you can see in the mosquito code, it can be a bit cryptic but all we're basically doing combining/multiplying our various waveforms and then bitshifting them to fit a specific number range. It's best to keep this function very light (not Serial calls or reading pins) and put most of the stuff in the controlUpdate() function instead. The Mozzi documentation details this more thoroughly.