Uncategorized

RasPiO duino with nokia 5110 LCD

I’ve added a cheap nokia 5110 LCD to my RasPiO Duino, it took me awhile to get the example code to work.

I downloaded the PCD8544 display library (Nokia 5110) (http://adafru.it/aHn) and the GFX graphics core library (
http://adafru.it/aJa).

Reading the readme note was essential as the name and location of the library is critical to getting this to compile.
One issue to be aware of is that the readme suggested placing the files in sketchbook/Libraries whereas I found that it was required to be in sketchbook/libraries (lowercase L).

The example code compiled OK (once I’d figured out the correct file name and location).
sketchbook/libraries/Adafruit_PCD8544
sketchbook/libraries/Adafruit_GFX

I found a nice clear wiring scheme at duino4projects, which I’ve followed (but I’ve connected the backlight to a pin 9 for PWM so I can dim it). http://duino4projects.com/getting-nokia-5110-lcd-running-arduino/
Pictures of the wiring are less useful as there are different variants of this LCD board so the pin locations are relative.

I added some more female and male headers to my RasPiO Duino, in the prototyping area, for easier connections to peripherals.20150603_205520

I changed the male headers on the LCD for female ones (because I could only find my male dupont cables.

nokia 5110 lcd female header

With a swift (OK, slow and painful) re-write of the display code we have a short countdown to….

I started with code for a countdown timer for 5110 LCD which I found on the Arduino forums:

http://forum.arduino.cc/index.php?topic=145464.0

 

I modified it a bit to give me this:


/*********************************************************************
This is an example sketch for a countdown timer using Nokia 5110 LCD
and adafruit library for the display

RWSDev.net
*********************************************************************/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// pin 7 - SCE
// pin 6 - RST
// pin 5 - D/C
// pin 4 - DN
// pin 3 - SCLK
// pin 9 - Backlight PWM

// set timer position on lcd
int xPos1 = 16;
int xPos2 = 4;
int xPos3 = 4;
int yPos1 = 16;
int yPos2 = 8;
int yPos3 = 16;

int hours =0;
int minutes = 0;
int seconds = 5;
int backlight = 9;    // setting the PWM Pin for the Backlight
int brightness = 130;   // setting the brightness level for the backlight

Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

void setup()   {
  display.begin();
  display.clearDisplay();   // clears the screen and buffer
  display.display();
  pinMode(backlight, OUTPUT);
  analogWrite(backlight, brightness);
}

void loop() {
  while (hours > 0 || minutes > 0 || seconds >= 0) {
    display.clearDisplay();   // clears the screen and buffer
    display.setContrast(30);
    display.setTextSize(2);
    display.setCursor(xPos1, yPos1);
    (minutes < 10) ?display.print("0"):NULL;
    display.print(minutes);
    display.print(":");
    (seconds < 10) ?display.print("0"):NULL;
    display.print(seconds);
    display.display();
    stepDown();
    delay(1000);
  }
}

void stepDown() {
    if (seconds > 0) {
      seconds -= 1;
    } else {
      if (minutes > 0) {
        seconds = 59;
        minutes -= 1;
      } else {
        if (hours > 0) {
          seconds = 59;
          minutes = 59;
          hours -= 1;
        } else {
          trigger();
          delay(5000);
          seconds = 5;
        }
      }
    }
}

void trigger() {
  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(2);
  display.setCursor(xPos2, yPos2);
  display.println("RasPiO");
  display.setCursor(xPos3, yPos3);
  display.println("Duino");
  display.display();
}

 

Advertisements
Standard

4 thoughts on “RasPiO duino with nokia 5110 LCD

    • Woops, I must have edited it a bit somewhere along the line.

      I’ve added the hours integer now so it should work now. I’ll test it at some point (i’ll have to reassemble the 5110 LCD into my ‘duino first).

      • A few additional remarks about your code:
        * you display only minutes and seconds, but you have a working invisible hours variable
        * the initial value of the count down is set at variable creation and only used for first count down, then set elsewhere for the restart on loop. So change has to be done on two places
        * there was a kind of overlap at the end screen between the two words, maybe a font size issue, (change in the lib?). From memory I added 8(?) pixels(?) to move the second word down a bit.

        But your documentation and code was really useful for knowing the wiring, testing the screen and the library installation.

        Thanks.

        In my copy, I replaced the fixed brightness by a variable from a potentiometer on an analogue input. Then at the end of the count down I make the brightness blink.

        Here is a video of the result:

        I can share the code, not sure I master git to do it the proper way.

  1. Thanks for the feedback David,

    I’m glad my example was of some use.

    This was an ugly hack job of programming which I threw together from a few other examples, I think it was my 3rd or 4th Arduino sketch. I can’t say that my programming will be any better these days as I haven’t really used my RaspIO duino (or any other arduino) much since I wrote this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s