OSError: I2C bus error
-
i2c bus: doesn't work for me.
This is what I did:
from machine import I2C
i2c = I2C(0, I2C.MASTER, baudrate=100000)
i2c.scan()[72] <- REPL reply
So the system recognize the slave at address 0x72 (temp. sensor TC74)
normally on I would request 1 bytes from slave device by writing to the slave to initiate the read sequence.i2c.writeto(0x72, b'1')
OSError: I2C bus errorOn the scope with i2c protocol analyser it puts the address byte on the bus but no ACK follows (weird). Because the scan works okay it seems to be wrong with the write functions. Or do I mis something?!?
Same slave (working) on a arduino, the code would be:
Wire.requestFrom(72, 1);
while(Wire.available()) temperatuur = Wire.read();Please help! Any suggestions?
-
All are integers.
#working code for TC74 i2c temp. sensor
from machine import I2C
i2c = I2C(0, I2C.MASTER, baudrate=400000)
t = i2c.readfrom_mem(72, 0, 1)
print('temperature room: ', t[0])
-
@Baruch1966 The i2c.scan() is returning a integer. You need a hex value for write.
I tried this:
from machine import I2C
i2c = I2C(0)
i2c = I2C(0, I2C.MASTER)
i2c.init(I2C.MASTER, baudrate=10000)
i2c.scan()
[68] <- REPLY
i2c.writeto(0x44 , '1')
1 <- REPLY
-
@rskoniec said in OSError: I2C bus error:
This error occurs because the function expects a bytes object and you are trying to send an integer. Could you try with:
i2c.writeto_mem(0x76, 0xF4, bytes([0x3F]))Cheers,
DanielSolved
i2c.readfrom_mem(72, 0, 1)
b'\x19'Did the trick. Manual sucks! Cost me hours of my life!!!
-
@Baruch1966 I think this @daniel's post should help (from thread https://forum.pycom.io/topic/265/wipy-2-0-and-bme280-sensor):
This error occurs because the function expects a
bytes
object and you are trying to send an integer. Could you try with:i2c.writeto_mem(0x76, 0xF4, bytes([0x3F]))
Cheers,
Daniel
-
-
You spelled it wrong
-
@littlebat said in OSError: I2C bus error:
Have you tried just I2C.readfrom(addr, nbytes)
i2c.readform(0x72, b'1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'I2C' object has no attribute 'readform'i2c.readform(0x72, 0x01)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'I2C' object has no attribute 'readform'i2c.readform(0x72, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'I2C' object has no attribute 'readform'
-
Have you tried just I2C.readfrom(addr, nbytes)