I had one device successfully connected via I2C (pins 4 and 5) and transmitting data. This was the TSL2591 - a digital light sensor.
I found a helpful librarythat got me to set that up and have the values printing to console without any issue.
I then wanted to print the values to an LCD, so I've been using the Grove-LCD and found another library that looked promising to use for that.
However, after connecting the LCD (pins 9 and 10), I'm suddenly running into an error:
"OSError: I2C bus error"
Running i2c.scan() returns [62, 98] (not sure what to make of that honestly, but I saw some people ask about that command elsewhere).
Here's what my main.py looks like:
Code: Select all
th = DHT(Pin('P8', mode=Pin.OPEN_DRAIN),1) # assign th variable to P8 and initialize
tsl = tsl2591.Tsl2591(0) # initialize lux sensor - pin initialized in ts2591.py
i2c = I2C(0, I2C.MASTER) # init i2c for display
d = i2c_lcd.Display(i2c) # initialize display
d.home()
while(1):
d.clear()
time.sleep(2) # sleep for two seconds as per DHT specifications
result = th.read() # read values from DHT
if result.is_valid(): # check if error_code = 0
pycom.rgbled(0x001000) # green - onboard data read confirmation
print('Temperature: {:3.2f}'.format(result.temperature/1.0)) # print temp to console
print('Humidity: {:3.2f}'.format(result.humidity/1.0)) # print rh to console
full, ir = tsl.get_full_luminosity() # read raw values (full spectrum and ir spectrum)
lux = tsl.calculate_lux(full, ir) # convert raw values to lux
print('Lux: ' + str(lux) + ' Lumens')
d.write('Testing')
gc.collect() # memory management