I2C isn't working anymore

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

I2C isn't working anymore

Post by ioukos » Wed Mar 29, 2017 10:45 am

Hello,

I have an issue with I2C devices. It's not working anymore. I've tried with BME280; DS3131 and OLED screen.

Here is my code (juste for the BME280):
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
bme = bme280.BME280(i2c=i2c)
here is the answer from the console :
>>> bme = bme280.BME280(i2c=i2c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bme280.py", line 74, in __init__
OSError: [Errno 19] ENODEV
(I use https://github.com/catdog2/mpy_bme280_esp8266 bme280 library)

Is there something wrong with my code ? Moreover it worked find until last sunday. Could it be a hardware issue ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C isn't working anymore

Post by Roberthh » Wed Mar 29, 2017 11:05 am

a) did you change the firmware version?
b) is anything else connected to the I2C bus?
c) are pullup-resistors present on SCL and SDA?
d) what is the result of i2c.scan()

dbenhart
Posts: 4
Joined: Fri May 26, 2017 3:47 pm

Re: I2C isn't working anymore

Post by dbenhart » Wed May 31, 2017 9:49 pm

I've found this same issue to be happening on my board as well. The board is an Adafruit Huzzah Feather.

Firmware version 1.9.0., I haven't tried any other firmware versions.
Nothing else is connected to the bus, but I have confirmed that other i2c devices work with this board.
No pull-up/down resistors connected (as mentioned, the bus works for other devices)
i2c.scan() returns [119] which is the correct address per the datasheet and is what the driver is using

in addition, I ran through some of the steps manually, e.g. setting up the device and entering the readfrom_mem command. Doing this, I can successfully read the contents of that register, so I know that the device is capable of communicating.

If anyone has successfully used this driver, please let me know what changes needed to be made.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I2C isn't working anymore

Post by pythoncoder » Thu Jun 01, 2017 6:48 am

This may or may not be relevant to the problem but pullup resistors are essential for reliable operation. The Huzzah does not provide them on pins 4 and 5. Some breakout boards provide them, but not all. Supplying a pair of resistors to 3.3V - in the range of 1-10K - will work whether or not the breakout has them and is worthwhile.
Peter Hinch
Index to my micropython libraries.

dbenhart
Posts: 4
Joined: Fri May 26, 2017 3:47 pm

Re: I2C isn't working anymore

Post by dbenhart » Thu Jun 01, 2017 2:35 pm

I checked the schematic for the BME280 breakout board and it looks like it has pull-up resistors built in.

https://cdn-learn.adafruit.com/assets/a ... 1437773082

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C isn't working anymore

Post by Roberthh » Thu Jun 01, 2017 5:21 pm

I just tested a BME085 sensor with the BME280 lib, and even if it delivers non-sense values, it communicates. The mp version is 1.9-7.
Using the proper lib the data returned is fine. So for me, the BME280 lib and V.19 of MicroPython are OK.
Can you try to use other GPIO's for SCL and SDA?

dbenhart
Posts: 4
Joined: Fri May 26, 2017 3:47 pm

Re: I2C isn't working anymore

Post by dbenhart » Thu Jun 01, 2017 7:05 pm

Before I go any further, thank you both for taking the time to look into this.

I downloaded one of the daily builds, esp8266-20170601-v1.9-7-gb53a6351.bin, and was able to flash it without issue. I tried the default pins, 5/4 as well as changing to 16/0; so far, no luck. I get the same error.

Just to confirm, I am using the following library:

https://github.com/catdog2/mpy_bme280_esp8266

There is another version of this library which seems to be older and have additional functionality which I don't need right now:

https://bitbucket.org/oscarBravo/wipy_bme280/src

I also tried this library with the pins 5/4 configuration, but that yielded a different error:

Code: Select all

bme = bme280.BME280(i2c=i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bme280.py", line 185, in __init__
  File "bme280.py", line 191, in _load_calibration
  File "bme280.py", line 151, in readU16LE
  File "bme280.py", line 134, in readU16
TypeError: function missing 1 required positional arguments
I also flashed the board using the Arduino IDE and used the official library from Adafruit; this configuration worked perfectly and printed reasonable values from temp, humidity, pressure, and altitude. This being the case, I know that the BME280 board is working and can communicate via I2C with this Feather Huzzah board.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C isn't working anymore

Post by Roberthh » Thu Jun 01, 2017 7:31 pm

I used this lib, which I thought to be the same.
bme280.zip
(2.82 KiB) Downloaded 387 times
Do you have an .mpy file in the file system with the same name? That would take precedence.

dbenhart
Posts: 4
Joined: Fri May 26, 2017 3:47 pm

Re: I2C isn't working anymore

Post by dbenhart » Thu Jun 01, 2017 7:54 pm

Problem solved, sort of. I was using 0x76 as the address for the most recent tests. I switched it over to 0x77 and everything works. I reverted back to the stable firmware build and it works there too. I was using the correct address in earlier tests but changed it over to 0x76 to see if that did anything, apparently I forgot to change it back. Either way, it seems to be working, so I'm not going to dig into it any further.

On a side note, I'm getting odd readings for temp. When I put my finger on the sensor, the humidity goes up as expected, but the temp barely moves. Is this something you've experienced?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C isn't working anymore

Post by Roberthh » Thu Jun 01, 2017 8:03 pm

I would expect the opposite: when you put the finger on the sensor, the temperature should go up, but the humidity should not change or even slightly drop. If you breath at the sensor, the humidity should go up, at more or less stable temperature. And you may breath at the sensor when putting the finger on it. But that all depends on your finger's heat etc.
Anyhow, my experience with the humidity sensor is, that it need some time to settle.

Post Reply