128×128 Colour LCD to Arduino

For an upcoming new project I wanted a colour (UK spelling) LCD screen (ideally OLED), 256×256 (or greater) resolution and nice and cheap. It was not an easy 2 minute task. There were no OLED screens offering what I wanted (that I could see at the time). So compromises were made, in the end I purchased a 128×128 pixel screen (none OLED) for around $3.50 (£3.20, 3.50 Euro). Not as cheap as I thought I might get one for but the cheapest I could find. There were a lot of sellers offering this screen and it’s shown below.

As can be seen from the connections it accepts both 5V and 3.3V with the 5V side having a pre-soldered pin header. This particular one was ordered from Ali-Express and had a picture of a cartoon boy on the screen. I suspect buying any with the same pin connections will give you the same screen as the one above.

A supporting video is also available

For my new project (after the Space Invaders one, see https://www.xtronical.com/programming-series-space-invaders-on-arduino/), I wanted a screen where I could directly port the Arcade graphics and screen layout without too much messing about re-designing graphics. But for the price point I wanted this proved impossible. Most arcade games of the early 80’s did not go above 256 pixels in any give direction so porting the graphics should be easy I thought. At half the resolution I hope that transferring the graphics will not be too tedious and that in most cases I can simply reduce the number of pixels in each image by half.

So onto getting this screen to work with my Arduino (another more powerful processor will be required for the actual game envisaged but for now I want to get it working with Arduino).

Connections – careful now!
Looking at the back we can see +5v (this screen can be powered from 3v3 as well), several grounds (Gnd) and SCL/SDA. This should mean that this device is an I²C device and can be easily connected to our Arduino. Err… Think  again. This screen gave me no end of problems as connecting it to the  I²C connections and running any demo I could find on the internet did not get anything on the display. I went back and looked at the listing for this device, it stated SPI Bus not I²C ! So it began to become apparent that this screen had an SPI interface. SCL and SDA would logically seem to be SPI clock and data (MOSI) respectively but other pin labels didn’t match normal SPI protocol labels. Reading several resources for other different screens and looking at the source code for the examples in the Arduino IDE Examples library lead me to find the correct connections to power and use this screen. The connection table for a standard Uno /Nano are shown below.

LCD ScreenUno.Nano
5V5V
GNDGND
LED5V
SCL (SPI Clock)D13 (SPI hardware clock pin)
SDA (SPI Data)D11 (SPI Hardware Data)
RS (Register Select)D8 (labelled as DC in Adafruit code)
RST (Screen reset)D9
CS (Chip Select : Defined as Slave Select in SPI) If low this device is active on data linesD10

Power is self explanatory. LED adds a little extra brightness to the screen but it does still work if not connected. I’ve seen resistors added in series here and even variable ones to vary the brightness but I’ve ran it directly connected on this screen with no issues and wouldn’t want it dimmer as its not ultra bright. It is actually on even when not connected giving adequate brightness in my opinion. SCL is the SPI clock and goes to the Arduino’s hardware SPI pin (pin D13). SDA is actually the SPI MOSI connection and goes to the Arduino’s SPI MOSI pin (D11). RS is a Regsiter Select pin for ST7735 driver chips, this maps to a variable called TFT_DC in the Adafruit code (explained later) that I was using for testing. This controls whether we are sending a command to the ST7735 chip or actual data. I think that Adafruit call it DC meaning Data Control, but I’m not sure. On some boards it may even be referred to as A0. RST is the screen reset and and is connected to pin 9. These last two can connect to any Arduino pin but I use 8 and 9 as these are the defaults in the test code I was using. CS is Chip Select (usually referred to as Slave Select in the SPI protocol) and again can connect to any pin but I use the default for the code being used (D10). If this is pulled low then this device can receive or send data on the SPI bus. If only one device in your design you could pull this low permanently and not use D10.

Below is the connection diagram for this set up (connected to a Nano but Uno pin-out numbers are identical).

Driver Code
When presented with this board (as mentioned above) it was difficult to work out where wires should go and what driver software I needed for the display. Looking at the solitary chip on the board and Googling revealed nothing. So I went back to the sellers listing and found buried deep in a sub-page description the phrase “7735 drive”. Googling this revealed Adafruit had written some drivers for this chip for a board they had created (which also had an SD card slot on it as well). It was not surprising I didn’t find the 7735 chip on the board as this chip is designed to by embedded onto the back of the screen. It was being armed with this source code and other web pages dealing with different chip sets but similar displays that I managed to work out (with a little trial and error) the connections talked about previously above. So the next thing you would need is the driver code, on this github page

https://github.com/adafruit/Adafruit-ST7735-Library

If you wish you can click download then add this library to your Arduino IDE (see this link for more info on adding libraries). But for me it worked but there were issues (as it was really designed for their own boards, not these generic ones). But if you want to replicate what I’m going to go through then please go ahead and install. Once this has been done you should see the following example code from this menu “File->Examples->Adafruit ST7735 library->graphicstest”. Load it in and upload, you should see the display going through several graphics examples. You will notice that some of the graphics and text appear off screen, here are some examples.

Text clipped off at top, missing quite a bit of start of text

Should be fully rounded rectangles but clipped at top

Top of triangles clipped

Also when the screen orientation is rotated (in software) so you can write to the display any way up then more things either correct themselves or mess up again.

Fixing the ST7735 driver to work with this screen.
So we have some work to do still to make this work well with our display. The driver we have used to get this up and running was not designed for this display exactly. Things appear clipped and off screen. There were other issues with colour (i.e. red was blue and blue was red amongst other colour problems) and other graphics routines were not correct. I won’t bore you with all the tiny re-writes I did but just supply you with the new driver for this particular display. This driver is very specific, i.e. only targeting this display and resolution but it may well work with many other similar displays. At the time of writing I have no other displays to test with but will be expanding the driver code as and when required. The full driver code is available from the link below, add it into your Arduino in the usual manner (Adding libraries to the Arduino IDE.)

XTronical-ST7735-Library

Code is also available on GitHub at

https://github.com/XTronical/Adafruit-ST7735-Library

You will also need the Adafruit graphics library at

Adafruit graphics library

Load up the example code that should now be available at “Files->Examples->XTronical ST7735 Library->graphicstest”. This is basically the Adafruit example with just some tiny changes (It goes through all the tests for each rotational position of the screen) so that it uses the new driver file and slightly altered initialisation routine.

Upload and run the code and all the routines should now work.

That wraps it up for this article,  hope it was helpful 🙂