Week 12: Interface and Application Programming

This week, I wanted to make a little system where a user can enter a string of text, and an LED blinks out the message in Morse Code. I did it in several steps, but wasn't able to make the entire system work seamlessly.

Computer Side

For the application programming, I decided to use Python. I'd been meaning to learn it for a while (I code Ruby, and Python seemed like the next logical step). I also knew it had lots of plugins, and was used to make little applications. While I was away for Thanksgiving, I made a little program that would input a text string and output it in Morse Code. I watched Lynda tutorials and took code from several sources (linked at the bottom) to put this together. I wanted Python to do the heavy lifting, and send the circuit just simple symbols or (better yet) just 0's and 1's. With Python Dictionaries (like associative arrays for all your Ruby kids out there), it is very easy to convert letters to symbols/patterns.

The translator in all its glory

Circuit Side

On Wednesday before leaving for break, I made a circuit that was connected to Rx and Tx through an FTDI cable, and had an LED (all cathodes connected, so it only does white) that I could control. Diagrams are below in 'Files' section. I gave myself a self five for being able to design and fab the circuit in about an hour. I am a little Modela/Eagle beast, basically.

Putting it together

I started by trying to learn PySerial, but this was a fool's game and I eventually moved to Neil's Echo program - the Python terminal and C program - and started hacking away at that to get what I wanted.

Step 1: Get Echo to work

Snaps to this tutorial for helping me start the program - it worked immediately!

Step 2: Microcontroller recognizes characters

So, instead of echoing letters, I wanted the microcontroller to recognize them and decide what to do for certain ones (ones like dot and dash, say). I made programs for dots, dashes, and breaks in Morse. And found that buffer[index-1] (see examples around line 285) is the pointer going to the most recent thing typed. So I made an array with .,-,_, and a space (to compare to buffer[index-1]) and when any of those were typed, the microcontroller would output "you typed dot/dash/space/end" (whichever was appropriate) and also do the light pattern I'd specified in the program associated with those symbols. Success! Unfortunately I didn't get any screenshots, but it was awesome I promise.

Step 3: Python sends letter by letter

Typing the letters doesn't work well because the circuit might be processing one and doesn't catch the next one. Instead, I wanted the python program to send the string it translated to Morse Code to the circuit so that no letters are missed. I wanted it to send one letter at a time, waiting for a signal that the circuit would send once it had done the light pattern. I was not successful in this. I could parse the string (called morse_out in my program) into individual letters, and I thought I was sending them. But I was unable to figure out if I'd picked it up on the circuit side. I used the LED for debugging on the circuit, and print() statements in python. But I was only able to see that the letter had been sent into the abyss... Code at the bottom is as I left it - it sends, but doesn't seem to be picked up by the circuit, so the circuit doesn't perform any lights or give the python terminal an 'ok ready for next letter' signal :/

So, I did sort of create a morse code translator. I could have changed my switch statements to letters instead of dots and dashes, so that you type in letters and get morse back. But a better solution is for Python to hang on to the string, and feed it to the circuit as necessary. And that still eludes me. Eventually, I'd like to make a phototransistor that picks up the signal and a python program that can translate it back into English. I think it would be especially cool to do this in infared - secret messages!!

Pertinent Links