Sunday 16 October 2016

Revisiting Sparkfun Colour LCD

Python for Sparkfun Colour LCD

Some time ago I posted code and setup notes to get the Nokia6100 screens, featuring on the Sparkfun Arduino shield, working on a RaspberryPi.
The examples were written in C/C++. This isn't so useful when the majority of users are working with Python so I decided to revisit and provide a useful object class to handle the display.

Setup

The shield is configured to fit straight on top of the Arduino. This doesn't mean it cannot work on other platforms. A bit of creative use of jump leads can get this working quite as effortlessly on the Pi.
The obvious connections are to 3.3V, 5V and GND. 
The other pins go to SPI (ensure it's enabled on your Pi in raspi-config).

From the shield connect:
Pin 13 (Clock) to 11 (SCLK) on a Pi
Pin 11 (MOSI) to 9 (MOSI) on a Pi
Pin 9 (CS) to 8 (CS0) on a Pi
Pin 8 (Reset) to any free GPIO of your choice. I used 25

The 3 buttons are connected to 3, 4 and 5 on the shield. I'm not going to cover the buttons here as it's another topic. RPi.GPIO library provides everything you need to get them working.

Software for the Raspberry Pi

Python code for the Pi can be found on my GitHub site at https://github.com/AidanHolmes/Nokia6100.

The code hasn't been made into a module or anything fancy.

from nokia import Nokia6100
should be enough to create the connection and send PIL images to the 132x132 LCD display.

This works on the shields with the Philips PCF8833 display as this is the variant I have. Code for the Epson display is included, but not tested. Start up sequence and code for the Epson is mostly borrowed from Jame P. Lynch's code on the Sparkfun site in Nokia LCD Display Driver.pdf.

Quick Start

from nokia import Nokia6100
from PIL import Image

disp = Nokia6100(25) # Assuming SPI bus 0 and CS0 used
disp.initialise()

img = Image.open('myimg.jpg')
disp.display(img)

Reference

The interface for the Nokia6100 class can be found on the GitHub page. It's quite a small set of functions. PIL does all the hard work with images so the functionality is just about the hardware control. 

Performance

The C/C++ code pushes data over SPI faster than the Python. It's fairly marginal and both the Python and C/C++ code can be seen to redraw the display. The redraw is more apparent using Python whilst the C/C++ code is a quick flicker. 
I'm not quite sure what the real speed is over the Raspberry Pi's SPI, but I expect that the real speed isn't the max speed set in spidev.

In any case, I wouldn't expect the LCD to handle rapidly changing displays very well with user-space code driving the display.