Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waterelf32 Wire.begin not using correct pins #17

Closed
cgmcintyr opened this issue Nov 16, 2017 · 7 comments
Closed

Waterelf32 Wire.begin not using correct pins #17

cgmcintyr opened this issue Nov 16, 2017 · 7 comments

Comments

@cgmcintyr
Copy link
Collaborator

cgmcintyr commented Nov 16, 2017

Problem

The pins for SDA and SCL on the esp32 are 23 and 22. Calling Wire.begin with no args seems to use incorrect pins for the esp32. This results in the TSL2591 never being found in startPeripherals:

Wire.begin();
byte error;
Wire.beginTransmission(0x29);
error = Wire.endTransmission();

Furthermore the Adafruit_TSL2591_Library's function tsl.begin() calls Wire.begin with no args, making it incompatible with the esp32.

Example

Running the example tsl2591.ino results in:

[W][esp32-hal-i2c.c:231] i2cWrite(): Ack Error! Addr: 29
[W][esp32-hal-i2c.c:334] i2cRead(): Ack Error! Addr: 29
No sensor found ... check your wiring?

Possible Fix

Replacing all Wire.begin() with Wire.begin(23, 22) in Adafruit_TSL2591_Library and waterelf32.ino.

After applying fix, tsl2591.ino can be run with the ESP32.

Problems with 'Fix'

After applying the fix the waterelf32.ino reports errors with addresses 20 and 29 being busy.

Example waterelf32 output after applying 'fix'
startPeripherals...
[W][esp32-hal-i2c.c:231] i2cWrite(): Ack Error! Addr: 4e
Soft AP started
AP SSID: WaterElf-BC130CC40A24; IP address(es): local=0.0.0.0; AP=192.168.99.1
[D][WiFiGeneric.cpp:258] _eventCallback(): Event: 13 - AP_STOP
[D][WiFiGeneric.cpp:258] _eventCallback(): Event: 13 - AP_STOP
HTTP server started
doing flow controller and mcp init...
[E][esp32-hal-i2c.c:465] i2cInitFix(): Busy at initialization!
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
Air Temp: 26.20 C, Humidity: 25.90 %RH, 
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
Light: 0 Lux
Water Level: 103 cm, 
Water Level: 74 cm, 
Water Level: 75 cm, 
getAnalog
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 20
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 20
free heap=140748
Air Temp: 26.20 C, Humidity: 25.90 %RH, 
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
Light: 0 Lux
Water Level: 103 cm, 
Water Level: 105 cm, 
Water Level: 70 cm, 
getAnalog
free heap=140748
Air Temp: 26.20 C, Humidity: 25.90 %RH, 
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
Light: 0 Lux
Water Level: 103 cm, 
Water Level: 96 cm, 
Water Level: 122 cm, 
getAnalog
free heap=140752
Air Temp: 26.20 C, Humidity: 25.90 %RH, 
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
Light: 0 Lux
Water Level: 103 cm, 
Water Level: 91 cm, 
Water Level: 100 cm, 
getAnalog
free heap=140752
Air Temp: 26.20 C, Humidity: 25.90 %RH, 
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
[W][esp32-hal-i2c.c:263] i2cRead(): Busy Timeout! Addr: 29
[E][esp32-hal-i2c.c:160] i2cWrite(): Busy Timeout! Addr: 29
Light: 0 Lux
Water Level: 103 cm, 
Water Level: 117 cm, 
Water Level: 78 cm, 
getAnalog
free heap=140396
@cgmcintyr
Copy link
Collaborator Author

Fork of arduino-esp32 that may be related to this issue (I have not looked into it thoroughly).

@layerzerolabs
Copy link
Collaborator

layerzerolabs commented Nov 17, 2017

The SDA and SCL pins are flexible - but seem to be defined correctly for the esp32 Feather we're using in .../Arduino/hardware/espressif/esp32/variants/feather_esp32/pins_arduino.h
static const uint8_t SDA = 23;
static const uint8_t SCL = 22;
However, the I2C subsystem does appear to be a bit of a nightmare due to the differences in the way the AVR chips (original Arduino's) implemented I2C compared to the ESP32 - hence the necessity of the fork you referenced.
Can you check that you had the ESP32 Feather selected in the arduino environment - that may resolve the pin issue. The timing issue looks more fundamental.
I2C is a critical subsystem for many if not most users and the fork is new and under active development (last commit 2 hours ago!) - the author of the fork is requesting testing and feedback - this is a great opportunity for us to contribute to the wider community.

@layerzerolabs
Copy link
Collaborator

Also please either assign yourself to this one - or let me know if you are already too busy and I'll take it - it's important enough that I'd like one of us to look at it asap.

@cgmcintyr
Copy link
Collaborator Author

I would like to prioritise issue #8. A more modular codebase would hopefully make fixing these types of issues easier in the future.

@hamishcunningham
Copy link
Owner

hamishcunningham commented Nov 20, 2017

I agree re. #8 -- I think ideally the config for stuff like this would migrate out into a spiffs file... So could be good to collaborate over #18

@layerzerolabs
Copy link
Collaborator

That makes sense, and we can work around the bug in the I2C system by various means (ugliest would be to reboot when it goes south...)

@layerzerolabs
Copy link
Collaborator

As this issue is more about fundamental bugs in I2C subsystem than wrong pin definitions, I'm going to close it for now, we can open a new one to track the I2C bug if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants