Connecting a graphic display nokia 5110

Probably, I, like all Arduino builders, had some kind of crazy idea in my head. I ordered all the necessary parts from China. We had to wait a very long time, but then a clone of the Arduino Uno board and a Nokia 5110 LCD display were delivered ahead of schedule. Since I was not familiar with electronics and programming before, I decided not to waste time and began to learn how to display information on this module.

The first thing I did was Google and came across the publication “Arduino, Nokia 5110 LCD module and Cyrillic alphabet” from the author. And then I realized that everything that I had previously planned would not be so easy to do.

I figured out the Cyrillic alphabet, everything is simple there, I won’t copy-paste the last post, but there’s a real problem with the pictures. The task is: you need to draw a picture and upload it to the display. I encountered the first problem, I went into the Arduino programming environment and saw that there is no such thing as “Insert - Images”, but you need to write a picture with a certain code in the hex calculus system. I found several editors, but that was not the case. The picture is not displayed adequately. I started looking for problems that could be.

Through a bunch of experiments, attempts and tests, I came up with an algorithm that I will share with you:

1) You need to get the picture itself, in black and white .bmp format with an extension of 84 x 48 pixels.
This can be done in a bunch of ways. Almost every graphic editor has a “Save As” function where we specify the necessary parameters.
I did it in corelDRAW. We get something similar. It is necessary to clarify that the name of the picture must be saved with the Latin keyboard layout, since the next program will not be able to open it.

2) If necessary, you can edit the picture in paint; oddly enough, there are several simple and interesting tools there.

3) Using this we get the hex code of the image.

4) Paste this code into the Arduino program code and upload it to the board:

// SCK - Pin 8 // MOSI - Pin 9 // DC - Pin 10 // RST - Pin 11 // CS - Pin 12 // #include LCD5110 myGLCD(8,9,10,11,12); extern uint8_t OKO; float y; uint8_t* bm; int space; void setup() ( myGLCD.InitLCD(); ) void loop() ( myGLCD.clrScr(); myGLCD.drawBitmap(0, 0, OKO, 84, 48); myGLCD.update(); delay(2000); )

#include const uint8_t OKO PROGMEM=( //Copied hex code GLCD tools );

New articles

● Project 16: Graphic indicator. Connecting the Nokia 5110 display

In this experiment, we will look at the Nokia 5110 Graphics Display, which can be used in Arduino projects to display graphical information.

Required components:

The Nokia 5110 liquid crystal display is a monochrome display with a resolution of 84×48 on a PCD8544 controller, designed to display graphic and text information. The display power supply should be between 2.7-3.3 V (maximum 3.3 V; if 5 V is supplied to the VCC pin, the display may be damaged). But the controller pins are +5V tolerant, so they can be directly connected to the Arduino inputs. An important point is low consumption, which allows you to power the display from the Arduino board without an external power source.
The connection diagram for Nokia 5110 to Arduino is shown in Fig. 16.1.

Rice. 16.1. Connection diagram for Nokia 5110 to Arduino

To work with the Nokia 5110 display, we will use the Adafruit_GFX library, which has rich capabilities for displaying graphics and text. In our experiment, we will receive illumination data from a photoresistor connected to the analog input of Arduino A0 and output the illumination data in numerical and graphical representation. The connection diagram is shown in Fig. 16.2.

Rice. 16.2. Connection diagram of Nokia 5110 and photoresistor to Arduino

The code for our experiment sketch is shown in Listing 16.1. We read the data from the photoresistor and display the numeric value, as well as graphically (progress bar), the illuminance value as a percentage of the maximum value. We take the values ​​of minimum and maximum illumination from experiment 13.

// Connecting the library #include #include // PIN 7 - RST Pin 1 on LCD // PIN 6 - CE Pin 2 on LCD // PIN 5 - DC Pin 3 on LCD // PIN 4 - DIN Pin 4 on LCD // PIN 3 - CLK Pin 5 on LCD Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7); const int LIGHT=A0; // Pin A0 for photoresistor input const int MIN_LIGHT=200 ; // Lower illumination threshold const int MAX_LIGHT=900 ; // Upper illumination threshold // Variable for storing photoresistor data int val1,val2 = 0 ; void setup()( display.begin(); // set screen background contrast // very important parameter! display.setContrast(60); display.clearDisplay(); // clear screen delay(2000); ) void loop()( val1 = analogRead(LIGHT); // Read the photoresistor readings drawText(val1,1); // display text // scaling the potentiometer value to 0-75 val2= map (val1, MIN_LIGHT, MAX_LIGHT, 0 , 75 ); // output black rectangle in % display.fillRect(5, 25, val2, 10, 1); // output the white part of the rectangle display.fillRect(5 +val2,25 , 75 -val2, 10 , 0 ); display.display(); delay(1000); // pause before new measurement drawText(val1,2); // erase text) // text output procedure void drawText( unsigned long num,int color)( display.setTextSize(2); // font size display.setCursor(20,5); // cursor position if (color==1 ) display.setTextColor(BLACK); // print the value else display.setTextColor(WHITE); // erase (white on white) display.print(num); )
Connection order:

1. Connect the Nokia 5110 display sensor and photoresistor according to the diagram in Fig. 16.2.
2. Load the sketch from Listing 16.1 onto the Arduino board.
3. Blocking the flow of light with your hand, look at the change in illumination readings on the display screen.

Program listings

For inexperienced users who want to independently create control systems for robotic devices or automation tools, various hardware modules and their modifications are offered on the IT services market. As a rule, such devices have a simple architecture with copy rights and accompanying software in the form of simple utilities. Such products can be used either independently or connected to other computer systems via wired or wireless interfaces.

Pros of working with graphic displays

Previously, graphic monochrome displays were used very widely in the production of cell phones.

Nokia has released a huge number of different models equipped with such a screen. The days of those phones have passed, but displays have not disappeared from the market and continue to be actively used to this day. They turned out to be indispensable and, in addition, cheap devices for text output and displays work by creating matrices of dots on the screens, which highlight the image. They save resources and time, while displaying a large amount of information and consuming a small amount of energy. There are a huge number of different areas where Nokia 5110 devices can be used: photo, video, television equipment, medicine, and in many other industries.

Before describing how to connect a Nokia display to the Arduino hardware module, it is necessary to provide a brief introduction to these devices.

Benefits of using Arduino Uno

Many platforms and microcontrollers have been created that are analogues of the Arduino platform presented in this article. Some of these analogues are Netmedia's BX-24, Parallax Basic Stamp and many others. However, we will focus on the Arduino Uno, since this designer has a number of advantages over other controllers. You should pay attention to them when choosing a platform for work. Firstly The main thing is the low cost of these devices. Models with this software cost less than $45, and if desired, they can be assembled manually, as they have a fairly simple design. The second point is that Arduino platforms can work with all operating systems: Windows, Linux. , as well as Macintosh OSX, while everyone else is limited to working exclusively with Windows.

Description of Arduino Uno

Arduino Uno is a platform for developing and programming various devices, which has 14 digital inputs and outputs, 6 analog inputs, several connectors (USB, ICSP, power) and a button that has a device reset function. This platform has a built-in fuse that prevents short circuits and ensures safe operation with the USB cable. It is triggered when more than 500 mA of current flows through the USB port. Compared to mainframe computers, the Arduino Uno interacts much more closely with the physical environment around it. The platform is built on a printed circuit board and is designed to work with open source. It can be used by both students and amateurs, as well as professionals who can expand and complement the models at their own discretion and work freely with open source. The platform is designed in such a way that new components can be easily added to it. The design requires the developer to choose to use the device independently; therefore, it is not placed in a housing and is not strictly tied to installation.

Description of the Nokia 5110 display

The Nokia 5110 graphic display is a budget monochrome display with a diagonal of 1.6", which allows you to display not only text information, but also pictures. Its resolution is 48x84 px, and the voltage at which it can operate is 2.7-5 V. Information on the screen is displayed in vertical blocks. Their height is eight pixels, the width of the screen is six lines. On the back panel there are symbols for each contact, which will not allow users to make mistakes in their location.

Earlier in this blog, several LCD displays/indicators and their use from Arduino were covered. Their significant drawback is their rather large size and weight. Often this is not a problem. For example, if you are assembling a DIY soldering station in a homemade case, it somehow doesn’t matter what size the display is. On the other hand, if you need a display on, say, a quadcopter, then weight and size become critical. Therefore, today we will learn how to work with a very small and light screen from the Nokia 5110 phone.

Note: Other posts on the topic of screens - Learned to display text on an LCD indicator from Arduino, About using 1602 screens with an I2C adapter, Working with LCD based on HD44780 without libraries, and Digital thermometer from an LCD matrix, TMP36 and Arduino.

Don’t worry, you won’t have to buy the Nokia 5110, which effectively doesn’t exist today, pick out the screen from it and throw away all the other parts. The Nokia 5110 screen is a very common stand-alone module for radio amateurs and costs anywhere from $2 to $5, depending on the store. In Russia, the module can be purchased, for example, on tpai.ru, arduino-kit.ru, amperkot.ru, compacttool.ru, chipster.ru or electromicro.ru. And, of course, the screens are sold at the lowest price on AliExpress, but you will have to wait a month or two until they arrive from China.

As often happens in the Arduino world, there are already ready-made libraries for the module, and more than one. I liked the LCD5110 library posted on the website rinkydinkelectronics.com. This library has two versions. The first one is called LCD5110_Basic. It is simpler and can only display text in fonts of different sizes. It is possible to create your own fonts. The second version is called LCD5110_Graph. It has all the capabilities of the first library and, in addition to them, can draw segments, rectangles, circles, and so on.

For the purposes of this post, the LCD5110_Basic will be used. Both libraries are well documented and have many examples of use, so if you need LCD5110_Graph you can easily figure it out on your own. It is worth noting, however, that in order for LCD5110_Basic to compile without warnings, I had to make a couple of small edits to its code.

So, an example of using the library:

#include

extern uint8_t BigNumbers ;
extern uint8_t MediumNumbers ;
extern uint8_t SmallFont ;

/* SCK / CLK, MOSI / DIN, DC, RST, CS */
LCD5110 lcd(2, 3, 4, 6, 5);

void setup()
{
lcd.InitLCD();
}

int ctr = 0 ;
void loop()
{
lcd.clrScr();

Lcd.setFont(BigNumbers) ;
lcd.printNumI(ctr, RIGHT, 0);

Lcd.setFont(MediumNumbers) ;
lcd.printNumF(12.34, 2, RIGHT, 24);

Lcd.setFont(SmallFont) ;
lcd.print ("Line 1" , 0 , 8 * 0 ) ;
lcd.print("Line 2", 0, 8 * 1);
lcd.print ("Line 3" , 0 , 8 * 2 ) ;
lcd.print ("L 4" , 0 , 8 * 3 ) ;
lcd.print ("L 5" , 0 , 8 * 4 ) ;
lcd.print ("0123456789ABCD" , 0 , 8 * 5 ) ;

Ctr + = 5 ;
if (ctr >= 1000 )
ctr = 0 ;

Delay(500);
}

What it looks like in action:

I hope there is no need to chew the code. Please note that the module is powered by 3.3 V, but it understands commands from Arduino normally without any logic level converters. Accordingly, we connect the VCC (power) and BL (backlight) pins to 3.3 V, connect GND to ground, and connect the remaining five pins to the Arduino digital pins. We pass the pin numbers to the LCD5110 class constructor in accordance with the comments in the given code.

Simple, isn't it? You can find the full source code for this post in this GitHub repository. Additions and questions, as always, are welcome in every possible way.

Addition: The author of the library for working with the Nokia 5110 screen is also the author of the OLED_I2C library, designed to work with equally popular OLED screens with an I2C interface. You can find an example of using OLED_I2C in the post Using a Sega Genesis joystick in Arduino projects. As you might expect, the two libraries have a similar interface.

Philips PCD8544.
To connect the module to other devices, the board contains a connector plug and holes for soldering wires. There are also 4 mounting holes located at the corners of the board.
The monochromatic display of the Nokia 5110 LCD (blue screen) is backlit with blue LEDs. Over the years of production, Nokia 5110 has been used and is used in a wide range of applications. The display module facilitates Nokia connection and installation in the device. Thanks to the module, the first acquaintance of an electronics engineer or programmer with the Nokia 5110 LCD display is simplified. Initially used as a mobile phone indicator, the display has spread to other categories of devices. It is convenient to use in measuring instruments: voltmeters, ammeters, ohmmeters and others. The display is also useful for displaying readings from medical mobile devices. It is interesting to use it for the scale of a radio receiver or a signal level indicator in sound-reproducing equipment. The screen with a resolution of 84x48 pixels allows you to display symbolic and graphic information.
If you have experience with the Nokia 3310 LCD, it will be easy to master the Nokia 5110 LCD, since these indicators are built on the same PCD8544 controller.

Nokia 5110 LCD module specifications

Nutrition
voltage 2.7…3.3 V
current
backlight off 5 mA
backlight on 20 mA

Air temperature during operation 0…50
Storage temperature -10…70

LCD indicator Nokia 5110

Main characteristics

The main component of the Nokia 5110 LCD module is the LCD indicator. It has built-in generators of supply voltage and bias of LCD elements, and there is LED backlighting. SPI information input interface. Nokia 5110 can operate in four modes: normal, image inversion, blank screen and “all dots on”. The user can also control temperature, supply voltage and bias.

Nutrition
voltage 2.7…3.3 V
current up to 320 µA
Clock frequency up to 4 MHz
Reset time at least 100 ns

Display structure

The display is a matrix of LCD elements and a PCD8544 microcircuit for their control, located in a housing mounted on the board. It also houses four screen backlight LEDs. Information about the state of the display points is stored in the RAM of the PCD8544 controller; each point corresponds to one bit of memory. There is also a built-in address counter, which automatically increases when the next byte of information is written to memory.

Display control

Carried out via the SPI interface, the display is a slave device. However, instead of the usual four control lines, there are only three. These are the CLK clock, SCE chip select, and MOSI input data lines. There is no MISO output line. This leads to the need to use special management methods, more on this below. The interface operates in SPI-0 or SPI-3 modes. The Nokia 5110 also has an additional Information/Command control line - D/C̅. Each byte sent to the display can be interpreted as a command or an information byte, depending on the level on the D/C̅ line.
Information transfer is unidirectional, and data cannot be read from memory and display registers. Therefore, the program must provide the ability to control display states. However, there is one more feature that complicates management. This feature is related to the organization of memory.

The memory consists of six banks, each of which contains 84 cells with a capacity of 1 byte.

Addressing each indicator pixel. In total we have 84x48 pixels, organized into 6 horizontal banks (zero to five) and 84 columns.

Each bank contains 8 vertically arranged pixels, which in the sum of six banks give 48 lines. The figure shows how a given pixel will be displayed from RAM on the display; each line in the figure represents one bank.
Information is written to memory byte-by-byte, not bit-by-bit, and there is no way to control each point, but only groups of eight points. This, combined with the fact that information from the Nokia 5110 LCD memory cannot be read, means that before sending it is necessary to remember which data is stored in which cell. Otherwise, information may be lost when new data is sent to the display. This feature is illustrated by a picture showing the replacement of a symbol. When writing a control program, it is necessary to provide for the possibility of storing data.

Replacing the symbol L with the symbol A.

The display has a size of 84x48 pixels. Information is output in vertical blocks 8 pixels high, the values ​​of which are determined by the bit values ​​in the output byte. The least significant bit encodes the top pixel.
Looking ahead to the descriptions of the commands, let's say. The commands 1xxxxxxx and 01000yyy define the cursor coordinates - the line and position at which the next 8 bits of data will be displayed. After the byte is output, the cursor is automatically moved to the adjacent position.
If the horizontal addressing mode V=0 is selected with command 00100PDVH, the cursor moves to the right and the next data byte will be displayed at the adjacent position to the right. When the right edge of the screen is reached, the cursor moves to the beginning of the next line. If vertical addressing V=1 is selected, then the cursor moves down to the next line, and after the last line the cursor moves one horizontal position to the right and is placed on the top line.
As an intermediate memory, you can use the memory of the control controller, which will store a copy of the data in the display. Before sending, it is necessary to adjust the data, depending on what information is stored in intermediate memory.

Nokia 5110 control commands

The display is controlled by sending a command word via the SPI interface. Word size is 1 byte. Control commands are divided into 3 categories.

Supreme functions of management

Set function type - indicates what type of functions the module will work with, basic or advanced.
Set power mode - turns the power on or off.
Set addressing mode - determines the type of memory addressing: vertical or horizontal. In the first case, after writing a byte of data, the Y-address counter will be increased, that is, the recording will proceed in columns. In the second - the X-address counter, the recording will go line by line.
Functions are transferred to Nokia 5110 LCD when the D/C̅ line is low. They are defined by a single command word. This word must be sent to the display at the start of operation. Format:

0 0 1 0 0 PD V H

The PD bit determines the power mode, set to PD means power-down mode.
Bit V addressing mode: 1 - vertical, 0 - horizontal.
Bit H is the type of functions that will be used for further work: 0 - normal, 1 - extended.
As you can see, it is necessary to remember the current state of the display so that when setting a new parameter value you do not lose information about the values ​​of others. The 00100PDVH command is present in both command sets.

Main functions

Set display mode to 00001D0E. Defines the display mode: blank screen, all dots on, normal display, inverse display. E - image inversion sign, D - image output. If D=0, then the screen is either completely clear E=0 or completely black E=1.
Set X-address command 1xxxxxxx, or 0x80 + x selection of a horizontal position in the current line where the image will be displayed. Where x=0 is the leftmost position, 83 is the rightmost.
SetY-address command 01000yyy sets the Y-address of the cell where the next byte will be written. Command, or 0x40+y select the line (page) number on which the image is displayed. Y=0 is the top line, 5 is the bottom line. The line is 8 points high.

Advanced Features

The extended command set is selected after command 00100PDV1 is sent.
Set the temperature mode. Command 000001tt, or 0x04 + t select one of four temperature correction modes. Depending on the mode, the display voltage will change differently as the temperature changes.
Set the bias voltage of the LCD display elements. Command 00010bbb, or 0x10 + b selects one of eight modes for calculating level offsets for LCD control. For regular Nokia displays, the recommended mode is 0001011, or 0x13.
Set the supply voltage for the LCD display elements. Command 1vvvvvvv, or 0x80 + v select the voltage on the boost voltage generator for the LCD. When v=0 the generator is switched off. The output voltage is calculated using the formula VLCD = 3.06 V + v * 0.06 V. Depending on the choice of voltage correction method, this value changes depending on the temperature. To avoid damage to the display at low temperatures, it is recommended that this value be less than 8.5 V, i.e. v<=90. Для обычных дисплеев Nokia это нормальное рабочее значение этого параметра примерно равно 56, т. е. команда принимает вид 10111000, или 0xB8.
Basic and advanced functions are easier to work with because each has its own command word.
It must be remembered that in order to work with a certain type of function, you must set the display to work with these functions. Otherwise, sending the command word will lead to incorrect execution of this command. More details about control commands can be found in the documentation on page 11.

Initializing the display

Must be executed within 30 ms after power appears in the following sequence:
reset by driving the corresponding input low for 100 ns or more,
turn on the display and select an extended set of commands by sending 0x21,
send voltage offset command 0x13,
set temperature correction with command 0x04,
turn on the high voltage generator to the level of 6.42 V using the 0xB8 command,
return to the standard command set by sending 0x20,
enable graphics mode with the command 0x0C.
After these steps, Nokia 5110 LCD is ready for use.

Connecting the Nokia 5110 LCD module

The output of signals to the module contacts is shown in the image at the top of the page. There may also be a different arrangement of contacts shown in the figure.

One of the contact arrangement options.

Module signals and lines

VCC Power 3.3V
GND Common wire
SCE Enable, active low
Reset Reset, active low
D/C̅ Data/command: 0 - data, 1 - command
SDIN Interface input
SCLC Clock signal
LED Backlight. For modules on the red board, connect to common, for blue modules, connect to power. Use a 330 Ohm resistor in the backlight circuit. Some modifications already have a resistor installed, others do not. To determine the presence of a resistor and select the optimal backlight mode, you should monitor the module current and the backlight current. It should not exceed 20 mA.

If no other devices are connected to the SPI interface of the microcontroller, then to save contacts of the main control module of the device and reduce the number of communication lines, the SCE active device selection pin should be connected to the GND pin on the module board. But there is a drawback. If the Nokia controller has lost synchronization with the MK, it is now impossible to detect.
A more reliable connection should be done this way. Pull this line to a high level with a 100-500 kOhm resistor to prevent interference from affecting the controller while the MK is in the reset state.
When working with AVR microcontrollers, it is convenient to use the USART interface in SPI master mode. SPI-3 mode (CPHA=1, CPOL=1). This means that while there is no exchange, the SCLK line is high, and the controller reads data from the SDIN line on a rising edge on the SCLK line for 100 ns. In this case, they must be set at least 100 ns before the rising edge. Transmission is carried out in 8 bits, most significant first.
The level on the D/C̅ line determines how to interpret the received data. A high level means that the transmitted data should be displayed, a low level means a command is transmitted. The controller reads the value on this line along with the last (lowest) bit of each data byte transferred. This can be difficult when using asynchronous hardware transfer. You must wait for the previous byte to complete transmission before setting the level.

Connecting Nokia 5110 LCD module and Arduino UNO.

The input signals of the module must correspond to the logical levels of the circuit powered by a voltage of 3.3 V. When working with a microcontroller with a 5 V power supply, level matching circuits must be used.

Graphic arts

At the beginning of preparing a graphic image, you should prepare a black and white image in *.bmp format with a resolution of 84x48 pixels in any graphics editor. We prepared such a picture in Paint, here it is:

The image file name must be saved in Latin letters. Using the program