树莓派+SSD1306屏幕

启用树莓派的I2C功能

sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
sudo raspi-config

Interfacing Options–>I2C–>enable


安装库文件

sudo python -m pip install –upgrade pip setuptools wheel

PIL 库

sudo apt-get install python-pil python3-pil

Adafruit-SSD1306 库

git clone https://github.com/adafruit/Adafruit\_Python\_SSD1306.git


连接屏幕

屏幕 GND 接树莓派 GND 屏幕 VCC 接树莓派 3V3 屏幕 SDA 接树莓派 SDA 屏幕 SCL 接树莓派 SCL


检测是否识别到 I2C 设备

sudo i2cdetect -y 1

运行

在之前克隆的代码中包含了可以直接运行的示例源码

sudo nano ~/Adafruit_Python_SSD1306/examples/stats.py

修改屏幕类型

# 128x32 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

128x64 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

Note you can change the I2C address by passing an i2c_address parameter like:

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)

运行

sudo python ~/Adafruit_Python_SSD1306/examples/stats.py

sudo python ~/Adafruit_Python_SSD1306/examples/image.py