Thursday, 20 September 2012

2 Raspberry Pis communicating via morse code

Our second Pi arrived in the post today from Cool Components, which arrived the next day after they shipped it. Nice! But what on earth can you do with 2 raspberry pis?

You can set up one to be an LED morse code transmitter, and one to be a phototransistor morse code receiver:



I got the idea from a post on the forums about a project described on http://c.cam108.me/ to monitor a power meter that indicates load by the frequency of a flashing LED. I took the phototransistor from there and found that it works very well with the LEDs contained in my SK Pang kit.

In my project, the sender is a typical GPIO output controlled LED, with python code to take an english message from the user and convert it into morse code LED pulses. I took the python morse code dictionary from http://www.cl.cam.ac.uk/~db434/raspi/morse_code/ to save a little work. 

The receiver setup is identical to the one in the power meter project, but with C code to monitor the LED pulses and convert them from morse code back into english. I used C because the python runtime turned out to be quite imprecise on the timing loops. With some tuning, I could get the C code to correctly interpret the active LED durations, and the pauses between. Because I was following the power meter project's C source, I also used the bcm2835 C library which can be found at http://www.open.com.au/mikem/bcm2835/



I prototyped this all on a single Pi initially, so don't let that stop you if you only have the one. 

The one minor issue with the phototransistor, is that it is quite sensitive to ambient light, so I covered the units with card during execution. Note that the current receiver code spits out the previous message when a new one arrives (i.e. pauses are currently only terminated with the next LED pulse).


No comments:

Post a Comment