我在广告1115(在树莓派下)遇到了麻烦。这是我的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
因此,我想我的答案是“bus.read_byte”(这里是17),I2C模块没问题。特别是,i2cdetec -y 1可以工作(输出是地址49。
如果我使用ads1115的另一个地址(在adafruit的例子中有另一个连线),问题仍然存在。
更新:模块ADS1115与Arduino(和Adafruit librairy)配合使用,并提供良好的测量结果。
你有个主意吗?
这是我在Windows 10 iot和raspberry pi上阅读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);