Tuesday, February 1, 2011

LeafLabs Maple with Nokia 5110 LCD display

I just got two Nokia5110 LCD displays, similar to this one. It's a basic monochrome 84x48 pixel display, very affordable, and they seem to be pretty widely available. It is the successor of the Nokia3310, both display can use the same drivers. One tricky part of the display is that the data is written to the display serially, one byte at a time. And one byte represents 8 pixels (vertically). So you cannot set one pixel at a time. This is fine for fonts (if they are multiple of 8 pixels high). But if you need control over each pixel, a display buffer needs to be implemented in the driver software.

I wanted to see if I can get this display to work on the Maple, so I did a quick port of an existing Arduino library for the display to the Maple. The library is modeled after the LiquidCrystal code, so it can be called pretty much the same way. It is just using a bit-banged approach to control the display, so you can hook up the display to pretty much any of the Maple GPIO pins. Hooking up the display requires 5 data pins on the Maple.
Here's a quick "Hello World" example:


The sketch for this is pretty simple too:

/*
 LCD_Nokia3310 Library - Hello World
 
 Demonstrates the use a Nokia 3310 or 5110 LCD display.  
 These displays are are 48x84 pixel monochrome serial displays
 
 If an 8x6 pixel font is used, characters are arranged in 6 lines x 14 characters
 This sketch prints "Hello World!" to the LCD
 and also the number seconds since the program was started
  
 The circuit:
 * LCD CS pin to digital pin 8
 * LCD reset pin to digital pin 7
 * LCD mode pin to digital pin 6
 * LCD clock pin to digital pin 5
 * LCD data pin to digital pin 4
 * LCD LED pin is connected to 3.3V
 */

#define LCD_PIN_CS 8   //digital Pin 8
#define LCD_PIN_RST 7
#define LCD_PIN_DC 6
#define LCD_PIN_SCK 5
#define LCD_PIN_DATA 4   //digital Pin 4

// include the library code:
#include <LCD_Nokia3310.h>

// initialize the library with the numbers of the interface pins
LCD_Nokia3310 lcd(LCD_PIN_CS, LCD_PIN_RST, 
                  LCD_PIN_DC, LCD_PIN_SCK, LCD_PIN_DATA);
uint8 x;

void setup() {
  lcd.init();
  lcd.setCursor(0,0);
  lcd.print("Hello World !!");
  x = 0;
}

void loop() {
  
  lcd.setCursor(0,2);
  if (x==0)
  {
    lcd.print("<= LCD Demo =>");
    x++;
  }
  else
  {
    lcd.setCursor(3,2);
    lcd.printInverse("LCD Demo");
    x = 0;
  }
  
  // set the cursor to column 0, line 5
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 4);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);   
  
  delay(1000);
}



The current display library does not implement a display buffer in RAM, so it's mostly useful for displaying fonts. But it's a nice tool to have for displaying textual data with a Maple.