EarthLCD.com Application Note AN-12

ezLCD-30x Touch Screen Interface with Arduino (Software Serial)

support301@earthlcd.com

 

Placeholder change log [GH]

1.0 Introduction

The purpose of this application note is to demonstrate how to use an ezLCD-30x Smart LCD as a touch screen user interface with an Arduino board. This example uses the ezLCD-301 but we designate ezLCD-30x because other present (and future) ezLCD-30x models are software and I/O connector compatible with the ezLCD-301. The ezLCD-30x uses two of its  I/O pins to communicate with the Arduino using the software serial driver. By touching the appropriate button widget drawn on the ezLCD-30x touchscreen, the user can turn the Arduino LED ON or OFF.

2.0 System Operation

Even though all Arduino boards can be interfaced to the ezLCD, an Arduino Duemilanove/uno board has been used in this application note. The Arduino board communicates with the ezLCD-30x over a software serial interface. Three pins are required Ground, and two I/O pins, one configured as an output for transmit data and another configured as an input for receive data. The software example (Arduino Sketch) programmed into the Duemilanove/uno board transmits EarthSEMPL commands (ASCII text) to the ezLCD. These commands program two button widgets labeled ‘ON’ and ‘OFF’ to be drawn on the ezLCD screen. When these buttons are pressed on the ezLCD touch screen the ezLCD will transmit widget responses (ASCII text) indicating when a button has been pressed and released.

3.0 Assumptions

This application note assumes you have a basic understanding of both the ezLCD and Arduino hardware and software. It is assumed that you have loaded the Arduino software on your PC and have ran a few sketches. You have also read your ezLCD manual and have it configured and can connect to it with the terminal program. You have ran and have an understanding of all the macros (ezm files) on your ezLCD. It also assumes that when you start this project your ezLCD has the factory default file system and startup.ezm in the \SYS\MACROS DIRECTORY.


4.0 Hardware Setup

Connect the ezLCD unit to the Arduino board using the schematic diagram as shown in figure 1. Note: Pin 8  (IO3) is the TTL level serial input of the ezLCD and Pin 7 (IO4) is the TTL level serial output of the ezLCD for SERIAL2.

Figure 1. Arduino ezLCD serial connection schematic

5.0  Setup

Software programming and/or configuration for both the ezLCD and the Arduino are required for this application. In the following steps we will 1) Change the ezLCD command port from USB to ‘serial port 2’ to communicate with the Arduino and 2) load the software sketch in Appendix 1 into the Arduino.

5.1 Connect your ezLCD-301 to your P.C.  

Plug the USB cable from your P.C. to the ezLCD-30x. Run the termie program and verify you have a connection by typing ‘CLS’ and pressing enter to clear the ezLCD screen. Be sure you have configured the termie program to communicate with it as shown in the ezLCD-301 User Manual (http://store.earthlcd.com/ezLCD-301).

5.2 Set the CMD port to Serial 2

At the command line, type:

VERBOSE ON

CMD SERIAL2 9600 1 N81

VERBOSE OFF

This will set the ezLCD serial port 2 to 9600 baud rate with 8 data character, No parity and 1 stop bit. Note that the ezLCD will no longer respond to the terminal program until powered off or until the command CMD CDC is received through the current command port which is now serial port 2.

5.3 Connect the Arduino to your P.C..

Plug the USB cable from your P.C. to the Arduino

5.4 Download the Arduino sketch.

Run the Arduino IDE software and open the program an12b.ino from the www.earthLCD.com website by clicking the Up Arrow Icon. You may optionally choose to cut and paste the code directly from this document into the Arduino editor. Download the sketch to the arduino by clicking the Right Arrow Icon.

5.5 Reset the Arduino.

When you press reset on the Arduino the ezLCD screen should look like this:

(insert ezLCD button widget screen here)

6.0 Turn on the Light With ezLCD Button Widgets!

Your ezLCD screen should now look like this. If you were able to wait, NOW press the ON button widget on your ezLCD and you will see the LED at location L on your Arduino board go on! Press the OFF button widget on your ezLCD and you will see the LED at location L on your Arduino board go OFF. Congratulations you have a Color Touch Screen on your Arduino!

7.0 Complete Your Project

This application note showed how to connect the ezLCD to a serial host (Arduino) and how to use a button widget. To complete it as a stand alone project you need to 1) connect a power supply and 2) modify the startup.ezm to set command port to SERIAL 2.

7.1 Power your project

If you have a 5 volt power supply in your project you will need to connect the power to the Arduino duemilanove/uno and to the ezLCD VBUS signal on PIN 1. If you are using a 3.3 volt Arduino and have a 3.3 volt power supply available you may connect the 3.3 volt power supply to the ezLCD VCC signal on PIN 16.

7.2 Modify your Startup

In Step 5.2 you temporarily set the command port to SERIAL 2 on your ezLCD by typing at the command line:

VERBOSE ON

CMD SERIAL2 9600 1 N81

VERBOSE OFF

To complete your project you need to make this load on startup. To do so you need to make a copy of these lines in your default STARTUP.EZM (in the \EZUSER\MACROS directory). Note: Never modify the startup.ezm in the \EZSYS\MACROS You can do this by

(1) Commenting out: CMD CDC       'Configure Command Port to USB CDC

(2) Uncommenting out: CMD SERIAL2 9600 1 N81 'Configure Command Port to SERIAL2

If you decide to use the ezLCD on another project you can get back to factory default by simply deleting the file \EZUSER\STARTUP.EZM .

8.0 About the Arduino sketch (software)

The Arduino program for ezLCD interface does the following.

Loads the software serial Library: #include <SoftwareSerial.h>

Set up an array with the ascii string of the themes, labels andbutton draw commands.

Defines the arduino pins for Transmit(TX), Receive(RX) an

1.  The first section is the setup() function that initializes the baud rate.

2.  Defines the Themes and Buttons and sends them out the serial port to the ezLCD.

3. The  and defines ON and OFF buttons on the ezLCD display. If the ON button is pressed, it will turn on the LED on the Arduino board on pin 13. If the button OFF is pressed, it will turn off the LED on the Arduino board. A complete source code of Arduino with comments is listed in Appendix 1.

9.0 Conclusion

You have connected your Arduino as a host to the amazing ezLCD-30x. You have used the incredibly easy Arduino and can now have a graphical touch panel on all of your Arduino projects. You are now limited by only your imagination in what you can create. Have fun and enjoy. If you create something share it on the internet and/or let us know at support301@earthlcd.com .

10.0 Material List

A list of materials used in this application note is provided in Table 1. All components can be purchased from the listed supplier. A complete list of suppliers are listed in Appendix 2.

Table 1. List of material

Material

Qty

MFR

MFR PIN

Digi-Key PIN

1

ezLCD-301-QK

1

EarthLCD.com

2

Arduino board

1

Arduino

3

Jumper Wires

3

11.0 ezLCD-30x Connector

Revision History

10/20/2011- Revision 1- Initial version

1/12/2012- Revision 2 - Update with connector picture and IO3 and IO4 names.

1/18/2012- Revision 3 - Added Arduino 1.0 Support with Software Serial Library


Appendix 1. Source Code

#include <SoftwareSerial.h>

// Updated 1/18/2012

// Wrote for ezLCD-301 Firmware Version 1.11 or later and Arduino 1.0 or later

// This assumes you have set CMD port to serial2 in your startup file by

// CMD SERIAL2 9600 1 N81

// and the Arduino Pin 6 is connected to ezLCD Pin 7 and Arduino pin 7 is connected to ezLCD pin 8.

//added /r to clear command buffer and set echo and verbose off to lighten traffic load on software serial!

// Stuff the themes and button initialization into an array

char *commands[] = {

"\r",

"echo off\r",

"verbose off\r",

"cls green\r",

"fontw 1 sans72\r",

"fontw 2 sans72\r",

"theme 1 9 3 0 0 0 8 8 8 8 1\r",

"theme 2 5 20 3 3 3 4 4 4 4 2\r",

"string 1 ON\r",

"string 2 OFF\r",

"button 1 10 40 185 140 1 0 25 1 1\r",

"button 2 205 40 185 140 1 0 25 2 2\r"

};

// This assumes you have set CMD port to serial2 in your startup file by

// CMD SERIAL2 9600 1 N81

// and the Arduino Pin 6 is connected to ezLCD Pin 7 (IO4) and Arduino pin 7 is connected to ezLCD pin 8 (IO3).

#define LED_PIN 13   //arduino on board led

#define RX_PIN 6     //

#define TX_PIN 7

SoftwareSerial nss( RX_PIN, TX_PIN );

char buf[3];        //we're only interested in 3 bytes at a time (BPx) wher x is widget ID

void setup()

{

    pinMode( LED_PIN, OUTPUT );

    nss.begin(9600);   // still testing 115200 but worth trying :-)

   

    for( size_t i = 0; i < sizeof(commands)/sizeof(char*); ++i )

    {

       nss.print( commands[i] );

       delay(100);

    }

}

void loop()

{

// everytime we get a serial byte shift into

// our three byte buffer at third location by

// moving last two bytes up

  while( nss.available() )    {  

        buf[0] = buf[1];

        buf[1] = buf[2];

        buf[2] = nss.read();

// Look for button release (You can press a button

// and slide off and not cause a release so you can

// change your mind!) BR1 (ON button released) turns

// Arduino LED on and BR2 (OFF button released) turns

// Arduino LED off

        if( buf[0] == 'B' && buf[1] == 'R' )        {

            if( buf[2] == '1' )

                digitalWrite( LED_PIN, HIGH );

            else if( buf[2] == '2' )

                digitalWrite( LED_PIN, LOW );

        }

    }