i used to use arduino as a i2c communication device but i'm changing to raspberry and i have a question about how to send and receive data from raspberry to my device
the device in question is a pressure and temperature sensor, the sensor address is 0x78
i need to send 0xAC, wait some time and then request 6 bytes
the arduino code is the following:
Wire.beginTransmission(0x78);
Wire.write(0xAC);
Wire.endTransmission();
delay(50);
Wire.requestFrom(0x78, 6); // request 6 bytes
if (Wire.available() == 6) { // read 6 bytes :status, BridgeDat1, BridgeDat2, BridgeDat3, TempDat1, TempDat2
data[0] = Wire.read(); //status
data[1] = Wire.read(); //BridgeDat1
data[2] = Wire.read(); //BridgeDat2
data[3] = Wire.read(); //BridgeDat3
data[4] = Wire.read(); //TempDat1
data[5] = Wire.read(); //TempDat2
}
my question is, how to do that in python ??
1 Answer 1
Here are some methods using my Python modules.
You can also use the Python smbus module.
import time
import pigpio
pi = pigpio.pi()
h = pi.i2c_open(1, 0x78)
pi.i2c_write_device(h, [0xAC])
time.sleep(0.05)
(b, d) = pi.i2c_read_device(h, 6)
print(d[0], d[1], d[2], d[3], d[4], d[5])
pi.i2c_close(h)
pi.stop()
import time
import rgpio
sbc = rgpio.sbc()
h = sbc.i2c_open(1, 0x78)
sbc.i2c_write_device(h, [0xAC])
time.sleep(0.05)
(b, d) = sbc.i2c_read_device(h, 6)
print(d[0], d[1], d[2], d[3], d[4], d[5])
sbc.i2c_close(h)
sbc.stop()
import time
import lgpio as sbc
h = sbc.i2c_open(1, 0x78)
sbc.i2c_write_device(h, [0xAC])
time.sleep(0.05)
(b, d) = sbc.i2c_read_device(h, 6)
print(d[0], d[1], d[2], d[3], d[4], d[5])
sbc.i2c_close(h)