Freitag, 29. März 2013

Connect and use a Sainsmart LCD12864 (ST7920) with a Arduino Mega 2560

Hello guest,

maybe here you find what you are looking for. A tutorial to wire a 12864 graphical LCD display with your Arduino Board and control it with the IDE afterwards.

My Equipment
  • Arduino Mega 2560 Board
  • Sainsmart J12864 LCD with serial/parallel backplane 
  • A few male/female wires

Whats the purpose of this blog?
  1. How to wire the 12864 LCD with your Arduino Board (Mega 2560 in my case)
  2. How to control the LCD


1. Wire LCD with board

Connect the pins of the serial interface of your LCD backplane with your arduino board as following described:

Take the backplane of the LCD and watch into the front of your serial/SPI interface like in the picture:



and connect the colored pins with the same colored jacks on the arduino board.


The result should look like:



Now your LCD is wired to your Arduino Mega board (should also work with other Arduino models).

2. Control the LCD

The easiest way for me was to use the u8glib driver from this site. How to install additional libraries in the Arduino IDE please have a look here.

After you've installed the u8glib libraries open your Arduino IDE and paste this code snippet to your sketch (do you see the jack numbers in the driver initialisation line?)


#include <U8glib.h>

U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);        

void draw(void) {
  u8g.drawCircle(20, 20, 10);
  u8g.drawDisc(30, 30, 10);
  u8g.drawLine(60, 30, 90, 50);
  u8g.drawBox(50, 50, 20, 10);
  u8g.drawFrame(70, 10, 10, 30);
}

void setup(void) { }

void loop(void) {
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
  // rebuild the picture after some delay
  delay(500);
}
After you compiled and uploaded your code to your Arduino you should see this:


Now your LCD is wired and the drivers are installed. Happy LCDing.

Feel free to leave a feedback. 

I've interested to control the LCD with the Sensor Shield V5 and the LCD-Serial interface. Unfortunately I had no luck to tell the u8glib driver how to adress it.

Best regards 

Ben


Kommentare:

  1. Thanks for the Tutorial.
    Oliver

    AntwortenLöschen
  2. Nice tutorial! I haven't managed to find a LCD that includes a serial/parallel interface. Did you buy it separatedly or did it come with the display? Could you post some links so we know where to buy it? Thanks in advance!

    AntwortenLöschen
  3. Thanks for the tutorial. But, I keep getting
    "'U8G_PIN_NONE' was not declared in this scope"
    I got the LCD illuminated and downloaded the U8glib library files.
    I just can't get to validate the sketch.
    Please advise.
    Thank you.

    AntwortenLöschen
    Antworten
    1. Finally worked after downloading the library a few more times. Have no idea why? - Nice display. Now to learn to use it... Thanks for the tutorial.

      Löschen