Arduino Code for a Nokia 5110 LCD Screen

Arduino Code for a Nokia 5110 LCD Screen


In this tutorial, we will explore how to use the Nokia 5110 LCD screen with an Arduino to display various graphics and text. The project will demonstrate how to draw lines, circles, rectangles, and even display text inside those shapes. By the end, you'll have a better understanding of how to interact with this LCD using Arduino code.

Nokia 5110_LCD

To provide clearer guidance, I encourage you to watch the associated video for a visual representation of the wiring and code implementation (in video at 00:00).

Hardware Explained

The Nokia 5110 LCD is a compact graphical display that operates on the SPI protocol, enabling efficient communication with the Arduino. It features a resolution of 84x48 pixels, which is sufficient for displaying basic graphics and text. The display requires only a few pins to operate, making it a great choice for projects with limited I/O options.

In addition to the LCD, you will need an Arduino board, typically an Arduino Uno or similar, a breadboard, and some jumper wires. The wiring is straightforward, and the LCD is powered by connecting its VCC pin to the Arduino's 5V output.

Datasheet Details

ManufacturerPhilips
Part numberPCD8544
Logic/IO voltage3.3 V
Supply voltage3.3 – 5.0 V
Max current200 µA
Screen resolution84 x 48 pixels
InterfaceSerial (SPI)
PackageModule

  • Use a current-limiting resistor for the LED pin to prevent damage.
  • Ensure connections to VCC and GND are secure to avoid display issues.
  • Double-check SPI pin connections: SCE, RST, D/C, DN, and SCLK.
  • Keep the contrast setting within the recommended range (40-60).
  • Update the display after drawing graphics to see changes.

Wiring Instructions

Arduino wiring for Nokia 5110 LCD
Arduino wiring for Nokia 5110 LCD

To wire the Nokia 5110 LCD to your Arduino, follow these connections:

  • Connect the LCD's VCC pin to the Arduino's 5V pin.
  • Connect the GND pin on the LCD to one of the Arduino's GND pins.
  • Connect the SCE pin on the LCD to pin 7 on the Arduino.
  • Connect the RST pin to pin 6.
  • Connect the D/C pin to pin 5.
  • Connect the DN (MOSI) pin to pin 11.
  • Connect the SCLK pin to pin 13.
  • Finally, connect the LED pin to pin 9 through a 330-ohm resistor.

These connections will allow the Arduino to communicate with the LCD effectively. If you need to adjust the wiring for your specific setup, ensure that the SPI pins remain consistent.

Code Examples & Walkthrough

The following code snippet initializes the LCD and sets the contrast:


void setup() {
  Serial.begin(9600);
  lcdBegin(); // Initialize the LCD
  setContrast(40); // Set contrast level
  delay(2000);
  clearDisplay(BLACK); // Clear the display
  updateDisplay(); // Update the display
}

In this snippet, the lcdBegin() function sets up the necessary pins for the LCD, while setContrast(40) adjusts the display's contrast. After a brief delay, the display is cleared to prepare for new content.

Nokia 5110_LCD back view

Next, we can draw a line on the display:


setLine(1, 4, 70, 4, BLACK); // Draw a horizontal line
updateDisplay(); // Make the line visible

This line of code uses the setLine() function, which takes the starting and ending coordinates along with a color parameter. After drawing, it's essential to call updateDisplay() to reflect the changes on the screen.

Finally, we can display text within a rectangle:


setRect(10, 10, 70, 40, 1, BLACK); // Draw a filled rectangle
setStr("Robojax ", 15, 20, WHITE); // Display text inside
updateDisplay(); // Update to show the changes

Here, setRect() creates a rectangle, while setStr() places text inside it. The color parameters define how the rectangle and text appear on the screen.

Demonstration / What to Expect

Upon running the code, you should see a series of graphics displayed on the Nokia 5110 LCD, including lines, circles, rectangles, and text. Ensure your wiring is correct to avoid issues like reversed polarity or floating inputs, which could prevent the display from functioning (in video at 02:30).

Video Timestamps

  • 00:00 - Introduction to the project
  • 01:30 - Wiring instructions
  • 03:00 - Code setup and explanation
  • 05:00 - Displaying graphics and text
  • 07:30 - Conclusion and further modifications

Images

Nokia 5110_LCD back view
Nokia 5110_LCD back view
Arduino wiring for Nokia 5110 LCD
Arduino wiring for Nokia 5110 LCD
Nokia 5110_LCD
Nokia 5110_LCD
82-Arduino code: Dual-axis joystick with Nokia 5110 screen to display dots.
Language: C++
Copied!

Things you might need

Resources & references

No resources yet.

Files📁

Fritzing File