GLCD Screens and Touchscreens with the Arduino

I’ve been playing with some more GLCDs (Graphical Liquid Crystal Displays) recently, along with a Nintendo DS touchscreen. The parallel KS0108 display I used for my emonGLCD used an awful lot of pins, 16 including the power, which doesn’t leave a lot left over for anything else, so I thought I would try some of the serial displays that are available, one from SparkFun and a nice one from Adafruit that has a RGB backlight, you can see a montage of pictures of this display on the right.

Interfacing with and coding for each of these displays is subtly different as there isn’t a single unified Arduino library but none of them are complicated, it’s basically commands to move to a particular pixel of the display, select a font and print it, or for boxes, lines etc. you need to provide coordinates for the start and end points.

In combination with these screens I’ve also been experimenting with the Nintendo DS Touchscreen which is available on its own from a number of suppliers and makes for a cost effective method of adding touch control to screens of this size. When you only want to detect relatively large areas of the screen, such as for a menu, they are very easy to use.

SparkFun LCD-09351 Serial 128×64 GLCD

The LCD-09351 from SparkFun is basically a parallel KS0108 with an ATmega168 based serial backpack attached and only needs 3 pins including the power. It’s not all fun out of the box though as the firmware that is supplied on it isn’t very good at all. Fortunately someone has written a much improved firware, available here. To update this you will need to use an ICSP programmer to flash it with AVRDUDE or WinAVR, this post on the SparkFun product page has details. Unfortunately the ICSP pads on the serial backpack are unpopulated and they aren’t the easiest thing to solder to when the backpack is fixed to the screen. I did it by pushing some wires up from between the two and soldering on the top.

Here is the pinout for the ICSP:

Once the new firmware from summoningdark has been flashed to the backpack you can use the serialglcdlib library here.

Another oddity of this screen is that VIN on the 4 pin header requires 6-7V for the display to work properly but on inspection this just goes to a regulator to feed 5V to the rest of the board so as long as you are providing it with a regulated 5V (eg. from an Arduino) you can just connect to the 5V pad on the opposite side of the board instead.

This is a nice display with a crisp output and good contrast, the 3 wire connection is very handy but on the downside it isn’t cheap, at £27+delivery from SK Pang it’s nearly twice the price of a bare KS0108. Also, unlike with the bare KS0108 it isn’t easy to use different fonts with this display, only two can be used and they can only be changed by compiling them into the firmware when flashing the backpack.

I’ve put some code on GitHub for using this display with an Arduino and RFM12B transceiver as a display for OpenEnergyMonitor.

 

Adafruit ST7565 Serial 128×64 GLCD with RGB backlight

Another display I’ve been playing with is a ST7565 based unit branded by Adafruit and sold in the UK by Proto-PIC at the great price of only £17.99 It’s the same resolution as the KS0108 displays (128×64) but is slightly larger and more readable in good light without the backlight on. The backlight is where this display differs from most 128×64 displays as it is an RGB backlight, essentially three in one, you have a common anode and a separate cathode for each of red, green and blue, which means you can drive them from separate pins on the Arduino and use PWM to fade and mix the colours giving you a whole range of colours, not just red, green and blue.

To drive the LCD part you can either use the Adafruit libary or the JeeLabs library. The Jeelabs library is an extension of the Adafruit one and is more actively developed, recently having been updated for Arduino 1.0 and has some nice additional functions including support for remote displays that I’ve not looked at yet. It’s also the one that OpenEnergyMonitor use so was the natural choice.

This screen runs on 3.3V so you can either run your whole system on 3.3V or Proto PIC have included a very handy CD4050BC chip which can be used as a logic level converter as described on this Adafruit tutorial.

I’ve been testing this on a 5V Arduino and in order to leave pins free for the RFM12B transceiver and Nintendo DS touchscreen that I am also be using I’ve connected it as follows:

Arduino pin Screen
0 (via CD4050BC) SID
1 (via CD4050BC) SCLK
2 – will be used with RFM12B transceiver
3 Red backlight cathode
4 (via CD4050BC) A0
5 Green backlight cathode
6 Blue backlight cathode
7 (via CD4050BC) RST
8 (via CD4050BC) CS

Pins 3, 5 and 6 are used for the backlight as these pins can do hardware PWM which will allow the three colours to be dimmed individually.

The anode for the backlights is connected to 5V via a 270 Ohm resistor

Changes to the JeeLabs library

The JeeLabs library is written for their Graphics Board and if you want to use it with this display on an Arduino you will need to make a few minor changes.

Firstly, in GLCD_ST7565.cpp make sure the defines for the pins reflect what you are using, eg. I used:

#define PIN_SID 0
#define PIN_SCLK 1
#define PIN_A0 4
#define PIN_RST 7

Change LCDUNUSEDSTARTBYTES from 4 to 1 otherwise the display will be off to the right hand side:

#define LCDUNUSEDSTARTBYTES 1

Uncomment the slowSPI define:

// Switch from fast direct bit flipping to slower Arduino bit writes.
#define slowSPI

Change the PAGE_FLIP mode by changing from 0x7 to 0x3

// If the top line is appearing halfway down the screen, try the other mode.
//#define PAGE_FLIP 0x7
#define PAGE_FLIP 0x3

Adjust the contrast to your liking. I don’t think the contrast is as good on this as the KS0108 displays, you can adjust it in the library by changing the badly named st7565_Set_Brightness value in GLCD_ST7565.cpp, the default 0x15 was far too light for me and I settled on 0x19. 0x20 does gives slightly better text but then lines start to appear in the background with some colours.

st7565_Set_Brightness(0x19); // strictly speaking this is the contrast of the LCD panel, the twist on the crystals.

A minor point but the library has been written for a negative display so I reversed the colour defines in GLCD_ST7565.h to it makes more sense for a positive display, this will save some hair pulling later on I’m sure.

#define BLACK 1
#define WHITE 0

My code for using this screen as a display for OpenEnergyMonitor with the backlight colour changing with power usage is also available on my GitHub page.

 

Using the Nintendo DS Touchscreen with the Arduino

The touchscreen from the Nintendo DS handheld game console makes a good companion to these small GLCDs, it’s slightly larger but this doesn’t matter and you could even use the extra off screen space for fixed (ie. none graphical) buttons.

They aren’t expensive either £5.65 for the screen and £2.51 for a breakout board/connector from Proto-PIC.

You WILL want the breakout board, don’t be tempted to try and solder to the ribbon connector, if you think it looks small in a picture I promise it is smaller in real life.

They are very easy to connect to an Arduino, it connects to four analogue pins and give you an x and y value of the place the screen was touched so you can build button areas by doing something like:

if (y>510 && x<490) { //top left quadrant touched }

There is some good info on using these touchscreens with an Arduino here and here.

The four connections from the touchscreen change purpose depending on which axis is being read, eg. to read the x value you need to put a positive voltage on X2 and ground on X1 the use the analogRead function to get the value of Y1. To read the y value you switch the positive to Y2, ground to Y1 and read X1

I haven’t used pull down resistors as the accuracy is fine for detecting large segments of the screen to use as buttons and not using resistors allows 3.3V to be used and I plan to use a WiNode which is 3.3V for my final build.

My code for the ST7565 display makes use of this touchscreen.

3 thoughts on “GLCD Screens and Touchscreens with the Arduino

  1. I have been working on using the Adafruit version https://www.adafruit.com/products/438. It works, but I can not get the contrast improved to the point I can see the display in a well-lit room. All three backlight LEDs are on at 3.3V, but the display is weak despite trying all of the contrast levels and resistor divider combos. Are the pictures in your blog post taken with fairly long exposures in a dark room?

  2. Mine’s the positive version so it could be different but if it is brand new you might find it gets better after a day or so, I’m sure mine did as I remember thinking the contrast was very poor at first but then I ended up having to lower st7565_Set_Brightness again as the background started to become visible.

    As far as the pictures go I would say they are a pretty fair representation of how it looks in real life and I don’t have any trouble seeing it in a lit room or in daylight. It’s been a while since I took them but looking at the others on Flickr it wasn’t in a dark room but the exif data does show they were all fairly slow exposures (camera was on auto).

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.