I2C接口的OLED在树莓派3上的应用

I2C接口的OLED在树莓派3上的应用

首先感谢Ki1381(https://blog.csdn.net/ki1381)的博客支持,最新的驱动让我的12864显示屏出现了helloworld。基本过程有以下几步:
- 正确接线
- 下载安装支持Python库
- 检测设备
- 运行示例程序


Markdown及扩展

I2C总线需要详细了解原理,可以同时接入多个设备 —— [ i2c总线 ]

接线

Markdown Extra 对应即可:

pi 3 12864屏幕
1 Vcc
3 SDA
5 SCL
6 GND

下载支持库

先下载工具
记得在raspi-config里启用I2C。

然后下载一些必备工具:

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

检测设备
运行一下 sudo i2cdetect -y 1
正常情况下默认在0x3C处有标注,这就说明接线成功了。
下载支持库

sudo apt-get install libfreetype6-dev libjpeg-dev build-essential 
sudo apt-get install python3-dev python3-pip  
sudo -H pip3 install --upgrade luma.oled

测试示例


from luma.core.interface.serial import i2c, spi  
from luma.core.render import canvas  
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106  

serial = i2c(port=1, address=0x3C)  
device = sh1106(serial)  

with canvas(device) as draw:  
    #draw.rectangle(device.bounding_box, outline="white", fill="black")  
    draw.text((30, 40), "Hello World", fill="white") 

猜你喜欢

转载自blog.csdn.net/qq_27663847/article/details/79935531