-
1Step 1
All schematics for this project are shown above. All the Arduino pin connections are listed below:
Analog
0 - Gyroscope Y (Y4.5)
1 - Potentiometer 1
2 - Gyroscope X (X4.5)
3 - Accelerometer Y (YAcc)
4 - Accelerometer X (XAcc)
5 - Potentiometer 2Digital
0 - serial in - this must remain unconnected
1 - serial out - this is hooked up to the MIDI output
2 - 74HC165 data pin (Q7)
3 - 74HC165 clock pin (CP)
4 - 74HC165 latch pin (PL)
5 - 74HC595 clock pin (SH_CP)
6 - 74HC595 latch pin (ST_CP)
7 - 74HC595 data pin (DS)no connections to digital pins 8-13
-
2Step 2
Solder LEDs and diodes to sparkfun board, be mindful of their orientation.
Thread the leads of 16 LEDs (5mm or 3mm are fine, I used 5mm) through LED holes in the Sparkfun PCB. These boards are compatible with 4-lead RGB LEDs, so there are four available holes on each button pad. You can use the two center holes for single color LEDs. Be sure that the flat edge of the LED (the cathode) lines up with the flat marking on the PCB.
Cut about 1ft of 16 conductor ribbon cable. Separate and strip the ends of all 16 wires on one side and solder to Sparkfun PCB. The following list gives all the colored conductors in order with the name of the PCB hole they should be soldered to, if you do this correctly none of the wires should cross. Note that since I'm only using a single color LED, I'll wire up only the "blue" anode.
Connections:
one side of ribbon cable
Brown SWT-GND1
Red LED-GND1
Orange SWT-GND2
Yellow LED-GND2
Green SWT-GND3
Blue LED-GND3
Purple SWT-GND4
Grey LED-GND4
White BLUE4
Black SWITCH4
Brown BLUE3
Red SWITCH3
Orange BLUE2
Yellow SWITCH2
Green BLUE1
Blue SWITCH1
other side of ribbon cableUse a bench vice to clamp the16 pin socket on the ribbon cable. If you do not have a bench vice do not use pliers do this, you will clamp the socket on sideways and mess up the connections. You're better off using a hammer to tap the clamp shut, just make sure you are always applying pressure evenly across the socket.
Be sure the clamp the socket on the ribbon cable in the same orientation indicated in the images above.
-
3Step 3
Two 74HC595s (wired in parallel) will be driving all the LEDs in the project as well as providing power to all of the buttons. The 74HC595 is an 8 bit serial in parallel out shift register. I've written a detailed tutorial about multiplexing with the 74HC595, and you can find more info about this chip on its datasheet. Please note that the 74HC595 drawn in the schematic is not a pin diagram, I have rearranged the order of the pins to make the circuit diagram more clear. The pin diagram for the chip is shown in fig 4.
The 74HC595 has the following pins (the technical name may be one of several things depending on which data sheet you are reading):
Position / Common Name / Technical Name
1 parallel output 2 QB or Q1
2 parallel output 3 QC or Q2
3 parallel output 4 QD or Q3
4 parallel output 5 QE or Q4
5 parallel output 6 QF or Q5
6 parallel output 7 QG or Q6
7 parallel output 8 QH or Q7
8 ground GND
9 serial data output QH' or Q7' or Q7S
10 master reset (active low) MR(with a line on top) or SRCLR(with a line on top)
11 clock pin SH_CP or SRCLK
12 latch pin ST_CP or RCLK
13 output enable (active low) OE(with a line on top)
14 data pin DS or SER
15 parallel output 1 QA or Q0
16 5 volts supply VCCThe connections between the 74HC595 and the sparkfun board are shown in the schematic and repeated below:
74HC595 / Sparkfun Breakout Board
Q0 BLUE 4 and SWITCH 4
Q1 BLUE 3 and SWITCH 3
Q2 BLUE 2 and SWITCH 2
Q3 BLUE 1 and SWITCH 1
Q4 LED GND 4 (via current limiting resistor)
Q5 LED GND 3 (via current limiting resistor)
Q6 LED GND 2 (via current limiting resistor)
Q7 LED GND 1 (via current limiting resistor)The remaining pins have the following connections to the Arduino (also shown in schematic):
74HC595 / Arduino
Vcc 5V
GND GND
DS Digital Pin 7
OE(line on top) GND
ST_CP Digital Pin 6
SH_CP Digital Pin 5
MR(line on top) 5V
Q7' no connectionThe 74HC595s will be driving the LEDs in the sparkfun board. However, each chip only outputs 0 or 5V and it can output as much as 70mA. This means we must use current limiting resistors to prevent damaging the LEDs.
From the specs of the LEDs I used:
max forward current: 30mA
forward voltage: 3.2VCalculate the resistance needed to achieve these max ratings from V = IR:
resistance = (5V-3.2V) / (0.03A)
= 60 ohmsI used 68 ohm resistors so that I was not running at the absolute maximum, but also ensuring that I wouldn't lose too much brightness. (I made a mistake a grabbed the 100KOhm resistors when I made this project, I fixed it later, but the stripes of 100Ohm resistors should be blue, grey, black, gold, ignore the colors in the images).
These are the sample calculations for the specific LEDs I used, you'll need to do you own calculations based on the specs of your LEDs. If you are unsure of what to do, use 220ohm or higher resistors; using too much resistance will make the LEDs less bright, but they will not be damaged.
The pins connections to the 74HC595s should be as follows:
Pin 15 - Blue 4
Pin 1 - Blue 3
Pin 2 - Blue 2
Pin 3 - Blue 1
Pin 4 - LED GND 4
Pin 5 - LED GND 3
Pin 6 - LED GND 2
Pin 7 - LED GND 1data pin (pin 14) digital pin 7
latch pin (pin 12) digital pin 6
clock pin (pin 11) digital pin 5Each 74HC595 can only source 70mA at a time for all its pins. With the 100ohm current limiting resistors, if all 4 LEDs in a row are on at the same time (with multiplexing this is the max number of LEDs that can possibly be on at the same time), they will each draw about 18mA which puts the current requirements slightly above the 70mA maximum rating. I'll be drawing additional current from pins Q0-Q7 to multiplex the buttons (in later steps). An easy solution to this problem is to add another 74HC595 to the circuit, it will be wired parallel to the current 74HC595 (see schematic). This will give us additional 70mA to draw from on all 8 pins.
Add another 16 pin socket to the protoboard and wire pins 1-7 and 15 of the sockets to each other (see note on schematic). These pins correspond to all eight outputs of the 74HC595s.
Connect pins 11, 12, and 14 of the sockets to each other. These correspond to the clock, latch, and data pins of the 74HC595s.
Wire pin 10 to 5V (pin 16) and pin 13 to ground (pin 8). Pin 10 (MR) should be high and pin 13 (OE) should be low in order to send data to the output pins (Q0-Q7).
-
4Step 4
The 74HC595 can only do parallel output, so I used a 74HC165 to measure the state of the buttons via 4 current limiting resistors and send this information to the Arduino. More info about the chip can be found on its datasheet.
The 74HC165 has the following pins (the technical name may slightly different depending on which data sheet you are reading):
Position / Common Name / Technical Name
1 latch pin (active low) PL(with a line on top)
2 clock pin CP
3 parallel input 4 D4
4 parallel input 5 D5
5 parallel input 6 D6
6 parallel input 7 D7
7 inverse serial output Q7(with a line on top)
8 ground GND
9 serial output (data pin) Q7
10 serial input DS
11 parallel input 0 D0
12 parallel input 1 D1
13 parallel input 2 D2
14 parallel input 3 D3
15 clock enable input (active low) CE(with a line on top)
16 5 volts supply VCCThe connections between the 74HC165 and the Sparkfun board are shown in the schematic and repeated below:
74HC165 / Sparkfun Breakout Board
D0 SWITCH GND 4 (via current limiting resistor)
D1 SWITCH GND 3 (via current limiting resistor)
D2 SWITCH GND 2 (via current limiting resistor)
D3 SWITCH GND 1 (via current limiting resistor)The remaining pins have the following connections to the Arduino (also shown in schematic):
74HC165 / Arduino
Vcc 5V
GND GND
CE(line on top) GND
DS GND
Q7 Digital Pin 2
Q7(line on top) no connection
PL(line on top) Digital Pin 4
CP Digital Pin 3Connect the data pins of the 74HC165 to the Arduino.
Pin connections (also shown in schematic):74HC165 Arduino
PL(line on top) (pin 1) digital pin D4
CP (pin 2) digital pin D3
Q7 (pin 9) digital pin D2 -
5Step 5
This instrument is primarily a MIDI device, so we need to build a MIDI out. There are two ways to do this (and over the course of this project I did one and then switched to the other):
output MIDI via a 5 pin DIN connector
output MIDI via USB (this is what I eventually settled on)Either of these options is fine, I chose USB because I didn't want to have to carry a special MIDI to USB cable all the time. If you have a lot of synthesizers that receive a 5 pin MIDI input, it might be more convenient for you to use the 5 pin jack (it's also a little easier). I'll go through both processes below:
5 pin connection:
Solder a 220ohm resistor to pin 4 of the MIDI jack and connect to Arduino 5V. Solder a wire between MIDI pin 2 and ground. Solder a wire between MIDI pin 5 and digital pin 1 (TX).
MIDI over USB:
MIDI over USB is a little tricky. Ideally we'd be able to send MIDI out the USB port already connected to the Arduino, but this turns out to be more trouble than it's worth in my opinion. You can read a little bit about various solutions here. Instead, I found a really great tutorial that explains how you can take apart a cheap MIDI to USB cable, solder new connections to it, and tuck it inside your project enclosure with your Arduino, to create a secondary MIDI-USB output. The process is explained really well on the Shiftmore blog, but the MIDI to USB cable I received from amazon was a little different, so I'll describe the process again here.
Remove the plastic casing from the MIDI to USB cable and unsolder the connections to the cables on either end (fig 8). The USB connections are shown here, make the following connections:
5V +
DP D+
DM D-
VSS -As you can see in figs 9 and 10, I used a pieced of perf board to make the connections to the USB jack. On the other side of the MIDI to USB board, make the following connections to the Ardunio:
IN- Digital Pin 1 (TX)
GND Arduino Ground -
6Step 6
I attached a 2 axis gyroscope and 3 axis accelerometer onto this project so that I could add some interesting control to the device. The 5 degrees of freedom board from Sparkfun outputs data from its gyroscope and accelerometer as analog voltages. I sent these to analog pin 0-4. You may notice that the Gyro has four outputs- I chose to use the X/Y4.5 out instead of the X/YRate out because the 4.5 has higher resolution. I wrote more about this board and explained some of the code I used to get it up and running here.
Solder header pins on the gyro/accelerometer board. Solder on the perfboard, making sure to leave room for the Arduino to fit on top. Make the following pin connections:
RAW - Arduino 5V
GND- Arduino ground
X4.5- A2
Y4.5- A0
XAcc- A4
YAcc- A3 -
7Step 7
I borrowed an idea from my friend Mads Hobye for my enclosure. Mads founds these sleek boxes at the container store and used them to make project enclosures for the various musical instruments he's built. These boxes are particularly convenient because they have a bevel around the top that allows you to easily mount a 5mm acrylic front panel.
I used a laser cutter to cut out two USB ports (one for the Arduino and one for MIDI out) in the bottom of the enclosure. Then I used a drill to make holes for two pots, a power switch, and a charging jack.
I laser cut a front panel from translucent white 5mm acrylic so that it would snap fit into the wood box.
Find the vector files here
-
8Step 8
For the final firmware, I've extracted all the code that controls the buttons and leds into a library to make it more tidy, all of this is in a class called SugarCube. I was inspired by the work I've been doing on the Instructables iOS app, and wrote the event handling pieces of the code so that they work in a similar way that an iPhone deals with touch and other gestural events. Basically I created a set of methods that each app can subscribe to, things like "deviceWasShaken" or "buttonPressed". When the SugarCube class detects one of these events, it tells the current app to execute the corresponding method. If you're interested in seeing an example of this structure in action, check out SimpleMIDIKeyboard.cpp, it shows how few lines of code are needed to wire up all the button and analog controls to MIDI outputs. I hope to eventually write out a little more complete documentation for how to write your own apps based on this framework, please let me know if there is interest. This is by far my biggest piece of C++ code, and I am by no means an expert in C++, I'd love to hear an expert's thoughts on how I did!
Find it on Github:
https://github.com/amandaghassaei/Sugarcube-Arduino-Library
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.