Go Down

Topic: Wiring 12864A LCD with Mega 2560 (Read 1 time) previous topic - next topic

bemar

Hello,

I'm new to Arduino and trying to wire a 12864A Display with my Mega2560 board.
I've found a description (http://lcd12864r-arduino.blogspot.ch/) in the forum on which such displays are connected with the mega board over some additional controllers on the back of the display and interface shields. But I only have the display and the mega board (see photos).

In this description (http://playground.arduino.cc/Code/LCD12864) the pins on the LCD have names like EN, RS, RW ..... but I only have numbers from 1 to 20.

Could somebody please explain how to wire my display with the mega board?

Thank you in advance

Ben

Mega 2560

gregted

#1
Apr 12, 2013, 02:20 pm Last Edit: Apr 12, 2013, 10:05 pm by gregted Reason: 1
Hey Ben,

New to this myself but got my screen working today so I can help.

You may already know some of this so if so, ignore it.

The first thing you need to do is find out what com port your arduino is connected to.

To do this, ensure your arduino is unplugged and open device manager from Start, Control panel, System, device manager.

Plug in your arduino and see what com port changes. Eg. com 4 or com 3 etc. This is the com port your arduino is connected to.

Download arduino from here http://www.arduino.cc/

Open arduino and click Tools and select your board and com port.

Copy and paste this to your open arduino page.

/*

 HelloWorld.pde
 
 "Hello World!" example code.
 
 >>> Before compiling: Please remove comment from the constructor of the
 >>> connected graphics display (see below).
 
 Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
 
 Copyright (c) 2012, olikraus@gmail.com
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification,
 are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this list
   of conditions and the following disclaimer.
   
 * Redistributions in binary form must reproduce the above copyright notice, this
   list of conditions and the following disclaimer in the documentation and/or other
   materials provided with the distribution.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
*/


#include "U8glib.h"

// setup u8g object, please remove comment from one of the following constructor calls

//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9);       // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9);       // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9);  // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGS102 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGM132 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGM128 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_ST7920_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, U8G_PIN_NONE, U8G_PIN_NONE, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_128X64 u8g(18, 16, 17, U8G_PIN_NONE);                  // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_192X32 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, U8G_PIN_NONE, U8G_PIN_NONE, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_192X32 u8g(18, 16, 17, U8G_PIN_NONE);                  // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_LM6059 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_LM6063 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_BW u8g(10, 9);            // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9);             // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9);            // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9);             // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
// RS=19, WR=18, CS=17, RST=16
U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 );  // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16

void draw(void) {
 // graphic commands to redraw the complete screen should be placed here  
 u8g.setFont(u8g_font_unifont);
 //u8g.setFont(u8g_font_osb21);
 u8g.drawStr( 0, 22, "Hello World");
}

void setup(void) {
 
 // flip screen, if required
 // u8g.setRot180();

 // assign default color value
 if ( u8g.getMode() == U8G_MODE_R3G3B2 )
   u8g.setColorIndex(255);     // white
 else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
   u8g.setColorIndex(3);         // max intensity
 else if ( u8g.getMode() == U8G_MODE_BW )
   u8g.setColorIndex(1);         // pixel on
}

void loop(void) {
 // picture loop
 u8g.firstPage();  
 do {
   draw();
 } while( u8g.nextPage() );
 
 // rebuild the picture after some delay
 delay(500);
}


Don't copy anything else including this line....

You will notice at the start of the script a " Please remove comment." this means delete the // from the start of the line that matches your lcd screen.

Mine was this one..

U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16


Anything after // is ignored by the program. These comments are to tell others what the line is for.

You'll see 8,9,10,11,4,5,6,7 are the digital pins on your arduino in that order.

18, 14, 15, 17, 16 (or analog 3,2,4,0,1 ) to your pinouts for your lcd screen for enable, select chip1, select chip2, Display instructions, and r/w for rewrite.

The following pins relate to my setup of arduino uno and 12864a lcd screen.


lcd ; Arduino
1   ; To 12k resistor and then to ground ( 12k is brown ( the number 1) , red ( the number 2 ), orange ( 3, The multiplier. Equals 3 zeros ).
2   :+5 volts
3   ; to centre pin of 10k pot
4   ; Analog pin 3 ( Called 18  in sketches or en for enable)
5   ; Analog pin 2 ( Called  14 or cs1 for select chip 1)
6   ; Analog pin 4 ( Called 15 or cs2 for select chip 2)
7   ; Digital pin 8
8   ; Digital pin 9
9   ; Digital pin 10
10 ; Digital pin 11
11 ; Digital pin 4
12 ; Digital pin 5
13 ; Digital pin 6
14 ; Digital pin 7
15 ; Analog pin 0 ( Called 17 or Display instruction)
16 ; Analog pin 1 ( Called 16 or Reset)
17 ; Not connected
18 ; One side of 10 k pot
19 ; 5 volts
20 ; Ground

Other side of 10k pot to ground.

Pot is for adjusting contrast but mine doesn't work yet but all displays work and can be seen on screen.

I also have a Mega 2560 but haven't tried to connect this board to my lcd yet. Maybe others can help with that board.

Hope this helps.

Greg

Go Up