239
This is similar to the previous example, this time we will display the time on our LCD. If you are familiar with JavaScript you will recognise some of the code
These displays were used in old Nokia 5110 cell phones. It is a 84×48 pixel monochrome LCD display and you can use it for graphics, text or bitmaps. To use the display, you will require 5 digital output pins. Another pin can be used to control the backlight.
The display driver is a PCD8544 chip (which is another name for the display), and you can safely run the display off 3.3v
Here is the connections I used
Connection
LCD pin | Espruino Pico | |
---|---|---|
GND | GND | |
LIGHT | N/C | |
VCC | 3.3v | |
SCLK | B3 | |
DN(MOSI) | B5 | |
D/C | B13 | |
CE | B14 | |
RST | B15 |
Schematic
here is a schematic
Code
[codesyntax lang=”javascript”]
var g; function draw() { g.clear(); var t = new Date(); var time = t.getHours()+":" + ("0"+t.getMinutes()).substr(-2); var secs = ("0"+t.getSeconds()).substr(-2); g.setFontBitmap(); g.setFontVector(20); var timeWidth = g.stringWidth(time); g.drawString(time,(g.getWidth()-timeWidth-12)/2,10); g.setFontBitmap(); g.drawString(secs,(g.getWidth()+timeWidth-8)/2,26); g.flip(); } function onInit() { clearInterval(); // Setup SPI var SPI1 = new SPI(); SPI1.setup({ sck:B3, mosi:B5 }); // Initialise the LCD g = require("PCD8544").connect(SPI1, B13 /*DC*/, B14 /*CE*/, B15 /*RST*/, function(){ setInterval(draw, 1000); }); } onInit();
[/codesyntax]