Index>Robot Kit>Alter All in One Kit for RPi>Lesson 3 Displaying Text on the OLED Screen
No related product information!

Lesson 3 Displaying Text on the OLED Screen

1069

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

3.1 Components used in this course


image.png


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


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


3.4 How to display text on the OLED screen 

3.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. Enter the Course Code folder, this folder stores the sample code program to control the robot, enter the following command:

cd adeept_alter/02CourseCode/01ComponentCode

image.png


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

ls

image.png


5.  The 02OLEDtext folder stores the sample code of this course. Enter the command to enter this folder:

cd  02OLEDtext

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


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.


3.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.We use sublime IDE to view and edit the code program of this lesson. Please refer to the content of lesson 2 for specific methods.

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