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?
-
Have you tried just I2C.readfrom(addr, nbytes)
-
@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' -
You spelled it wrong
-
-
@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
bytesobject and you are trying to send an integer. Could you try with:i2c.writeto_mem(0x76, 0xF4, bytes([0x3F]))Cheers,
Daniel -
@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 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 -
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])
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login