Python访问Jetson Nano或树莓派的IIC及smbus总线时,需要开启 I2C,并安装相关库,具体命令可查看txt文件。
python_Jetson_Nano_IIC_smbus.txt
环境说明:Linux,python,Jetson Nano,IIC传感器
I2C简介:
I2C 有两个关键信号线:SCL 为时钟信号,SDA 为双向数据传输。 每个 I2C 器件采用独特的 7 位地址,这意味着你可以有超过 120 个独特的 I2C 器件共享总线。
运行错误及问题:
1.run temp sensor or bmp180 ,提示import Error: No module named smbus
2.使用Nano 读取bmp180 temprature,出现下面错误
(chip_id, chip_version) = bus.read_i2c_block_data(addr, REG_ID, 2)
IOError: [Errno 121] Remote I/O error
解决办法:
一、开启 I2C
因为默认 I2C 是关闭,需要通过下列步骤开启 I2C
1)在 /etc/modprobe.d/blacklist.conf 中,注释掉 blacklist i2c_i801
# blacklist i2c_i801
2)在 /etc/modules 的最后面追加
i2c-dev
3)sudo reboot 重启
二、安装相关库,total 3 lib
sudo apt-get install python-smbus
sudo apt-get install libi2c-dev
sudo apt-get install i2c-tools
三、查看设备
wheeltec@wheeltec:~/sensor ls /dev/*i2c*
wheeltec@wheeltec:~/sensor i2cdetect -l
wheeltec@wheeltec:~ i2cdetect -y -r 1
比如:diplay 0x77 ,means DEVICE = 0x77
执行上面命令,可以看到总线上挂的设备,并列出设备的地址。
参考:
https://zhuanlan.zhihu.com/p/22609190?utm_id=0
https://www.freesion.com/article/4382191724/
https://blog.csdn.net/finedayforu/article/details/116590855