hamishcunningham / fishy-wifi

Scripts, notes and the odd subaquatic gizmo for the ESP8266 and what-have-you.
GNU Affero General Public License v3.0
25 stars 13 forks source link

Waterelf32 Wire.begin not using correct pins #17

Closed cgmcintyr closed 6 years ago

cgmcintyr commented 6 years ago

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: https://github.com/hamishcunningham/fishy-wifi/blob/c7e3cb415f0ee15786c1d1fe610efdc433e5f889/ardesp/waterelf32/waterelf32.ino#L832-L835

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 commented 6 years ago

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

layerzerolabs commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

hamishcunningham commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.