Index>Robot Kit>RaspTank-Pro Smart Robot Car Kit for RPi>Lesson 9 Displaying Text on the OLED Screen

Lesson 9 Displaying Text on the OLED Screen

774

Lesson 9 Displaying Text on the OLED Screen

 

    In this lesson, we will learn how to display text on the OLED screen.

9.1 Components used in this course

 

Components

Quantity

Picture

Raspberry Pi

1

image.png 

Robot HAT

1

image.png 

4 pin wire

1

image.png 

OLED screen

1

image.png 

 

9.2 Introduction of OLED Screen

OLED (Organic Light-Emitting Diode), also known as organic electric laser display, organic light emitting semiconductor (Organic Electroluminesence Display, OLED). OLED is a kind of current-type organic light-emitting device, which produces light by the injection and recombination of carriers, and the luminous intensity is proportional to the injected current. The PiCar Pro robot uses an OLED screen to display the  expressions or some parameters of the robot. OLED Screen is a commonly used module on robot products. Due to the black non-luminous feature of OLED Screen, this type of screen has extremely high contrast. Even if the ambient light is strong, you can see the information on the OLED Screen clearly, and the power consumption is relatively low. We only need to connect the power supply and the GPIO port to control it.

If you want to use OLED Screen, you need to use a 4-pin cable with anti-reverse interface to connect the OLED screen to the IIC interface on the Robot HAT.

image.png 

If you do not use Robot HAT driver board to connect with Raspberry Pi driver board, then you need to connect Vin of OLED screen to 5V or 3.3V of Raspberry Pi, and connect GND of OLED screen to GND of Raspberry Pi. Connect SCL of Robot HAT to SCL of OLED, and SCA of Robot HAT to SCA of Raspberry Pi. Please refer to the pin definition diagram of Raspberry Pi for specific pins.

9.3 Wiring diagram (Circuit diagram)

If you want to use the OLED Screen module, you need to connect the IIC interface on the Robot HAT driver board, as shown in the figure below:

image.png

 

9.4 How to display text on the OLED screen 

Run the code

1. Remotely log in to the Raspberry Pi terminal.

image.png

 

2. Enter the command and press Enter to enter the folder where the program is located:

cd adeept_rasptankpro/server/

image.png 

3. View the contents of the current directory file:

ls

image.png 

4. Enter the command and press Enter to run the program:

sudo python3 OLED.py

image.png 

5. After running the program successfully, you will observe that the word "ADEEPT.COM" will be displayed on the OLED screen.

6. When you want to terminate the running program, you can press the shortcut key "Ctrl + C" on the keyboard.

9.5 The main code program of this lesson

For the complete code, please refer to the file OLED.py.

1. from luma.core.interface.serial import i2c  

2. from luma.core.render import canvas  

3. from luma.oled.device import ssd1306  

4. import time  

5.   

6. serial = i2c(port=1, address=0x3C)  

7. device = ssd1306(serial, rotate=0)  

8.   

9. text_1 = 'ADEEPT.COM' # Define the text displayed on the OLED screen, up to 6 lines. 

10. text_2 = 'IP:CONNECTING'  

11. text_3 = '<ARM> OR <PT> MODE'  

12. text_4 = 'MPU6050 DETECTING'  

13. text_5 = 'FUNCTION OFF'  

14. text_6 = 'Message:None'  

 

Import dependent libraries and initialize.

1. def run():  

2.     with canvas(device) as draw:  

3.         draw.text((0, 0), text_1, fill="white")  

4.         draw.text((0, 10), text_2, fill="white")  

5.         draw.text((0, 20), text_3, fill="white")  

6.         draw.text((0, 30), text_4, fill="white")  

7.         draw.text((0, 40), text_5, fill="white")  

8.         draw.text((0, 50), text_6, fill="white")  

9.   

10. if __name__ == '__main__':  

11.     run()  

Light up the OLED screen.