For Moogfest this year, Smashing Boxes will be hosting a VIP reception featuring some innovative projects we have done in the areas of digital art, machine learning, and data visualization. We want to do more than just show however; we wanted to give participants something that they could go home and hack on as well. Our goal was to put together a small kit of electronics that would allow festival-goers to build their own programmable synthesizer. We are not associated with any of the products discussed in this post; we simply wanted to put together a kit that could be functional for around $20, including prototyping materials like a breadboard and wires.This guide will walk through all the parts needed, the theory behind how this project works, how to assemble the parts, and how to write software that controls it.[embed]https://vimeo.com/218178006[/embed]
First we’ll take a look at a few of the circuits that make this synthesizer work. If theory isn’t your thing, you can skip this section and jump right into the build.
In order for a speaker to produce sound, it needs to be fed a signal that causes the cone to move back and forth. This is typically done by producing a very weak signal, like one coming from a microphone or guitar, and putting it through an amplifier.For our cheap version, we will be using a transistor to simply switch the speaker all-on and all-off. A transistor is a voltage controlled switch; it allows us to turn on and off a high current circuit (like a speaker) using a low current circuit (like a microcontroller pin).
When the microcontroller pin goes high, the speaker circuit turns on, sending current through the speaker and causing the cone to move. When the pin goes low, the circuit is shut off and the cone moves back. These movements produce sound! The big limitation of this circuit, however, is that the signal is either all-on or all-off (digital), meaning it will only create a square wave.You may also notice that there is a resistor in the picture. The speaker that we chose is rated at 0.5W, and has an impedance of 8 ohms. Power is calculated as:P = IV = V^2 / RFor V = 5V; R = 8 Ohm, the power calculates out to 3.125W! In order to make sure that the speaker doesn’t burn out, we need to add a current limiting resistor. Since we cannot change the impedance of the speaker, we need to change the input voltage by using a simple voltage divider. If we instead solve for V in the formula above by fixing R = 8 Ohm, P = 0.5W, we find that the max voltage for the speaker is 2V. We can finally calculate the resistance needed using:2V = 5V * 8 Ohm / (R1 + 8 Ohm)Solving this, we find that we need at least a 12 Ohm resistor to not burn out our speaker. For this kit, we chose 24 Ohm just to be safe.If you are interested in making a circuit that can do more than just square waves, check out the Using Analog Outputs section in Where to Go From Here below!
The potentiometer circuit we will be using is much simpler. A potentiometer is simply a resistor with a third connection (the wiper) that can be moved around using a physical dial. We will be using the potentiometer to create a signal between 3.3V and GND that the user can control using the dial.
When the dial is turned all the way in one direction, the wiper will be connected to the 3.3V line. When you turn is all the way in the other direction, the wiper will be connected to ground. Anywhere in between it will be at some voltage in between 3.3V and ground. By connecting the wiper to an analog input on your microcontroller, you can get a reading of where the dial is currently at.
If you haven’t used a breadboard before, check out this tutorial which goes through the basics of how the breadboard is internally connected. Our guide will use the notation letter:number to denote the row and column that the wires or parts should be placed in. These letters and numbers are marked on the board suggested in the parts above.
Let’s start by laying out where all the components will go. Start by connecting the Nucleo board to the top of the breadboard so that pin D1/TX is connected to d:1 and VIN is connected to h:1. Connect the resistor to the very bottom of the board: e:30 and f:30. The potentiometer will be connected to g:20,21,22 with its side legs set in the groove in the middle of the breadboard. The transistor should be connected to j:22,23,24. The transistor should have its flat side facing the center of the breadboard.
To wire the potentiometer, connect the following pins:- Potentiometer Pin 1 i:20 to the microcontroller’s 3.3V line, j:14.- Potentiometer Pin 2 i:21 to the microcontroller’s A0 input, j:12.- Potentiometer Pin 3 i:22 to the microcontroller’s GND pin, j:2.
Finally, lets wire the speaker and transistor up.- The PWM audio signal a:6 to the gate of the transistor i:23.- One speaker cable to the source of the MOSFET, i:24.- One speaker cable to one side of the resistor, j:30.- The 5V line i:4 to the other side of the resistor, a:30.
Note: there is an error in this picture. Instead of a:30 being tied to the 5V line, it is tied to Vin. Please connect a:30 to j:4, not j:1 as depicted in the picture.
The final wiring diagram should look like the following:
Once these are all connected, your breadboard is ready to be programmed. Check out the sections below to start programming your board, or alternatively, check out our moogfest-2017 repo for some stock programs to test that your board is working!
In addition to the hardware specs and costs, we also chose the Nucleo board because it can be easily programmed using mbed.org. Mbed is an online IDE that allows you to compile your code remotely, download it, and then drag and drop it into the microcontroller’s memory. If you want more information about the platform, we recommend mbed’s getting started guide.As was mentioned in the beginning, we need to be able to do two things: output a square wave, and read the position of the potentiometer. The mbed platform makes both of these tasks easy. The code to create a square wave is simply:// Create an instance of a PWM object
// Set the period, or time between cycles, to (1.0 / FREQ).
// Set the duty cycle, or amount of time at the top of the
// square versus the bottom of the square, to 0.5 (50%).
// This will start the note.
Likewise, the code to read an analog input is:// Create an instance of an Analog input
// To read the input, simply call the read() function.
float reading_1 = potentiometer.read();
// This does the same thing, but has a shorter notation.
float reading_2 = potentiometer;
That is pretty much all you need! We can use these primitives in a bunch of different ways to create sound. Creating a basic synthesizer that lets you use the potentiometer to sweep through 3 octaves is as simple as:my_pwm.write(0.5);
while(1) my_pwm.period(1 / (220 + 1540 * potentiometer));
We wanted to make something a little more complex though, so we made a demo that lets the user shift the pitch dynamically for the Giorgio Morodor rhythm from Daft Punk’s Random Access Memories. There are a couple of helper functions that allow you to call notes by name instead of frequency and to keep basic tempo.The code for this demo can be found here. If you just want to program your controller and go, you can download the compiled version: giorgio.bin. To program the Nucleo, plug it into a computer and it will enumerate it as a flash drive. You can then drag-and-drop the .bin file onto the Nucleo and it will reprogram itself and start running this program.
In this example, we used one of the 9 analog inputs to read in the signal from a potentiometer. Analog inputs can be used for so much more, from reading temperature sensors and light sensors to reading inputs from your other synthesizer components. We recommend checking out sparkfun.com or adafruit.com for more easy to use, well-documented components.
Square waves are great, but there are so many other waves that can completely change the sound of the synth. As mentioned before, there are 2 digital-to-analog outputs, or DACs, that allow us to send an analog signal out of our chip. This opens the door to all kinds of other waves that are common in synths, such as sine waves and sawtooth waves. Since the transistor driver circuit is on-off only, we will have to use one of the following two ways to output our sound into the world:
Hopefully this covers everything you need to know in order to build your own programmable synth. If you have any problems with setting things up, we’ve set up an email that you can use to ask questions: email@example.com. If you use this kit to build a cool new type of synth, we would also love to hear about it.The reason we are hosting this event is to highlight the projects that have spun out of Smashing Labs, including this synth kit. We hope that if you are at Moogfest, you have the chance to check out some of the other fun projects that we have been working on this year.Good luck, and happy hacking.
Smashing Boxes is a creative technology lab that partners with clients, taking an integrated approach to solving complex business problems. We fuse strategy, design, and engineering with a steady dose of entrepreneurial acumen and just the right amount of disruptive zeal. Simply put, no matter what we do, we strive to do it boldly. Let's talk today!
IoT has the ability to unlock enhanced experiences across a broad spectrum of industries, and music is no different.
It’s 2021 and the Internet of Things (IoT) is no longer the new and shiny toy. The “things” are ubiquitous and becoming ever more so by the day. Today, we are talking about data and data security, but this subject is still in its infancy.
Nick Jordan recently spoke at the IoT Evolution Conference and Expo in Miami, covering the exciting future of infrastructure investment.