Close
0%
0%

Sugarcube - a tactile music controller

The Sugarcube is a portable controller powered by Arduino that allows you to interact with MIDI and audio in playful and intuitive ways.

Similar projects worth following
video: https://www.youtube.com/watch?v=BLHSy9PcmEg
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 available 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 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. 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.

System design:

  • 1 × Button Pad 4x4 - LED Compatible Sparkfun COM-07835
  • 1 × Button Pad 4x4 - Breakout PCB Sparkfun COM-08033
  • 1 × Arduino Uno Sparkfun DEV-11021
  • 1 × 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: https://www.sparkfun.com/products/9652
  • 16 × White 5mm LED (3mm is fine too) Digikey C513A-WSN-CV0Y0151-ND

View all 33 components

  • Future Work

    amandaghassaei08/16/2014 at 22:22 0 comments

    This project has the potential to be expanded upon quite a bit. Unfortunately, I just don't have the time to invest in exploring all the possibilities, but here's some ideas I had for things to look into:

    More apps: The current implementation of this device allows you to boot into 16 different applications, but I've only written seven so far. There's a ton of great ideas over on the monome website for grid based controllers, it'd be great to see some of that translated into Arduino.

    Gyro Control: As I mentioned earlier, I threw an x/y gyroscope in the controller, but I've yet to write an app that actually uses it. I'd love to hear if someone has an idea for how this could work with MIDI.

    Wireless: When I started this project, my major design objectives were portability and plug and play ease of use. I wanted to try to break away from the model of the electronic controller that necessitates a computer to run, in an effort to bring electronic music out of the traditional studio environment. In keeping with that idea, I'd like to eventually get this controller to wirelessly send MIDI to my phone to make it totally portable. I have one of these bluetooth boards from Red Bear Labs, and I think there might be some way to send the data to my phone, translate it into CoreMIDI and run it though a MIDI synth, but I just haven't explored the idea enough yet. If anyone has any insight, I'd love to hear your thoughts.

  • Code Structure

    amandaghassaei08/16/2014 at 22:21 0 comments

    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!

    https://github.com/amandaghassaei/Sugarcube-Arduino-Library

  • Enclosure

    amandaghassaei08/16/2014 at 22:20 0 comments

    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.  This has stayed fairly secure so far, but I think it might be made better with some kind of magnetic snap.

  • Wiring Considerations

    amandaghassaei08/16/2014 at 22:17 0 comments

    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.

    Each 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 me additional 70mA to draw from on all 8 pins.

    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.

    More info about wiring and schematics can be found in the instructions section.

View all 4 project logs

  • 1
    Step 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 2

    Digital

    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

  • 2
    Step 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 cable

    Use 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.

  • 3
    Step 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 VCC

    The 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 connection

    The 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.2V

    Calculate the resistance needed to achieve these max ratings from V = IR:

    resistance = (5V-3.2V) / (0.03A)
    = 60 ohms

    I 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 1

    data pin (pin 14) digital pin 7
    latch pin (pin 12) digital pin 6
    clock pin (pin 11) digital pin 5

    Each 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).

View all 8 instructions

Enjoy this project?

Share

Discussions

Adam Fabio wrote 06/16/2014 at 05:45 point
Great project! Thanks for submitting Sugarcube to The Hackaday Prize! Those Sparkfun 4x4 buttons are awesome, aren't they? Your demos are great - the flin demo especially looks fun!

  Are you sure? yes | no

technolomaniac wrote 05/10/2014 at 04:23 point
Wow, this is a beautiful project. I'm really impressed. Super happy to see this in here. Have you launched this on kickstarter? You could target toddlers, also artsy types. I would buy one :) Just leave it on my coffee table and play with it whenever I got nervous or bored. :P

  Are you sure? yes | no

amandaghassaei wrote 05/10/2014 at 06:39 point
Thanks! I don't plan on trying to sell this anytime soon. It was a fun project to work on, but I've just got too many other things I want to build right now :) I am thinking of designing an arduino shield for this that would make the electronics portion of the project a lot more accessible to people without a ton of soldering skills, maybe I'll get around to that sometime this summer.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates