I2C at expansion board
im a bit confused about setting up the I2C Bus.
I can use my sensor at Pin9 and Pin10 without any problems, but i cant manage to set up any other Pins for I2C. I read that this should be working but i couldnt get it done by now. I use FW 1.8.6
The Sensor seems not to exist when i connect it to any other Pins. (i.e. Pins 11 and 12)
Actually i use a class to control my sensor
from machine import I2C
def __init__(self,pinSDA='P9',pinSCL='P10',bd=100000): self.i2c = I2C(2, pins=(pinSDA,pinSCL)) self.i2c.init(I2C.MASTER, baudrate=bd) self.addr = self.i2c.scan()
When i change pinSDA to P19 and pinSCL to P20
i get I2C bus error and a strange behaviour
Thanks in advance for any help on this topic.
@lopyusr I apologize, I misunderstood. I provided too much info on something not your issue.
I'm assuming you are using this driver and example: HERE
And documentation HERE
@ledbelly2142 Im using a DHT12 temperature and humidity sensor. I dont get the point with that battery reading code. I just wonder why it is working on the Pins 9 and 10 but not at any onthers :/ Yfyi i use the Expansion board also. Best regards for your help.
This post is deleted!
@ledbelly2142 It all works fine until i try changing the Pins i cant figure out what im doing wrong at this point :/
Im building a driver file. So im initing the sensor at given ports.
When i try
i2c = I2C(0,mode=I2C.MASTER,pins=('P9','P10'),baudrate=1000000)
i get the following result
i2c = I2C(0,mode=I2C.MASTER,pins=('P20','P19'),baudrate=1000000)
when i try i2c.scan() at this config i dont get a result.
self.i2c = I2C(2, pins=(pinSDA,pinSCL))
Please try the following instread:
self.i2c = I2C(2, mode=I2C.MASTER, pins=(pinSDA,pinSCL),baudrate=bd)
Please also remember that I2C bus nr. 2 is emulated in software while I2C bus 0 and 1 are hardware I2C ports, so you might not get reliable communication at this speed when using bus nr. 2
@lopyusr Try this before you class or def
i2c = I2C(0, I2C.MASTER, baudrate=100000, pins=('P8','P9'))
What are you init -ing?
Or maybe try this
def __init__(self, i2c, address=0x29): # where0x29 is your device I2C address self.i2c = i2c self._address = address