Raspberry Pi i2c读/写错误 [英] Raspberry Pi i2c Read/Write Error
问题描述
像许多人一样,我有一段时间的Pi,但从未真正做过任何事.我终于可以将MPU6050 IMU连接起来玩了.它使用i2c进行通信,因此我按照Adafruit的指南进行操作,有关此处显示的启用i2c Adafruit i2c .
Like many people, I've had a Pi for a while but never really done anything with it. I've finally got round to hooking up an MPU6050 IMU to play around with. It uses i2c for communication so I followed the guide by Adafruit regarding enabling i2c shown here Adafruit i2c.
然后我将MPU6050连接到i2c总线,并使用i2cdetect -y 1
能够在0x68看到设备.
I then hooked up the MPU6050 to the i2c bus, and using i2cdetect -y 1
I was able to see a device at 0x68.
但是,当尝试从设备进行读取或写入时,出现了权限被拒绝的错误,因此我按照这篇文章来解决该问题
However, when trying to read or write from the device I got a permission denied error, so I followed this post to solve that problem /dev/i2c-x permission. It told me to modify /lib/udev/rules.d/60-i2c-tools.rules with
KERNEL=="i2c-0" , GROUP="i2c", MODE="0660"
KERNEL=="i2c-[1-9]*", GROUP="i2c", MODE="0666"
这可行,但是当实际上尝试使用C ++进行读取或写入时,出现输入/输出错误".同样,在Python中使用smbus会得到[Errno 5] Input/output error
连接到Arduino后,我可以使该设备正常工作.
This worked, but then when actually trying to read or write using C++, I get "Input/output error". Similarly, using smbus in Python I get [Errno 5] Input/output error
When connected to an Arduino I can get this device to work perfectly.
我已经用尽了所有可以找到的论坛帖子.希望我刚刚做了一些愚蠢的事情.有人有任何想法吗?
运行Raspbian的原始模型B RPi,如果有帮助的话.
Original model B RPi running Raspbian, if that's of any help.
欢呼
推荐答案
在通常情况下,您实际上不需要更改/lib/udev/rules.d/60-i2c-tools.rules 文件,因此建议您重新安装raspbian.
In normal cases you don't really need to change the /lib/udev/rules.d/60-i2c-tools.rules file, so I would recommend resinstalling raspbian.
将MPU6050连接到正确的引脚:
Connect the MPU6050 to the correct pins:
然后下载官方的Adafruit库:
Then download an official Adafruit library:
- C++
- Python
检查Raspberry Pi的I2C是否已通过$ sudo raspi-config
启用,并确保I2C地址正确,除了使用$ i2cdetect -y 1
进行检查外,如下所示:
Check if the Raspberry Pi's I2C is enabled with $ sudo raspi-config
and make sure the I2C address is correct, besides checking it with $ i2cdetect -y 1
, like this:
try:
bus = Adafruit_I2C(address=0)
print("Default I2C bus is accessible")
except:
print("Error accessing default I2C bus")
mcp = None
for i in range(0x00, 0x28):
try:
mcp = Adafruit_MCP230XX(address=i, num_gpios=16)
break
except:
pass
这篇关于Raspberry Pi i2c读/写错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!