Picture of Sugarcube MIDI Controller
IMG_0286 copy copy.jpg
IMG_0279 copy copy.jpg
IMG_0273 copy copy copy.jpg

This project is a portable, Arduino-powered, grid-based MIDI controller that boots up into a variety of apps to do lots of things with sound. It has 16 backlit buttons, used as both inputs and outputs to give the controller some visual feedback. 2 potentiometers give analog control, depending on the app the pots are assigned to tempo, MIDI velocity, pitch, and scrolling (making the avaible grid space larger than 4x4). An x/y accelerometer and an x/y gyroscope add some playful, gestural control to the device; most of the apps implement a "shake to erase" control and several respond to tilt in various ways. It boots up into 7 different apps (described below), though it has the potential to boot up into 16 total. This device is primarily a MIDI controller, but I've also written an app that allows you to pull the button and analog data into MaxMSP and to control audio.

This controller was inspired by both the monome and tenori-on. When I was in college, I built a large touchscreen display, based on the Arduinome monome-Arduino clone schematics and code, that worked with all the open source monome applications written in MaxMSP. There are a ton of people building their own monome-type devices using these buttons from Sparkfun and the Arduinome code, as well as a few variations on the theme. With this project, I was interested in making a device that was a little more self-contained and relatively cheap to make (lots of buttons = lots of $). In keeping more with the concept of the tenori-on, this controller does all its app processing itself, it does not rely on a computer to process button presses/analog controls into MIDI. This means you can plug it directly into a synth or any device that understands MIDI and you're good to go, no computer required. It runs off a beefy LiPo battery that keeps it running for days on a charge, so it's fairly portable as well. In keeping with the monome side of things, it's totally open source and can be adapted to your particular audio setup/needs. All the Arduino code is up on github (click the cloud-shaped button to download), along with a MaxMSP patch that decodes data from the controller into something usable in Max.

An overview of the apps I've written so far:

Pixel Tilt - One pixel moves across a 2D keyboard with tilt, triggering MIDI as it moves. Control velocity and basenote with pots.

Flin - Music Box app based on monome. Speed and velocity of notes controlled by y tilt. Paging across 16 "lanes" with pot. Shake to erase.

Serial Communication with MaxMSP - Pull data from buttons and analog controls into MaxMSP and use Max to send LED states. Supports 5 bit analog controls for x/y accelerometer and 2 pots. This is great if you want to run audio processing applications with the controller. Download SerialDemo app (SerialDemo.maxpat, included with the Arduino files, click the cloud-shaped button here) to parse data in Max. Beat slicer (shown above) app is included with the Arduino files as well.

Arpeggiator - Plays a two, three, or four note arpeggio, similar to this app I wrote for monome. One pot controls the speed of the arpeggio, another controls velocity. Notes within the arpeggio can be shifted up or down by one semitone via button controls. The whole arpeggio is transposed via x tilt. Press the leftmost note in the arpeggio to play the notes in ascending order, press the rightmost note in the arpeggio to play the notes in descending order, and press a middle note in the arpeggio to play the notes in a random order. Shake to erase.

Boiing - Bouncing pixels that generate polyrhythms, based on this tenori-on app. Bounce direction based on y tilt. Speed and MIDI velocity (loudness) controlled by pots. Shake to erase.

Step Sequencer - Four note 16 step sequencer. Pots control tempo and paging across sequence. Shake to erase.

MIDI Keyboard - Simple MIDI keypad. Control velocity and basenote with pots, pitchbend with x tilt.

Parts List:

(1x) Button Pad 4x4 - LED Compatible Sparkfun COM-07835
(1x) Button Pad 4x4 - Breakout PCB Sparkfun COM-08033
(1x) Arduino Uno Sparkfun DEV-11021
(1x) Accelerometer/Gyro 5 Degrees of Freedom Sparkfun SEN-11072
I put a 3-axis accelerometer and 2 axis gyroscope in this controller to give it some gestural control, but so far I haven't actually used the gyro in any apps, and I've only got the x and y axis of the accelerometer wired up. That means you could sub in a simpler/cheaper part like this.

(16x) White 5mm LED (3mm is fine too) Digikey C513A-WSN-CV0Y0151-ND
(2x) 74HC595 shift register Digikey 296-1600-5-ND
(1x) 74HC165 shift register Digikey 296-8251-5-ND
(3x) 16 pin IC socket Digikey A100206-ND
(16x) 1N4148 Diode Digikey 1N4148FS-ND
(4x) current limiting resistors (value will depend on LEDs, sample calculation included in step 5)
(4x) 10kOhm 1/4watt resistors Digikey CF14JT10K0CT-ND
(1x) 220Ohm 1/4watt resistor Digikey CF14JT220RCT-ND
(1x) 5-Pin MIDI Jack Digikey CP-2350-ND (optional - explained in step 27)
(1x) USB type B female jack Digikey 732-2734-ND (optional - explained in step 27)
(2x) 10kOhm linear taper potentiometer Digikey 987-1308-ND

(1x) 16 conductor ribbon cable Jameco 28RC16-10VP
(1x) 16 pin right angle connector Jameco 746285-3
(6x) male header pins Jameco 103393

(1x) Midi Cable Radioshack 42-2149 (optional - explained in step 27)
(1x) Size N Panel-Mount Coaxial DC Power Jack with switch Radioshack 274-1576
(1x) Size N Coaxial DC Power Plug Radioshack 274-1573
(1x) SPST Toggle Switch Radioshack 275-634

(1x) Li-Ion 7.4V Tenergy 2200mAh Rechargeable Battery module with PCB Amazon
(1x) Tenergy Universal Smart Charger for Li-Ion/Polymer battery Pack (3.7V-14.8V 1-4 cells) Amazon
(1x) MIDI to USB cable Amazon (optional - explained in step 27)

(2x) Aluminum knobs Newark 74M6717

22 Gauge Wire, various colors Jameco #9313-0-R
electrical tape Radioshack 64-2373
wire cutters
wire strippers
wood/acrylic/project enclosure (I used this 6"x6"x2" bamboo box The Container Store)
double sided foam tape Amazon

Remove these adsRemove these ads by Signing Up
1-40 of 81Next »
liampower24 days ago

I've gotten an adafruit trellis button pad and controller ( which interfaces with the arduino through an on board chip multiplexer, communicating through the i2c protocol. How would I go about converting the sugarcube firmware to work with the adafruit trellis? Is it possible? My coding skills are pretty weak so any help is greatly appreciated.


mle101 month ago

When I connect to my computer through the Arduino USB port, I am able to see it in the serial port drop down in Hairless and am able to control MIDI sounds in FL studio but when I connect through the USB of the MIDI to USB cable, I get the message USB not recognized and it does not appear in Hairless. I tested the cable prior to taking it apart and it worked fine. Do you know what could be causing this discrepancy from Arduino USB port and MIDI to USB cable USB port?

amandaghassaei (author)  mle101 month ago

you should only use hairless if you're connecting through plain old usb, the point of hairless is to convert a "usb" message into a midi message in your computer. If you have a MIDI to usb cable and you are able to get that into fl studio, you should be good to go. right?

pj.jones.58952 months ago

AWESOME!! Whats the total cost? :)

markkuki3 months ago

Amanda, I have multimeter incase you are able to help with troubleshooting. On step 24 right now. After uploading your code, only one row of buttons lights up and they all light up at the same time when pressed (4 LEDs). All other buttons are non-responsive as of now.

NOTE: I am omitting the gyroscope and accelerometer. Note sure if or how much this changes things with the DIP chips? I have been following the schematics until this point and noting your mistakes in the pictures and fixing them as best as I could interpret them.

Steps 21-23 are a lot more confusing than the previous 20 steps.

Documentation is key for others to build properly. I think it is not ideal to show an image and then say "don't do it like that."

Seems you might be on vacation again? Hope you are enjoying it and looking forward to a reply when there is time. :)


I'm about to attempt the same thing... I just want the MIDI output part of this build...

My biggest question is this... what portions of the code can I scrap? Obviously, the gyroscope and rotary knobs, but I'm not sure about the rest. Coding Arduino's are still a weak spot of mine...

I basically want to assign each button a MIDI note, as the software I want to control can listen for MIDI notes on each playback button. When the SC button is pressed, it triggers that soundbyte from the software.

amandaghassaei (author)  bacarudaguy3 months ago
If you tie the analog pins to ground it should work as is. If you want to get fancy you can go in the code and comment out the parts where it's grabs accel/gyro data.
amandaghassaei (author)  markkuki3 months ago

did the code that just cycles through the buttons work correctly? I've updated the button schematic, are there other errors in the documentation? the gyro and acc should not affect the code in step 24. Where do I show an image and then say to do it differently?

I replied to baracudaguy an update on how my troubleshooting is going so far and what I have already eliminated as a point of failure. I think I fried my 74HC165 chip somehow but do not have another one on hand and won't be able to buy a new one until Friday morning when I am back home. Are you able to help with troubleshooting techniques to determine if the DIP is dead? Never done that kinda diagnosis before.

re: your question ... Step 22 - 74HC165 Part 3: (fig. 1) "these
should be connected to the analog pins, the design changed while I was
building, please refer to the schematic rather than this image."

Sorry, I just got a little confused because I thought there should be no mention of the analog pins until Step 28 and Step 29. Therefore, it begs the question what you mean by "these" what should be connected to the analog pins instead of digital pins that you were connecting in Step 22?

In my case, I am using 4 potentiometers as Attack, Decay, Sustain, Release for example, so I understand I will be using only 4 analog pins and the rest are free I think.

amandaghassaei (author)  markkuki3 months ago

I realized that I put it in the schematic, but I never mentioned in the text how to power the buttons - I think that may be your problem. Reread steps 19-24, I've made some edits that hopefully help with the clarity. I doubt you have damaged the 165, I've used them a lot and found them pretty sturdy chips.

Markkuki - have you checked all your solder connections on the 4x4 pcb?

Tested so far on Sparkfun PCB / perfboard (I am discretely testing everything (including components I know are working) since I didn't know where the best place would have been to start and this is good practice for me either way):

LEDs = OK (tested with Arduino code from Step 18)

4 x 100 Ohm resistors = OK

Diodes = OK (tested with multimeter to exact instructions that came with multimeter)

Ribbon Clamp Female Pins 1-16 = OK (discretely tested with multimeter)

Male Header Pins 1-16 for Ribbon = OK

NOTE: After cleaning with 91% isopropyl alcohol and toothbrush (believe it or not) now all rows are non-responsive aka not lighing the buttons.

NOTE: Steps not necessarily in the order I preformed each troubleshooting check.

Slowly but surely elimating potential points of failure. As I type this, I am waiting for my perfboard to dry from cleaning and will resolder the SWT GND pins that have the 10K Ohm resistors on them. The continuity I checked OK was at the male header pins but my soldering was messy so not necessarily continious from the lead wires at the header pins going to the 74HC165 socket. Meaning, if I touched certain spots of the joined solders I could not get a signal (multimeter in "beep mode" so to speak).

Furthermore, I do not have another 74HC165 chip to test/swap in... so who knows that DIP could have been defective straight out of the bag since it was not in a anti-static vacuum sealed bag or I damaged somehow by accident.

mle103 months ago

Great project! I am on step 25 and am getting no response from my sugarcube when uploading the code and the running the individual beatslicer app. In step 24, I needed to set the pin modes individually using pinMode() to get it to work. I am using a SainSmart Mega 2560 R3 instead of an arduino uno though. Do you know of any differences between these that would cause some of your code not to work? Any advice would be greatly appreciated!

amandaghassaei (author)  mle103 months ago

yes you're going to run into problems if you use a board other than uno or duemilanove. It's possible to use a 2560, but not supported with my code.

I added up the prices of the parts listed above, excluding the basics such as wire, solder, cutters, etc. and making a couple of substitutions for parts that are no longer available, and this project comes out to $146.63. Pretty pricy, though it could be reduced by scrapping some of the optional parts or finding cheaper alternatives. Attached is a spreadsheet with the price breakdown.

amandaghassaei (author)  StephanStansfield3 months ago

nice, thanks for posting this. markkuki did just point out one small error in the parts lists - 2x the 595 and 1x the 165, not 3x the 595. and I noticed one other thing: 16 leds instead of 20. little change in the price though. Yes you can definitely find cheaper alternatives - all the Radioshack parts could be found for cheaper on amazon or digikey. Using plasic knobs instead of aluminum ones, maybe finding another battery - anything that outputs between 7 and 12V will work.

Very true...the most expensive item after the Arduino is the battery charger, and the MIDI cable is also pricy, although neither of these are really part of controller. I think this could definitely be built for under $100.

markkuki3 months ago

In the parts list at the intro prior to step 1 you mentioned about needing

(3x) 16 pin IC socket.

These do not come up in the 37 steps that follow. I bought a (4x) 16 pin IC socket that are the general kind (I assume this to mean the pin out would differ from the shift register in Step 19?). Thus, I suppose I am still missing the 74HC165 component that is mentioned later in the documentation?

amandaghassaei (author)  markkuki3 months ago

the sockets are used for the chips (see step 9). The sockets do not change the pin out, they are just adapters that let you mount the chips on your pcb non-permanently in case you need to replace them later. Does that answer your question?

ahh, I think I get it now. So the (2x) 74HC595 and (1x) 74HC165 each have their own sockets and the DIP chips are pressed on top of their respective sockets which are already connected and hard soldered to the PCB?

amandaghassaei (author)  markkuki3 months ago


Nice, thank you!

Btw, could you please update the parts list for future reference for everyone?

The parts list just says (3x) 74HC595 with no mention of the 74HC165 on that introductory page. This would have saved me an extra trip to the components shop. All good, great project to work on. Going to be a lot of fun now that I have all the parts. :)

amandaghassaei (author)  markkuki3 months ago

good catch, I will update that. Sorry!

whatisntseen4 months ago

Can you verify the code in step 27? I'm trying to check my midi connection, but it doesn't look complete. I'm not a programmer, so I'm not really sure where the code is going. Looks like it's missing the rest of the sendMIDI function and all of the loop function.

amandaghassaei (author)  whatisntseen4 months ago

ah! yest it's totally cut off. I'll find the rest of that for you.

amandaghassaei (author)  amandaghassaei3 months ago

hey, sorry for the long wait- I've been on vacation. I'm having trouble getting the full code loaded into that box, so I've attached it here

Thank you, Amanda. Hope you enjoyed your vacation-- no worries, I was able to work on other projects in the meantime.

The device seems to be working and is recognized as midi using the midi-to-usb method. Now I just have to clean up the traces and come up with an enclosure for it all.

amandaghassaei (author)  whatisntseen3 months ago

exciting! Let me know if you hit any more bumps

amandaghassaei (author)  amandaghassaei3 months ago

also - just just got a chance to update the schematic for the buttons -
turns out there was an error. Please take a look at the new schematic
in (image 2, step 1) and make sure you've got the correct wiring.

pasteldreams4 months ago

Great project, thanks for the awesome instructions! I'm also having issues with some of the test codes - step 25 (and as prev said, 27 seems incomplete). This is the error I get for the button and serial comm test in step 25 - for this line of code

if (buttonEvent[i]<> 1) & 3;

expected primary-expression before '>' token

sketch_may30c.ino: In function 'void shift()':
sketch_may30c:128: error: expected primary-expression before '>' token
sketch_may30c:128: error: lvalue required as unary '&' operand
sketch_may30c:130: error: 'ledstate' was not declared in this scope
sketch_may30c:131: error: 'ledy' was not declared in this scope
sketch_may30c:134: error: 'ledy' was not declared in this scope

Any ideas how to resolve this? I have very little experience with coding. Cheers.

Hey there! I'm having the exact same problem... have you found a way to resolve it pasteldreams?

From what I understand, it's a Library issue, but have run out of ideas...

amandaghassaei (author)  Thomatic4 months ago

just looked into this, you're right. I must have changed something when I copied into the Instructable. Let me look through some files and see if I can find it. This code is actually totally separate from the final code I wrote in step 31, I rewrote the final code from scratch, so don't worry about it too much :)

amandaghassaei (author)  amandaghassaei3 months ago

finally got a chance to look at this. Here is the code from step 27, and I think this code may work for step 25. Alternatively, you could try running the final code (from github) with the updated version of the beat slicer app, that should work fine. Sorry some of this in progress code is a few years old now - I've kind of lost track of some of it. Let me know if it works!

amandaghassaei (author)  amandaghassaei3 months ago

also - just just got a chance to update the schematic for the buttons - turns out there was an error. Please take a look at the new schematic and make sure you've got the correct wiring.

hgarg24 months ago

amazing midi u made Amanda! can u tell me how much money u spend on it?

amandaghassaei (author)  hgarg23 months ago

not exactly sure, you'll have to look through all the links and add it up. Thanks!

Kharon4 months ago

This is extremely inspiring and I plan on making one of these some time this year for my little brother who loves making music. The only function I can think of for the four extra buttons would be either gyro axis control (locking and unlocking), mode scrolling (ie. beat slicing to arpegiator) {I haven't experimented with Arduino yet so I'm not sure if this is possible on just one, and if so it would probably need a lot of lines of code}, and/or (if you really want to go pro) LED color scrolling (of course, this would require changing the LEDs to RGB LEDs and a lot more code writing). Just throwing ideas out there though. I'm still learning about the basics of C so I'm not able to give more than ideas at this point :D

amandaghassaei (author)  Kharon3 months ago

that all sounds awesome! keep my updated if you build it

whatisntseen5 months ago

Amanda, this is a great project. I'm really enjoying working on it, but I've run into a bit of a problem that I'm not really sure how to solve. I was able to get the LEDs working and tested out my buttons with the arduino button matrix example. Thing is, when I use the 595 and 165 circuit to have the LEDs light when I press a button, they actually light up before I touch the button. What I mean is that the buttons are sensitive to proximity. Could this be because I used a 1/6 watt 10k ohm resistor instead of 1/4 watt? I've tried cleaning the button pad and pcb. I don't want to start building a box with shielding if that's not going to solve this conundrum. I'll probably head out later to get some different resistors. Any other ideas on why this might be happening? It's kind of cool, but won't really be useful for a MIDI controller.

I figured out what was going on. Maybe I was reading the schematic incorrectly as I'm fairly inexperienced, but after reviewing your instruction and looking at the pictures, I put the switch grounds going between the 165 IC and the resistors. Your schematic, to me, has the resistors going between the switch grounds and the 165 IC. Here's how I'd have drawn the circuit to reflect what you described and what seems to work. Please let me know if this is correct or if it'll damage my components. Thanks!

LEDButton Test 165Schematic.jpg
1-40 of 81Next »