Making Noise with Microcontrollers

Teensy 2.0 with Garageband

Download Teensy 2.0 loader for your operating system.

Download the Arduino add-on Teensyduino for you operating system. Follow the steps on that page, if when you get to step where you navigate to the Arduino software and do not see Arduino in your applications folder (or wherever it usually lives). Go to Arduino.cc to get a fresh download. It should recognize it after installing again.

Once you have the add-on installed, you can upload any Arduino sketch to your teensy from the Arduino IDE. Check out the documentation on that here.

The really cool thing about the teensy 2.0 is that you can send MIDI (musical instrument digital interface) messages very easily. This is usually not an entirely easy thing to do, but with the teensy, you can upload a sketch and get jamming right away.

Open Arduino and a new sketch. Copy and paste the below code.

Read the comments carefully. There are coupld different ways things are happening with this code, than with the typical DigitalReadSerial or Button example Arduino provides. A library in this sketch is being used called Bounce is being used. If digitalRead() is used to read the button presses the trigger is very sensitive. Bounce helps it slow down and uses the function fallingEdge() to detect when the button goes from high to low (5 volt to 0 volts). Here you can see there is more than one way to read a button state!

Open GarageBand, if you can’t find it in your applications folder, go to the App store and search for it. It may tell you it’s $4.99, click on install and it will end up telling you that the update is actually free, since your mac should of come with it preloaded.

Choose a new keyboard project.

Screen Shot 2016-02-11 at 3.40.08 PM

 

The teensy will automatically be seen as a MIDI device that you have connected to your computer. Press the button and it will play a keyboard note!

Screen Shot 2016-02-11 at 3.40.39 PM

You can change the note in the Arduino sketch

And you can choose other sounds in GarageBand from the library, such as “Dreamy Bells” on a synthesizer.
Screen Shot 2016-02-11 at 3.43.59 PM

 

LilyPad USB/Flora with Soundplant 43

The LilyPad USB and Flora can not only trigger lights, motors and other actuators, it can also act as a HID (human interface device). HIDs are mouses and keyboards. This means that you can read a button and when it’s pressed it will act like a keypress on your keyboard. You can assign this keystroke to a letter or a key like SHIFT or CTRL, to make all kinds of stuff happen.

In this tutorial, you will be printing a character that will trigger a sound that it is assigned to it in the application Soundplant.

Connect two switches to pins 2 and 3. Plug in the Arduino and open a new sketch. Copy and paste the below code.

Upload and open up TextEdit or something else that you can type into. Press the button on pin 2 and watch it type the character ‘n’. You will need to adjust the sensitivity of the press. This is done by tweaking the amount of the delay() between it pressing the key down using Keyboard.press() and the release of the key using Keyboard.releaseAll(). Try typing in lower numbers like 10 and higher numbers like 1000 (1 second).

If you need to upload a sketch now, the LilyPad is seen as an USB HID device, you will need to choose this new port option under ports before each upload.

Screen Shot 2016-02-11 at 4.13.33 PM

Download Soundplant for your OS.

Open Soundplant and you will see a keyboard.

Screen Shot 2016-02-11 at 4.16.06 PM

 

Soundplant makes is really easy to assign sounds to the keyboard. Navigate to an audio file using finder, choose a file and drag it on top of the key you want to assign it to. In this case, you want to assign it to the ‘n’ and ‘b’ key because that is what we told our Arduino sketch to assign to our button presses.

Screen Shot 2016-02-11 at 4.22.43 PM

Screen Shot 2016-02-11 at 4.22.51 PMN Key is now assigned!

 

Press a button to listen to the sample! it will also scrub through and you can watch it play out it’s entirety. Play around, you can trigger multiple events at once which can be fun.

Screen Shot 2016-02-11 at 4.23.41 PM

Both keys assigned and N sound is playing.

 

Adafruit Feather Bluefruit with Soundplant

Adafruit’s new Feather Bluefruit brings a microcontroller and bluetooth together into one small powerful package. It is easy to get up and running, sending keystrokes to Soundplant, but wirelessly!

Connect the Feather using a USB cable and hook up a switch to pin 2.

Open up Arduino and a new sketch.

Copy and paste the code below.

This code is a bit clunky and can be cleaned up, stay tuned for an update!

Before this code works, a file needs to added to the sketch. To do this, click on the downward arrow button below the serial monitor button and select “New Tab”. Name it BluefruitConfig.h

BluefruitConfig

Copy and paste the code from the above link. Verify to make sure every was copied ok.

Upload sketch and open the serial monitor. The information of the bluefruit module and checks will print out telling you if everything is OK. It will end by telling you to pair with your phone and some commands to send it from typing in the text field above.

You can pair it with your phone through your settings, but let’s pair it with the computer instead so we can use Soundplant.   Press the button, even if you aren’t paired with something and a command with the letter ‘n’ should still print along with an OK after it’s successfully be sent. If not, pair it with the computer first.

Before pairing with the computer, plug in a LiPo battery and unplug the USB cable to disconnect from the computer.

To pair on a Mac, go to System Prefences and click on Bluetooth. A window will pop up and scan for devices, choose Bluefruit Keyboard and pair. For Windows go to the Control Panel and find the bluetooth settings.

Screen Shot 2016-02-11 at 5.57.40 PM Screen Shot 2016-02-11 at 5.57.48 PM

To test, open up a text document and push the button, ‘n’ should print each time you press. If it’s working open up Soundplant and assign a sound to the N key, you can see how to do that by scrolling up and checking out the LilyPad/Flora with Soundplant section. Once a sound is assigned, press the button and the soundbite will play.