Over last summer, I got the GamePack from Liquidware which includes a touch screen display, joystick, microcontroller, and battery pack. With this kit you can make a GameBoy from scratch. With some blood, sweat, and tears, I was able to re-create some games like Asteroids and Tetris.
The touch screen is called the TouchShield Slide which is a 320×240 OLED and resistive touch screen. The screen also has a microcontroller that is Arduino compatible and expands your program space. Since the screen is really a microcontroller in disguise, it can be used for many types of projects. Overall I am very happy with the screen, but I realized I didn’t know how to use it very well. I set out to learn and develop a protocol / reusable library that allows the screen to talk to a microcontroller and vice-verse. So I wanted to take a moment and explain what I learned – maybe you can get going faster than I did.
My goal is to be able to display data on the screen that has been received from another device. The data requested would be initiated by a touch on the screen. The protocol has to be consistent and reliable, while being flexible enough to be the basis for future projects.
I found quite a few libraries and resources on liquidware.com. I also discovered quite a few important things through my trial and error. My biggest frustration was with programming and figuring out the IDE. Here are some tips.
Program the screen and Arduino separately – make sure the IDE has the proper device selected
To put the screen in program mode, press the switch beside the power connector – it’s in program mode when the LED on the backside is red
TouchShield Slide Serial
Serial data sent and received by the TouchShield Slide uses the hardware serial lines.
To setup the serial connection, place this line in your setup code block:
Now you can read and write to and from the serial buffer. To read in a whole string, use a byte array to store bytes from the serial buffer when serial data is available. To write to the serial buffer, simply use serial print.
On the Arduino side, you have to use some form of Software Serial that sends and receives data on Pins 2/3. I have found that the Adafruit SoftSerial Library, “AFSoftSerial.h”, works the best. It seems to be reliable and produce consistent results when talking to the TouchShield Slide. Reading and writing from a software serial buffer is about the same as a hardware one with this library.
To use software serial, follow these steps:
Include the “AFSoftSerial.h” library in your Arduino code header space
I took a moment to put together all of the things that I learned into a quick demo project. This project displays a random number on the screen. The random number is being generated by an Arduino, sent via serial, and requested by a touch of the TouchShield Slide.
Random Number from Arduino Displayed after Detecting a Touch…
Visit Liquidware’s App Store to download the source code and library for this demo project.
I took the leap and bought an Arduino from LiquidWare. Arduino is an open-source microcontroller that has a processor, some digital I/O pins, and analog inputs. You can create little standalone programs that monitor inputs, control LEDs, and pretty much anything that you dream up. My favorite projects are ones that involve the Internet. A microcontroller is rather simple by itself, but what if it could use the web to get answers, send an email, maybe update my Twitter status? That means there is an unlimited number of projects ahead – Microcontrollers collaborating in cyberspace. The missing link for the web part is the ioBridge IO-204. I know you are no stranger to the IO-204, but for those of you who have not heard. The IO-204 sits on my network and relays data from its channels to ioBridge.com servers and back into my network. It allows for remote control and monitoring without network configuration and programming. One of the expansion boards is a two-way serial board that accepts serial strings and connects them to APIs of web services that ioBridge interfaces to and sends back responses. For instance, I can send the commands, “[[[calc|9*9]]]” and this returns 81. OK, maybe not impressive on the surface, but that result came from Google Calculator. Anything Google Calculator can solve, your microcontroller has access to those results. For more examples, visit the Serial Web Services API on the wiki.
Message Center Project
I wanted to combine these two worlds with a sample project – maybe it will inspire you to come up with something better, spark some ideas that you have. I have my Arduino measuring my outside temperature here in Pittsburgh, which is an analog input scaled to Fahrenheit. At any moment I can press a button and get the temperature on the LCD screen – no Internet required. Since I have been planning a work trip to Atlanta, I also wanted to compare my temperature with hot-lanta’s. So, my project solves that. Using the “weather command”, I am able to get the weather anywhere in the world by zip code or city name.
I added a few more things to the message center. With another button, I can get Google’s current stock price. My strike price was $405, so I have been watching it closely. If it gets below $405, I get an automatic email from my message center. The stock quote comes from the Yahoo Financials API.
I have one more button that emails me a secret message when it’s pressed. I put this in here for when my mom comes into my room from when I am on the road. It’s aptly labeled, do not press. Next time, I will hook it to a light sensor in the basement to catch her when she turns on my lights. I am sure you all have the same issues with your mom.
The Arduino requires some c-like programming and I wanted to include the sketch for you to steal and use for your projects. You will see how I send the serial commands from the Arduino to the IO-204 using the UART serial connection (pins 0/1) and receive and parse the incoming results. I use a SoftwareSerial port for the LCD results. The pushbuttons are software debounced and use pull-up resistors for solid digital connections. The LED’s linked to each button use a 330-ohm resistor to protect them. I was aided by the Arduino Inputs tutorial on Ladyada.net, Debounce Tutorial, and the ioBridge Wiki / Forum. Please let me know if you have any questions, maybe I can help. I have learned a lot about handling strings on the Arduino.
// // Message Center using Arduino and the ioBridge IO-204 // // An open-souce Shadowlord Project // www.IamShadowlord.com
It’s simple, but I hacked together a power supply for the Arduino, which gets power from USB or a coaxial input from a transformer. I wanted to only run one brick, wall wart, so I hacked a USB cable. There are 4 wires in the USB cable (from pinouts.ru):
The IO-204 has a regulated 5VDC and ground (up to 1A – 4A total draw depending on supply) on each channel, so using a terminal strip, I connected the VCC and GND to a cut in half USB cable.