TouchShield Slide Two-way Communications
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. The Goal 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.
Touch -> TouchShield Slide -> Arduino -> TouchShield Slide Programming Tips and Tricks 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.
To program the screen use the Antipasto Arduino / AardvarkĀ IDE
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: [cc lang=ācā]Serial.begin(9600);[/cc] 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. [cc lang=ācā]char charIn = 0; byte i = 0; char stringIn[32] = āā; while(Serial.available()) { charIn = Serial.read(); stringIn[i] = charIn; i += 1; } Serial.print(āAā);[/cc] Arduino Serial 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
Define the RX and TX pins
Instantiate the software serial
Initiate the software serial line
[cc lang=ācā]#include #define RX_PIN 3 #define TX_PIN 2 AFSoftSerial touchSerial = AFSoftSerial(RX_PIN, TX_PIN); void setup() { touchSerial.begin(9600); }[/cc] Demo Project 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. Visit Liquidwareās App Store to download the source code and library for this demo project.
Random Number from Arduino Displayed after Detecting a Touch...













