Week 13
Networking and communications

The assignment this week was to create two boards that can communicate with eachother, either wired or wirelessly. In class we learned about a number of ways to do this, including a protocol developed by the Center for Bits and Atoms, internet 0. Inspired by internet 0, which is very similar to morse code, I decided to try to have two AVRs communicate wirelessly using morse code.
My strategy was to have a "master" and a "slave". The master is in control of the communication, and the slave follows suit. In my case, I decided to try 1 way communication rather than 2 way to make things easier. The master sends messages to the slave, who receives and interprets them.
First I had to design the board. Fortunately the electronics for this are pretty simple. Each board has five LEDs to display things to the user, and either an LED for transmission or a phototransistor for receiving. Since the boards we're so similar, I actually only had to design one board and make two copies of it.



I ran into some difficulty initially programming the board but it turned out MOSI was connected to ground, so I separated them with a knife, which solved the problem. I also decided that it would be good to filter out the receiving pin, so I added a capacitor between the pin and ground.
My approach to the software was pretty simple. Since characters are at most 5 dots/dashes long, each character was represented as length 5 array of dots (1), dashes (2), or nothing (0). For example, S = . - . = {1, 2, 1, 0, 0}. Each of these five elements would be sent in 200ms. A 1 cooresponding to 100ms on, 100ms off, a 2 to 200ms on, and a 0 to 200ms off. In this manner, I would send a character a second, with the received measuring at 50ms and 150ms. Since the measuring is triggered by the light turning on (ie the beginning of a character), the timing was pretty simple and didn't need to be too accurate.


Here the master is transmitting a 1, (100ms on, 100ms off in blue), and the slave is reading it (reads occur at the yellow vertical lines). Reading 1, 0 cooresponds to a dot, reading 1, 1 cooresponds to a dash, and reading 0, 0 cooresponds to nothing.

For some reason my code wasn't working. I created a lookup table to find the morse code for each character, but when I read values out, they weren't what I put in. After a long time struggling with this, I decided to just send and decode the character 's'. I could see that what the slave read in was correct ({1, 2, 1, 0, 0}), but for since I couldn't use my lookup table, all the slave was able to do was tell me whether or not an 's' had been sent. For dubugging purposes, the boards display what they sent/decoded using 5 LEDs to display the offset from 'a'. S, being the 19th letter of the alphabet, is represented as 18.
Eagle files and firmware