【问题标题】:I2C error with ADS1115 (read_i2c_block_data)ADS1115 的 I2C 错误 (read_i2c_block_data)
【发布时间】:2018-02-11 18:37:11
【问题描述】:

我在使用 ads1115(在树莓派下)时遇到了问题。 这是我的python代码

import smbus
bus = smbus.SMBus(1)
address = 0x49
print bus.read_byte(address)
print bus.read_i2c_block_data(address, 0x00, 2)

还有以下问题:

17
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    data = bus.read_i2c_block_data(address, 0x00, 2)
IOError: [Errno 121] Remote I/O error

因此,我猜 I2C 模块没问题,而我的答案是“bus.read_byte”(此处为 17)。特别是, i2cdetec -y 1 完全有效(输出是地址 49。

如果我使用 ads1115 的另一个地址(如 adafruit 示例中所说的另一个接线),问题仍然存在。

更新:模块 ADS1115 可与 Arduino(和 Adafruit 库)配合使用并提供良好的测量结果。

你有想法吗?

【问题讨论】:

  • 只是一个疯狂的猜测,但是——您是否尝试过在读取调用之间设置一点延迟?我遇到过这种 RPi 的计时问题,我从来没有真正理解过。无论是什么原因,我都注意到 I2C 操作无法按照 CPU 的速度按顺序执行的情况。
  • 我刚刚使用了 time.sleep(1),没有做任何改动。请注意,ADS1115 模块已通过 Arduino 和 Adafruit 库成功测试
  • 对不起——这只是在黑暗中刺伤。我在 RPi 上做了一些 i2c 编程,但只在 C 中。是否可以深入研究 python smbus 模块并详细了解错误 121 是否来自内核模块,或者是 python 模块对某些条件的解释不明白?

标签: python raspberry-pi i2c adafruit


【解决方案1】:

解决方案: 将 ADDR-Pin (ADS1115) 接地到您的 RaspberryPi 接地(我使用 PIN9)

Details of the Issue:
I had the same issue. But there is much more... 
I noticed when i run the python code, 
then run i2cdetect -y 1, my device changes address it becomes 48, 49, 4a, 4b (random) 

我真的希望这对某些人有所帮助,因为我花了几天时间才知道问题所在。顺便说一句,将所有未使用的通道接地也是一种最佳做法。

【讨论】:

    【解决方案2】:

    这是我在 windows 10 iot 和树莓派上阅读 ads1115 时的示例代码, 我觉得对你有帮助

    var i2CSettings1 = new I2cConnectionSettings(0x48)
                {
                    BusSpeed = I2cBusSpeed.FastMode,
                    SharingMode = I2cSharingMode.Shared
                };
    
    
    
    var i2C1 = I2cDevice.GetDeviceSelector("I2C1");
                    var devices = await DeviceInformation.FindAllAsync(i2C1);
                    var gpio = GpioController.GetDefault();
    

    //这里很重要,先设置i2c设备

     _converter1 = await I2cDevice.FromIdAsync(devices[0].Id, i2CSettings1);
                    _converter1.Write(new byte[] { 0x01, 0xc4, 0x60 });
                    _converter1.Write(new byte[] { 0x02, 0x00, 0x00 }); //rate
                    _converter1.Write(new byte[] { 0x03, 0xff, 0xff });
    

    // 你必须发送这个字节。这必须只发送一次

    // 现在我们正在读取数据,您可以循环读取数据,但最好的方法是使用警报引脚。 ads1115 有一个警报引脚,并在准备好读取时发送和警报,您可以通过此代码通过数字输入触发器读取警报引脚

    _converter1.WriteRead(new byte[] { 0x0 }, bytearray1);
                                if (BitConverter.IsLittleEndian)
                                    Array.Reverse(bytearray1);
                                var value1 = BitConverter.ToInt16(bytearray1, 0);
    

    【讨论】:

      猜你喜欢
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      相关资源
      最近更新 更多