May 2, 2014
This project displays text from the DrRacket interpreter to a 16 x 2 LCD display attached to an Arduino. This is done using serial communications to manipulate the I/O pins of the Arduino sequentially to create output.
- Data abstraction Is used for the interpretation of chars and pin maps
- True recursion Is used used in the algorithm for printing strings
- Symbolic language processing techniques is used during command entry
- Hash Tables Are used to create a binding between a char and its pin map
- File I/O Is used to create a serial link to the Arduino
How It Works
The real meat of this program comes down to three main points.
- screen initialization
This is done by setting the data pins in a specific order corresponding to the mode you wish to be in. In this case it's 16x2 mode with 5x8 size chars. This was actually more difficult to acomplish than I had originally anticipated. This is due to one of the biggest issues I ran into for this entire project, Propogation Delay. Basically the messages telling the Arduino to change its pin status were being sent too fast and the SimpleDigitalFirmata.c code could not keep up. This caused untold errors as only occasionally would the correct pinout appear.
- char mapping
The way I mapped the different displayable chars for this project was a cons cell. Both the car and cdr were either integers or symbols. I mimicked hexadecimal in this case. EX: "A" -> '(4 . 1) or "o" -> '(6 . 'f)
- map interpretation
This is where the magic happens. My map interpreter (print-hex hex1 hex2) takes the two values and creates a binary representation of that number which then corresponds to a combination of HIGH and LOW pin statuses on my 8 data lines. For example if the arguments from above were passed to (print-hex 4 1) it would process as follows,
- 4 -> 0100 (upper data bits (db4-db7) would be set in the corresponding pattern)
- 1 -> 0001 (lower data bits (db0-db3) would be set in the corresponding pattern)
- firmata.rkt is a very small library which allows basic pin control of an Arduino
This is what I started with. It was offically supported as a racket external library however, it's about 200 lines of code with no real documentation. I did have to modify this library a bit for this project to function correctly.
- An Arduino http://arduino.cc/
- Hitachi HD44780 LCD (very popular 16x2 LCD and controller)
- SimpleDigitalFirmata.c is the code running on the Arduino (straight from Arduino examples page)
After having done several hours of research on the topic I found that no one had ever tried to create a racket to 16x2 LCD communicator before. Total shock right? And seeming as I had already built this wonderful Arduino Altoids LCD thing I figured this would be a perfect project.
Technology Used Block Diagram
You can also fork and contribute to this project and others on my github