Introduction: Fidget Spinner MIDI Controller

About: I enjoy making things that make noise.

Let's hack a fidget spinner and turn it into a whirling dervish of sound making!

Step 1: Materials Needed

Tools

Velcro

Scissors

Hardware

Fidget Spinner!

Bluetooth enabled computer

LightBlue Bean

https://www.adafruit.com/product/2732

CR2032 Coin Cell Battery

https://www.sparkfun.com/products/338

Software

GarageBand (or other BLE MIDI controlled software)

Bean Loader

https://punchthrough.com/bean/docs/guides/getting-started/os-x/

Arduino version 1.6.8

https://www.arduino.cc/en/Main/OldSoftwareReleases

Animoog

https://www.moogmusic.com/products/apps/animoog-0

LightBlue Explorer

https://itunes.apple.com/us/app/lightblue-explorer-bluetooth-low-energy/id557428110?mt=8

Step 2: Development Overview

For this project, you will need to use an older version of the Arduino IDE (1.6.8) in conjunction with the "Bean Loader" from Punch Through, to load the sketch onto the LightBlue Bean.

See the provided links on the "Materials" step.

Step 3: Zip File of Arduino Sketch

Download and unzip this sketch.

Open it in version 1.6.8 of the Arduino IDE

Step 4: Turn on Bluetooth, Configure Bean Loader and Arduino IDE

Turn on Bluetooth in your System Preferences.

Open the Bean Loader, and when it asks you to Associate with Arduino, make sure you choose Arduino 1.6.8 - if you have multiple versions of Arduino on your computer.

Open Arduino 1.6.8. Set the Board to LightBlue Bean+ (2.0.0).

Set the Port to /dev/cu.LightBlue-Bean.

Set the Programmer to Bean Loader.

Step 5: Verify and Upload the Arduino Sketch

Click the arrow at the top of the Arduino window to compile and upload your code to the Bean Loader.

Step 6: Load Program Sketch in Bean Loader

In the Bean Loader, connect to your Bean.

Right click on the name and choose "Program Sketch"

Step 7: GarageBand Zip File

Download, unzip, and open the GarageBand file.

Step 8: Garageband Setup

Take note of the MIDI preferences within the GarageBand, which need to be reset occasionally, in order for the LightBlue Bean to connect and send its MIDI signals via BLE to the application.

Step 9: Final Steps and Troubleshooting

Adhere LightBlue Bean with velcro to the Spinner.

Verify connectivity to GarageBand.

If you are using an iOS platform device, the LightBlue Explorer app is helpful in discovering and interrogating nearby BLE peripherals (such as the Bean).

Spin It!

Try having the bean attached at different angles to the fidget spinner.

Try spinning in different directions and speeds.

Experiment with different instruments within GarageBand

Step 10: Arduino Sketch

You can peruse this gist of the AccelMIDI sketch, and check out the commented out lines, which can provide hints of possible values to play with.

LightBlue Bean Accelerometer to MIDI

#defineTHRESHOLD_113
#defineTHRESHOLD_223
AccelerationReading previousAccel;
voidsetup() {
Serial.begin();
previousAccel = Bean.getAcceleration();
}
voidloop() {
AccelerationReading acceleration = Bean.getAcceleration();
int readX = map (acceleration.xAxis, 0, 1023, 0, 127) + random(7, 23);
// int readX = (acceleration.xAxis/9) ;
int readY = map (acceleration.yAxis, 0, 1023, 0, 127) - random(13,23);
// int readY = ((acceleration.yAxis/11) - random(13,23));
int readZ = (acceleration.zAxis/7);
int sumXY = ((readX + readY)/17);
// int sumXY = ((readX + readY)/13);
int diff2x = abs(readX - readY);
int diffx3 = abs((readX*3) - readY);
int diff4 = abs(readX + readY)/4;
AccelerationReading currentAccel = Bean.getAcceleration();
int accelDifference = getAccelDifference(previousAccel, currentAccel);
previousAccel = currentAccel;
if(accelDifference > THRESHOLD_2){
BeanMidi.noteOn(CHANNEL1, sumXY, 11);
BeanMidi.noteOn(CHANNEL1, readY, sumXY);
BeanMidi.noteOn(CHANNEL1, diffx3, diff2x);
}
elseif (accelDifference > THRESHOLD_1){
BeanMidi.noteOn(CHANNEL1, readX, 9);
BeanMidi.noteOn(CHANNEL1, diff2x, sumXY);
BeanMidi.noteOn(CHANNEL1, diff4, diffx3);
}
else {
for (int j = 0; j < 128; j++) {
BeanMidi.noteOff(CHANNEL1, j, 7);
// BeanMidi.noteOff(CHANNEL1, j, 15);
}
}
Bean.sleep(7);
// Bean.sleep(49);
Bean.setLed((uint8_t)readX,(uint8_t)readY,(uint8_t)readZ);
}
intgetAccelDifference(AccelerationReading readingOne, AccelerationReading readingTwo){
int deltaX = abs(readingTwo.xAxis - readingOne.xAxis);
int deltaY = abs(readingTwo.yAxis - readingOne.yAxis);
int deltaZ = abs(readingTwo.zAxis - readingOne.zAxis);
return deltaX + deltaY + deltaZ;
}
intgetAccelDifferenceX(AccelerationReading readingOne, AccelerationReading readingTwo){
int deltaX = abs(readingTwo.xAxis - readingOne.xAxis);
return deltaX;
}
intgetAccelDifferenceY(AccelerationReading readingOne, AccelerationReading readingTwo){
int deltaY = abs(readingTwo.yAxis - readingOne.yAxis);
return deltaY;
}
view rawAccelMIDI.ino hosted with ❤ by GitHub

Step 11: Next Steps

Try different (BLE enabled) MIDI instruments, such as Animoog on iOS.