Index>Robot Kit>RaspArm-S Kit for RPi>Lesson 5 Displaying Text on the OLED Screen

Lesson 5 Displaying Text on the OLED Screen

3094

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

5.1 Components used in this course


image.png


5.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 Alter 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.


5.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


5.4 How to display text on the OLED screen 

5.4.1Run theprogram of this course

1. Open the terminal software MobaXterm:


image.png


2. Log in to your Raspberry Pi (the way to log in to Raspberry Pi has been introduced in Lesson 1):

image.png


3. The relevant code programs of the RaspArm-S robot are stored in the adeept_rasparms folder, which has been explained in "2.1 Downloading the code program for controlling the robot" in Lesson 2. First, you need to enter a command with the command window of the Raspberry Pi to enter the folder where the course code is stored: CourseCode, this folder stores the sample code program for each course, enter the following command:

cd  adeept_rasparms/CourseCode

image.png


4. Enter the command to display the contents of the current directory:

ls

image.png


5.  The 01OLEDtext folder contains the sample code of this lesson. Enter the command to enter this folder:

cd  01OLEDtext

image.png


6. Enter the command to display the contents of the current directory:

ls

image.png


7.OLEDtext.py is a python program. When using the OLED Screen module, we need to install the Python dependent library needed to control the OLED screen, called luma.oled library, and enter the following commands in the console of the command window:

sudo pip3 install luma.oled

image.png


If a download timeout warning appears, you can download the luma.oled library by adding a image source, and enter the following command:

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

image.png


8.OLEDtext.py is a python program.You can run this program on the Raspberry Pi by directly typing the following commands:

sudo  python3  OLEDtext.py

image.png


9. After successfully running the program, you will observe that "ROBOT" will be displayed on the OLED screen.


10. If you want to terminate the running program, you can press the shortcut key Ctrl+C on the keyboard.


5.4.2 The main code program of this lesson

After the above hands-on practice, you already know how to use and run our course sample code program. You must be curious about how our code program is programmed to display text on OLED screen on the Raspberry Pi. Let’s get to know the main code program.Here we use Subline IDE to view and edit the code program of this lesson. For the specific method, please see the content of Lesson 2: "2.4 Editing the code program in Raspberry Pi". In the file manager of the MobaXterm terminal, find adeept_rasparms/CourseCode /01OLEDtext, open the code of this lesson: OLEDtext.py.

1. First import the library used to control the OLED screen.

image.png 

2. Then import the library used to control the delay time.

image.png 


3. Instantiate the object used to control the OLED.

image.png 


4. Display the text "ROBOT" at the position (0, 20) on the OLED screen.

image.png