Detailed tutorial on connecting and programming the Nokia 5110 LCD. In this first part I'm only concerned with sending the bare minimum of commands so that something appears on the screen (all pixels on in this case).
Code is written from scratch, no libraries are used in this tutorial. Code is listed below.
#define RST 12
#define CE 11
#define DC 10
#define DIN 9
#define CLK 8
void LcdWriteCmd(byte cmd)
{
digitalWrite(DC, LOW); //DC pin is low for commands
digitalWrite(CE, LOW);
shiftOut(DIN, CLK, MSBFIRST, cmd); //transmit serial data
digitalWrite(CE, HIGH);
}
void setup()
{
pinMode(RST, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(DIN, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(RST, LOW);
digitalWrite(RST, HIGH);
LcdWriteCmd(0x21); // LCD extended commands
LcdWriteCmd(0xB8); // set LCD Vop (contrast)
LcdWriteCmd(0x04); // set temp coefficent
LcdWriteCmd(0x14); // LCD bias mode 1:40
LcdWriteCmd(0x20); // LCD basic commands
LcdWriteCmd(0x09); // LCD all segments on
}
void loop()
{
}
Code is written from scratch, no libraries are used in this tutorial. Code is listed below.
#define RST 12
#define CE 11
#define DC 10
#define DIN 9
#define CLK 8
void LcdWriteCmd(byte cmd)
{
digitalWrite(DC, LOW); //DC pin is low for commands
digitalWrite(CE, LOW);
shiftOut(DIN, CLK, MSBFIRST, cmd); //transmit serial data
digitalWrite(CE, HIGH);
}
void setup()
{
pinMode(RST, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(DIN, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(RST, LOW);
digitalWrite(RST, HIGH);
LcdWriteCmd(0x21); // LCD extended commands
LcdWriteCmd(0xB8); // set LCD Vop (contrast)
LcdWriteCmd(0x04); // set temp coefficent
LcdWriteCmd(0x14); // LCD bias mode 1:40
LcdWriteCmd(0x20); // LCD basic commands
LcdWriteCmd(0x09); // LCD all segments on
}
void loop()
{
}
Very nice tutorial. You added code in description is what everyone like. Thank you
good tutorial
How much mA does this display consumes at its maximum?
your code doesn't compile. I get "macro names must be identifiers"
I just had to drop a comment here. I've finally got around to working with this display. And low and behold, after viewing many YT video, this one potted up. 2013, wow, I had to watch it. Yes, we've come a long way in how things used to be done. I've watched MANY of your others videos. Great content, interesting and amusing too. And yes, I've come to realize that the data sheets are the Bible of how things work. Thanks for all the time and effect! Now on to part II
I had bought the lcd and had connected by looking at the goodled images of wiring diagrams. Your video has provided with a huge help in correcting my mistake. I was completely fed up of the display as it wont work, but this tutorial was just too good and was a huge help. Thanks 🙂
Hey man , thanks a lot .
It is the best tutorial I've ever seen.
Actually I had problem with the contrast of screen that I fixed it with your tutorial.
Thanks a lot.
👌👍🙏
Can I use other I/O pins?
Helped me to sort out my vague display with an adjustment to the contrast in a line of code. Thanks.
Thanks Julian just what I needed to get going with my Nokia display and Nano.
Did u add any external library like pcd8544??
"Take it to bed" lol I'm not the only one.
Arduino projects look like a joke compared to real embedded programming.