1. Module Source
Purchase Link:
Baidu Netdisk Resource Download:
https://pan.baidu.com/s/13AM3v12Xt1yOui30IHUl5w?pwd=52ku
Password: 52ku
2. Specifications
The SSD1315 and SSD1306 drivers are largely the same, except for the scrolling feature.
Operating Voltage:3.3V
Operating Current:9MA
Module Size:27.3 x 27.8 MM
Pixel Size:128 x 64
Driver Chip:SSD1315
Communication Protocol:IIC
Pin Count:4 Pin (2.54mm pitch header)
3. Module Principle
The SSD1315 is an OLED driver chip that communicates via the I2C protocol. I2C (Inter-Integrated Circuit) is a multi-master, serial computer bus that allows multiple "devices" to connect to the same bus for communication. The I2C communication principle of the SSD1315 is based on several key points:
- Communication Address: The SSD1315 has two I2C communication addresses, 0x78 and 0x7A, which can be selected externally.
- Data and Clock Lines: I2C communication uses two lines: the Data Line (SDA) and the Clock Line (SCL). The data line is responsible for transmitting data, and the clock line provides synchronization for the data.
- Start and Stop Conditions: I2C communication uses specific start and stop conditions to mark the beginning and end of communication. The start condition is when the SDA line transitions from high to low while SCL is high. The stop condition is when the SDA line transitions from low to high while SCL is high.
- Acknowledge Signal: After sending data, the receiving device needs to send an acknowledge (ACK) signal to confirm successful data reception.
- Write Instructions and Data: The SSD1315 distinguishes between instructions and data in I2C communication. Typically, specific instructions are used to set display parameters such as brightness, contrast, page address, etc.
- Simulated I2C Communication: In some microcontrollers, if hardware I2C is not supported, I2C communication can be simulated using software, where high and low IO pins are manipulated to emulate the I2C protocol.
- Initialization Process: The initialization of the OLED screen includes sending a series of instructions to configure the screen, such as turning the screen off, setting the starting column address, setting the addressing mode, display start line, contrast, display inversion, multiplex ratio, current, screen offset, clock frequency, and other settings.
- Data Transmission: In I2C communication, data is typically sent in 8-bit byte form. Before sending data, the target device's address must be set, followed by the specific data or instructions.
The I2C module principle of the SSD1315 follows the standard I2C communication protocol, enabling communication and control of the OLED screen with a microcontroller through either software or hardware support.
4. Porting Project
4.1 Wiring Method
The wiring diagram is shown below:
4.2 Porting Steps
1. Install Driver
Before starting step 1, refer to the article "《Adapting Adafruit Blinka for LCSC Taishan-RK3566-Linux Dev Board, Easily Access CircuitPython Sensor Libraries》for adapting Adafruit Blinka
library for the LCSC Taishan-RK3566-Linux Dev Board.
The SSD1306 driver library provided by Adafruit is Adafruit_CircuitPython_SSD1306
. Install it on the Raspberry Pi system (Taishan-Pai) via the following command:
sudo pip3 install adafruit-circuitpython-ssd1306
2. Driver Testing
After installation, test whether the screen lights up properly. Using Thonny with remote Python 3 (SSH), write SSD1306 test code. Below is an example code:
import time
from board import *
import busio
import adafruit_ssd1306
#Define I2C
i2c = busio.I2C(I2C2_SCL, I2C2_SDA)
#Initialize the display module
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
#Turn on the screen
disp.fill(1)
disp.show()
2
3
4
5
6
7
8
9
10
11
12
13
14
Note: Refer to the previous GPIO library for I2C pin connections: I2C2_SCL, I2C2_SDA.
3. Display LCSC Taishan-RK3566-Linux Dev Board Information
The official repository of Adafruit_CircuitPython_SSD1306
provides many examples, which all run properly after testing.
GitHub link to Adafruit_CircuitPython_SSD1306 repository:
https://github.com/adafruit/Adafruit_CircuitPython_SSD1306
Let's test the display of CPU, memory, and other information using the ssd1306_stats.py
example. Below is the example code:
import time
import subprocess
from board import *
import busio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
i2c = busio.I2C(I2C2_SCL, I2C2_SDA)
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
#Clear the screen
disp.fill(0)
disp.show()
width = disp.width
height = disp.height
#Create monochrome bitmap
image = Image.new("1", (width, height))
#Create drawing object
draw = ImageDraw.Draw(image)
#Draw a black rectangle to clear the screen
draw.rectangle((0, 0, width, height), outline=0, fill=0)
#Define constants
padding = -2
top = padding
bottom = height - padding
x = 0
#Define font
font = ImageFont.load_default()
while True:
draw.rectangle((0, 0, width, height), outline=0, fill=0)
# Use commands to display IP, CPU, memory, storage, etc.
cmd = "hostname -I | cut -d' ' -f1"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = 'cut -f 1 -d " " /proc/loadavg'
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\''
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
draw.text((x, top + 0), "IP: " + IP, font=font, fill=255)
draw.text((x, top + 8), "CPU: " + CPU, font=font, fill=255)
draw.text((x, top + 16), MemUsage, font=font, fill=255)
draw.text((x, top + 25), Disk, font=font, fill=255)
# Display the information
disp.image(image)
disp.show()
time.sleep(0.1)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
5. Porting Testing
Successfully lighting up the screen:
Experiment 2 display effect: