Musical robots can do amazing things, but in order to make them musical, it helps if they can communicate with other music software, like your favorite DAW. By creating Music Bots that understand MIDI they can be controlled in the same way as synthesized sounds or samples.
The Teensy microcontroller can be used as a MIDI device and combined with the MIDI Bots Motor Driver Board or other motor driver circuit can trigger motors with native MIDI support over USB.
Teensy makes it easy to create custom MIDI devices. This can be a controller that creates MIDI messages or an output that takes in MIDI messages and turns them into an action.
The Teensyduino add-on for Arduino includes a library to handle MIDI communications. In this tutorial I’ll show you how you can use the Teensy as an output device that can control LEDs, motors or anything else you want to hook up to your Teensy.
Different coders for different motors
The control code used depends on the type of motor being driven. The Music Bots Driver Boards use a MOSFET circuit that is suitable for DC motors, vibration motors and solenoids.
Solenoids have a short quick movement. This makes them good and impulsive movements, like that of a drum stick. They only need to be turned on for a short pulse (typically 10-20 ms) in order to fully activate. Longer than that and their final position is simply held. Often a return spring is used to reset the solenoid after the voltage is removed. So to control a solenoid we only need a short pulse each time the motor is activated. For solenoids we will only use “note on” messages to trigger the solenoids. They will be pulsed for a predetermined time and then turned off automatically.
When using other DC motors such as hobby motors, geared motors and vibration motors, chances are you want to turn them on for more than 20ms each time you trigger them. For these motors we will use MIDI “note on” messages to activate the motor and they will remain on until the corresponding “note off” message is sent.
The MIDI velocity message typically controls the volume and perhaps timbre of a sound. With motors we will use this message to control the power used to engage the motor. In the code below the velocity message is mapped to a PWM value to control the effective voltage sent to the motor. Another way to control this for pulsing motors (i.e. solenoids) is to control the “on time” of the pulse. A short pulse will result in less velocity than a long pulse.
Download the code here.
This zip file has 3 Arduino sketches
- musicBotsPulse – use for solenoids
- musicBotsSustain – use for DC / Vibration motors
- simpleMidiOutput – demonstrates the basics of using a Teensy as a MIDI output device.