(photo credit: alvaroprieto)
This year I decided (in true last-minute fashion) to build a couple demos to show off my Geiger Counter kit at the Maker Faire Bay Area. One of these demos used my Geiger Counter kit to create ambient music:
(Thanks to @j_jwalrus for the interview and video!)
The PULSE output of each Geiger counter is connected to one input of a 74LS04 hex inverter on the Protoshield. Each time a Geiger counter detects a radioactive decay, it sends a 0.1ms 3V high pulse to one input of the inverter. The 74LS04 functions as a level shifter and outputs an (inverted) 5V pulse that is suitable for driving an ordinary (5V) Arduino.
Five outputs of the 74LS04 are connected to input pins on the Arduino. For convenience, I used Analog inputs 0-1 as digital input pins. The rest of the gates are connected to digital pins 10-12.
I used the PinChangeInt library on the Arduino to trigger an interrupt handler every time a falling edge is detected on one of the geiger inputs. This interrupt handler stores the pin number to a variable and sets a flag to tell the main() function that something has happened.
The main() loop polls the interrupt flag and waits for something to happen. When it detects that an interrupt has occured, it sends a “Note On” midi message to the Music Instrument Shield, using the SoftwareSerial library built in to Arduino 1.0. I had to hack the library a bit to get it to work in conjuction with the PinChangeInt library, since the SoftwareSerial library automatically installs interrupts for all pins (bad, bad SoftwareSerial!)
The value of the note depends on which Geiger counter triggered the interrupt. In the video I am using note ‘C’ over five octaves, centered around middle C (midi note 60). (I am not a musician, but this seemed to provide a pleasing sound that wouldn’t annoy me or my neighbors at the Faire too much.)
The Arduino sketch is a complete disaster right now, having been thrown together at the last minute, but I plan to clean it up and post it soon.
Things I learned while creating this demo:
- Sparkfun doesn’t include stacking headers with their shields unless you buy them in retail packaging. $30 in overnight shipping fixed that.
- Arduino is still a pain to program for if you do anything moderately unusual, like try to use two libraries together that both use pin change interrupts.
- You can get away without issuing “Note Off” commands for midi instruments that fully decay. (I think the MIDI spec frowns on this, but it works on the Sparkfun shield, at least.) This greatly simplified programming the demo, so I took advantage of it!