Here's how I built a simple musical instrument with Sharp IR Rangers to demo my A2D boards.
It was the night before the big robot expo at Wings Over the Rockies museum and I needed another exhibit. In the wee hours I breadboarded a Theremin. Wait. Theremin? What is it? How does it work?
It generates a tone with variable pitch. It's a digital slide whistle. One Sharp GP2D12 controls pitch, and a GP2D120X turns the sound on/off. The sensors point up from the table and you position your hands over the rangers for control.
The original version averaged 10-bit analog to digital conversions. The converted signal was still too noisy and it wasn't very responsive.
Months later I'm revisiting the pseudo-theremine to see if these A2D boards are any good. The new version uses...
- Sharp IR Rangers with A2D boards to lower the noise floor and raise resolution,
- An mbed with simple I2C master API (any MCU that can talk I2C works), and
- A simple BJT amplifier driving a standard speaker with some filtering caps.
Here's a demo video to show what I mean.
SoftwareThe source code for the project is here on mbed.org excerpted below. The A2D code is here on Google Code.
The heart of the mbed code simply reads 16-bit values from each A2D board and uses that to turn the tone on or off and set its pitch (pwm frequency).
Notice how simple the protocol is? Read two bytes. That's it. Do that over and over again. Configuring the A2D only requires sending a register and its value.
HardwareHere's how I wired up the hardware on a breadboard. I'm running the I2C pullups to 3.3V to protect the mbed, while the A2D and ranger are powered from 5V.
Schematic as follows:
The A2D board's Eagle files are on the Google Code repository linked above.