Arpeggiating Synthesizer (Mosquito I)

Introduction: Arpeggiating Synthesizer (Mosquito I)

About: VFX Artist, Painter, Musician, Maker

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

Step 1: Setting Up the Arduino

First, let's get the Nano on the breadboard and set up our power:

  1. 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.
  2. 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.
  3. 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.

Step 2: Adding the Controls

Mosquito I uses five potentiometers and two buttons for controls.

Potentiometers:

  1. Place the pots on the breadboard. Place the pots so that each pin is on its own row.
  2. 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.
  3. 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:

  1. Place buttons on the breadboard. Place the two push buttons on the breadboard so that they straddle the center channel.
  2. Connect positive sides. On one side of the breadboard, connect one of the push-button's pins to the positive rail.
  3. 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.
  4. 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.

Step 3: 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

  1. Place an LED in an empty space on the breadboard.
  2. Connect the negative (short) leg of the LED to the negative rail.
  3. 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

  1. 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).
  2. 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.
  3. 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

Step 4: Uploading the Code

Now that the hardware's all setup, we're ready to tackle the software side:

  1. 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).
  2. 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.
  3. 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.
  4. 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.
  5. Connect the Arduino to the computer and upload the code.

Step 5: 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.

Step 6: 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 leanbecause 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.

3 People Made This Project!

Recommendations

  • Anything Goes Contest 2021

    Anything Goes Contest 2021
  • Knitting and Crochet Speed Challenge

    Knitting and Crochet Speed Challenge
  • Jewelry Challenge

    Jewelry Challenge

3 Comments

0
anders.b.dahlqvist
anders.b.dahlqvist

7 months ago

Hi! This looks like a really fun project.
Do you think there's some way of syncing this with other stuff using a click track?
like, maybe it could execute an arpeggio every time it detects a click, that is, when a pin goes high?

0
analogsketchbook
analogsketchbook

Reply 7 months ago

That's an interesting idea! Things can get tricky with timing in Mozzi because it's trying to use every possible clock cycle for tone generation but I think it should be possible to sync it to an external trigger.

I'm using a relatively simple method of controlling the playback speed by just having the Rate pot drive a Mozzi EventDelay which controls how long we wait between notes.

For something that needs more explicit control of timing (like a click track/trigger) think a better approach would be to use a Mozzi object called ADSR which is an envelope generator. This would give you precise control over when the note starts/stops so you could start each note of the sequence exactly when you want. Of course you'd still have to keep track of each click's timing and set the delay after that to keep things spaced properly.

It's a different approach to playing the notes than I'm currently using so the code would have to be re-worked quite a bit, but it might not be too bad. You'd probably also have to tweak the parts of the code that control the legato. My code uses the Legato pot to control the "on" cycle of the note relative to the "off" cycle. You would probably want to replace that by having the Legato pot control the sustain value in the ADSR (that's the "S" in ADSR) instead. So in that regard it might actually make things simpler.

If you end up giving that a try, let me know how it goes. Who knows, maybe I'll have to work up a Mosquito II that uses an ADSR...could open up some interesting possibilities!

0
jumperd1981
jumperd1981

1 year ago on Step 6

Me again. Hey. I am still working with my son on this. We had a working prototype that worked really well and decided to get a little more "permanent" and place inside a hand made wood cabinet with a amp module and some speakers, 8 years old and he soldiered it himself. It is proving a little more complicated because we are attempting to use lots of spare parts instead of new stuff. So we hit a little snaffu with incorporating a volume pot for the input on the amp. I think from what I gather it is a combination of a ton of unshielded wiring and possibly shielding electronics from fan and speaker magnetic fields. AND I was trying to use a A500k pot from an old guitar that I upgraded. So I have ordered the correct pot and some new wiring...once I am finished I wanted to send you or share with you the complete build out...it will be a little bit since the holidays and such are a bear.

Suffice to say, I have been picking your brain and a couple users brains on Arduino forums and why did I wait until now to jump into this stuff. This is more fascinating than I ever imagined. Thanks for you instructions, and patience. I am a tech head, been doing a lot of electronic repair, but never really had to design anything on my own...I am including some UV lights, and a cooling fan as well as a volume pot, and the cabinet will hopefully have enough room to include at least one more device...and there is a voice synth machine that is crying to be included...

For now I am waiting patiently for new stuff to come so we can continue...in the meantime we are working on circuit bending on an old 1980s Casio keyboard.

Regards.

UPDATE:: Having a few issues with the RC network. I think I am going to remove it, and use a pot for volume on the input to the amp instead of relying on this. I think the network works a little to well for our specific amp because the sound is very weak. Also finding that in a closed cabinet with speakers and all the electronics, shielding is a real thing.

Thanks again.