Rich's Wordpress

又一个WordPress站点

OLED short for Organic Light-Emitting Diode – a technology that uses LEDs in which the light is produced by organic molecules. It is a solid-state device consisting of a thin, carbon-based semiconductor layer that emits light when electricity is applied by adjacent electrodes. The characteristic of OLED is that it can emit light by itself, so the visibility and brightness are very high, there is also a low voltage requirement and high efficiency of power saving, coupled with fast response, lightweight, thin thickness, simple construction and low cost.

The OLED used in Raspberry Pi Hat is ssd1306, with 0.9 inch, 128*64 resolution and white text on a black background.

The function of the Pins:

1GNDConnect the ground of the supply to this pin.
2VCCIt is a power supply pin, a supply of 3.3V.
3SCL (Serial Clock line)It is a clock signal, data is sent to other devices as clock ticks occur.
4SDA (Serial Data line)A serial data bus uses voltage to communicate

What is I2C?

I2C is a two-wire protocol for communication between devices. Physically, it consists of two lines: SCL and SDA, which are the clock line and the data line respectively. This means that different devices can communicate with each other through these two lines.

I used the gpiozero library in previous projects, but Raspberry PI has a huge community in the world, and different libraries can be selected to complete tasks on different devices. For OLED device drivers, the library we used is Luma.oled. The Luma.oled library needs to be downloaded into my Raspberry Pi first.

Download Luma.oled Library

Enter the following command on the Raspberry PI terminal and press Enter.

sudo apt install python3-dev python3-pip libfreetype6-dev libjpeg-devbuild-essential libopenjp2-7 libtiff5

After that, continue to enter the following command in the terminal and press Enter

sudo -H pip3 install --upgrade luma.oled

After installing the library, open the Raspberry Pi configuration, and enable the I2C interface.

Common Functions:

luma.oled.device.ssd1306(port,address) #initialize OLED
luma.core.render.canvas(ssd1306) #to draw symbols on the OLED

Code for displaying some words on the OLED:

from luma.core.render import canvas
from luma.oled.device import ssd1306
from time import sleep

device = ssd1306(port = 1, address = 0x3C)

with canvas(device) as draw:
	draw.text((0,0), 'Hello World', fill = "white")
	draw.text((0,10), 'Raspberry Pi', fill = "white")
	draw.text((0,30), '1+1=2', fill = "white")

while True:
	pass

Final Result:

Texts are displayed on the OLED
OLED
Scroll to top