树莓派学习笔记——IIC驱动OLED

树莓派外引IO中有IIC接口,但需要手动开启 ,可使用python的smbus库进行调用:

sudo apt-get install -y python3-smbus //安装Python3的SUMBS库 

sudo apt-get install -y i2c-tools    //安装IIC工具

sudo raspi-config                    //打开树莓派设备管理IIC默认关闭,需要将其打开 

 

 

git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git //安装OLED的python库
cd Adafruit_Python_SSD1306/examples/            //打开OLED的python库文件
sudo python3 setup.py install    //如果使用 Python2 ,则使用sudo python2 setup.py install命令
python3 stats.py                 //运行程序stats.py

程序中导入smbus库:

#导入方法一:
import smbus
 
#导入方法二:
from smbus import SMBus
 
#创建一个smbus实例
b = smbus.SMBus(1)
 
b = SMBus(1)    # 0 代表 /dev/i2c-0, 1 代表 /dev/i2c-1
                #具体看使用的树莓派那个I2C来决定。
 
#使用i2c函数
b.read_byte_data(0x2f,0x58)

版权声明:本文为m0_53222561原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。