项目场景:
树莓派小车连接开发
问题描述:
Adafruit_I2C. getPiI2CBusNumber(): Error: File or directory not exist.原因分析:
查看函数:def getPiI2CBusNumber():
# Gets the I2C bus number /dev/i2c#
return 1 if Adafruit_I2C.getPiRevision() > 1 else 0
发现是
/dev/i2c#
这个小妖精
于是
ls /dev/ |grep i2c
果然没有。
接下来debug:
首先查看i2c模块装了没:
lsmod |grep i2c
发现是有的。
经过查询发现是i2c interface没开
解决方案:
sudo raspi-config
找到interface
找到I2C
然后enable就可以了
接下来再康康有没有/dev/i2c
ls /dev |grep i2
发现有的。
再i2cdetect一下
sudo i2cdetect -y 1
然后重新run一下代码,没有报错了。
https://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/