当前位置:网站首页>In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World

In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World

2022-06-25 08:41:00 la_ vie_ est_ belle

Section 5 Use Nokia 5110 LCD display Hello World

5.1 Nokia 5110 Pin Introduction

5.2 Start raspberry pie SPI Interface

5.3  download LCD Driver library

5.4  Write code


Nokia 5110 The LCD screen is a slave type Nokia 5110 From your Nokia phone , Is a monochrome LCD screen , The size is 84*48 Pixels , with 4 star LED The lamp bead is used as a backlight device . It has a small size 、 Cheapness 、 Easy to use, etc . In this section , We will learn how to use Nokia 5110 LCD screen , And use it to display a “Hello World” character string . The materials involved in this project are :

  1. Raspberry pie  * 1
  2. Breadboard * 1
  3. DuPont line ( Male to female ) * 8
  4. Nokia 5510 LCD screen * 1

5.1 Nokia 5110 Pin Introduction

The image below shows Nokia 5110 Each pin of LCD screen , Let's explain the function of each pin and the raspberry pie pin they should be connected to .

  1. RST: Reset pin , We can reset the screen by setting it to a low level .
  2. CE: Chip enable (Chip Enable) Pin . When the electricity is low , Raspberry pie can read and write to this device , When the power is high, the communication with this device will be suspended .
  3. D/C: data (Data) And instructions (Command) Control pin . This pin will tell the display whether it is currently receiving displayable data or commands .
  4. DIN:SPI Serial data pin of the interface .
  5. CLK:SPI Serial clock pin of the interface .
  6. VCC: Power pin , The input voltage range is 3.3v-5v.
  7. BL: Screen backlight pin , This pin illuminates LED Lamp beads .
  8. GND: Ground pin .

In this tutorial ,Nokia 5110 The raspberry pie pins corresponding to each pin are listed below :

Nokia5110 Raspberry pie
RST16 Number GPIO 23
CE24 Number GPIO 8 (CE0)
D/C18 Number GPIO 24
DIN19 Number GPIO 10 (MOSI)
CLK23 Number GPIO 11 (SCLK)
VCC17 Number 3V3 power
BL22 Number GPIO 25
GND20 Number Ground

5.2 Start raspberry pie SPI Interface

Nokia 5110 It's through SPI ( Serial peripheral interface ) Controlled by agreement , So we need to open it on raspberry pie SPI Interface . First enter the following on the command line :

sudo raspi-config

Then choose Advanced Options.

choice Interface Options.

The final choice SPI, Press enter to select ” yes ”.

5.3  download LCD Driver library

Nokia 5110 use PCD8544 Master chip , So we need to use a device that can drive this kind of chip Python library , What I choose here is luma.lcd, This is its Document address .

Enter the following command on the command line to install :

pip3 install luma.lcd -i https://pypi.tuna.tsinghua.edu.cn/simple

5.4  Write code

from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.lcd.device import pcd8544

#  initialization SPI Interface , Pass in D/C and RST Pin number 
serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=23)

#  Initialization equipment , Incoming backlight pin , And set the active low level 
# rotate Parameter is used to rotate the screen , Can be introduced into 0, 1, 2, 3.0 Indicates no rotation ,1 Indicates clockwise rotation 90°, And so on 
device = pcd8544(serial, rotate=0, gpio_LIGHT=25, active_low=False)
device.backlight(True)  #  Turn on the backlight 

#  Draw rectangle and text 
with canvas(device) as draw:
    draw.rectangle(device.bounding_box, outline="white", fill="black")
    draw.text((10, 20), "Hello World", fill="red")


input(" Press any key to exit ")

The above code will draw a rectangular border on the screen , And draw a... In the border “Hello World” Text , The backlight will also turn on . The details of the API The interface description can be viewed through the following links , I will not repeat .Python Usage — Luma.LCD: Display drivers for PCD8544, ST7735, ST7789, HT1621, UC1701X, ST7567, ILI9341, ILI9486, HD44780 2.9.0 documentationhttps://luma-lcd.readthedocs.io/en/latest/python-usage.html#backlight-controlAPI Documentation — Luma.LCD: Display drivers for PCD8544, ST7735, ST7789, HT1621, UC1701X, ST7567, ILI9341, ILI9486, HD44780 2.9.0 documentationhttps://luma-lcd.readthedocs.io/en/latest/api-documentation.html#luma.lcd.device.pcd8544

The running results are as follows ( After the backlight is turned on , Text can't be captured by mobile phone ):

                 

原网站

版权声明
本文为[la_ vie_ est_ belle]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250705306617.html