cyberman54 / ESP32-Paxcounter

Wifi & BLE driven passenger flow metering with cheap ESP32 boards
https://cyberman54.github.io/ESP32-Paxcounter/
Other
1.73k stars 405 forks source link

Heltec ESP32 LoRa V2 Display works not properly #262

Closed DasNordlicht closed 5 years ago

DasNordlicht commented 5 years ago

The display stays black, sometimes it works after a few reboots. There seems to be a problem with the I2C bus.

[I][lorawan.cpp:369] lora_stack_init(): Starting LMIC... [W][esp32-hal-i2c.c:1411] i2cCheckLineState(): invalid state sda(4)=0, scl(15)=0 [E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=0, scl=0 [I][main.cpp:337] setup(): Features: LED OTA BLE BTN_PD LORA OUIFLT OLED PLAIN

cyberman54 commented 5 years ago

Which version oft software did you use?

DasNordlicht commented 5 years ago

I use the last commit e7a416cd7a5350fe6f2882af3621a9ebbfae1611

cyberman54 commented 5 years ago

Could you re-test without that commit? I saw it working on heltec v2 already before this commit, maybe the bug came in with it.

DasNordlicht commented 5 years ago

Which version worked for you, how far should I go back?

aapris commented 5 years ago

I've this same issue in one TTGO V2(.1?). I thought the display was broken. I think I flashed it last week using commit 80866adecf176ba47321dbffa04c0dc1ab89d75a

release_version = 1.7.11
env_default = ttgov2
aapris commented 5 years ago

I found one TTGO v2 running v1.6.971 in my bag, its display worked until I flashed it with v1.7.11, now it remains blank.

cyberman54 commented 5 years ago

Probably a bug in i2c handling, or pin mapping. Note: Pin maps for heltec device come from extern pins_arduino.h from arduino-esp32 repo.

cyberman54 commented 5 years ago

@DasNordlicht @aapris Please update to latest 6b3a367 , there was a fix in i2c handling two days ago which should solve this issue.

Please check and report result here, thanks.

DasNordlicht commented 5 years ago

Sorry also no Display :-(

This is the arduino-esp32 pins_arduino.h: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_wifi_lora_32/pins_arduino.h And this the Heltec V2 Version: https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/blob/master/esp32/variants/wifi_lora_32_V2/pins_arduino.h

--- Heltec --- static const uint8_t SDA = 21; static const uint8_t SCL = 22; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4;

--- Arduino ESP32 --- static const uint8_t SDA = 4; static const uint8_t SCL = 15; static const uint8_t OLED_SCL = 15; static const uint8_t OLED_SDA = 4; static const uint8_t OLED_RST = 16;

How can I use the right definition?

DasNordlicht commented 5 years ago

OK, the error has already been reported by Heltec https://github.com/espressif/arduino-esp32/pull/2392

cyberman54 commented 5 years ago

@DasNordlicht Seems we found the bug, thanks. I updated the paxcounter hal file vor Heltec v2, it should work now without the patch in pins_arduino.h. I will leave this in, until Heltec's pull request was merged. If you try to recompile and reflash it should now work with your v2 board.

aapris commented 5 years ago

Can you update also src/hal/ttgov2.h and possibly src/hal/heltec.h and src/hal/ttgov1.h since they may have the same bug:

// Pins for I2C interface of OLED Display
#define MY_OLED_SDA OLED_SDA
#define MY_OLED_SCL OLED_SCL
aapris commented 5 years ago

I tried this in src/hal/ttgov2.hwithout luck:

#define MY_OLED_SDA (21)
#define MY_OLED_SCL (22)
aapris commented 5 years ago

When I remove my changes and uncomment env_default = ttgov21old instead of ttgov2 the display works. Also LoRaWAN part seems to work since my Gemtek indoor gateway catches paxcounter packets so v21old seems to be somewhat compatible with v2.

BTW, this line env_default = ebox, eboxtube, heltec, ttgobeam, lopy4, lopy, ttgov21old, ttgov21new, ttgofox is uncommented here and my Platform.io compiles for all those boards, may be not by purpose? https://github.com/cyberman54/ESP32-Paxcounter/blob/a25ab0930c465363cadd8da8d0a5022ea79e1163/platformio.ini#L27

cyberman54 commented 5 years ago

fixed the platformio.ini.

cyberman54 commented 5 years ago

updated heltec v1 hal file with explicit pin numbers.

cyberman54 commented 5 years ago

updated TTGOv1 and TTGOv2 hal files with explicit pin numbers.

DasNordlicht commented 5 years ago

So the Display is working:

Pins for I2C interface of OLED Display

define MY_OLED_SDA (4)

define MY_OLED_SCL (15)

define MY_OLED_RST (16)

And an 10KOhm Resistor between +5V and PIN4

cyberman54 commented 5 years ago

sure that you have a heltec v2 and not a v1?

cyberman54 commented 5 years ago

I tested the current code from repo (v1.7.2) with a heltec V1. Works like a charm, pinouts for v1 are correct.

cyberman54 commented 5 years ago

@DasNordlicht Meanwhile i tested with a heltec V2. The current settings in the repo are correct, it works with Heltec V2 (SDA=21/SCL=22).

If your board runs on SDA=4/SCL=15, it probably is a V1, or there are V2s with different pinouts. My V2 has a printed label "V2" alongside the U.FL connector. This label is not present on V1 boards.

Neither on V1 nor on V2 i ever used pullups on the I2C bus. I am not sure if the electrical design by Heltec for the I2C bus is well designed, but it seems to work without extra pullups, at least as long as the display is the only device on the bus.

Parr0t commented 5 years ago

@cyberman54 I have the problem again now. can it be that with the new update again the header files are wrong? my display shows me nothing although i have the V2 board from Heltec :(

cyberman54 commented 5 years ago

@Parr0t Probably the low power switch of heltec v2 board causes the trouble. I disabled it in heltecv2.h for now, please reload this file and build again.

Parr0t commented 5 years ago

@cyberman54 now there are unfortunately new errors in the channel definition. these were either initialized incorrectly or the method in battery.cpp cannot work with it because it was set to adc2.

define HAS_BATTERY_PROBE ADC2_GPIO13_CHANNEL

this line throws errors: i guess the wrong channels are addressed there or the numbers are swapped.

cyberman54 commented 5 years ago

Yes, this is an ADC2 problem, the battery.cpp was designed for ADC1 only. Until battery.cpp is improved by somebody (could you make PR for this?) i will disable battery voltage monitoring in Heltec v2 hal file to avoid errors.

cyberman54 commented 5 years ago

https://github.com/cyberman54/ESP32-Paxcounter/issues/321

4jandals commented 5 years ago

I have two variations of "Heltec V2" boards which came from two different suppliers. Both have the antenna connection on the right of the board below the v2 label. However, the components on the board are very slightly different.

With one of these boards, the latest heltecv2.h configuration works great, but for the other I had to make some strange changes to get the oled working....

When I looked at the order of the parameters being passed to U8X8_SSD1306_128X64_NONAME_HW_I2C, they are in a different order to what I've used in other projects. Switching the config from U8X8_SSD1306_128X64_NONAME_HW_I2C to U8X8_SSD1306_128X64_NONAME_SW_I2C and swapping the order as follows got it working for me:

// Pins for I2C interface of OLED Display
#define MY_OLED_SDA (16)
#define MY_OLED_SCL (4)
#define MY_OLED_RST (15)

And with this configuration, it also continues to work on my other v2 board.

4jandals commented 5 years ago

Looks like HW and SW have different constructs which explains the order (https://github.com/olikraus/u8g2/issues/664).

What I didn't explain in the last post is that the problem I had with the display was the "invalid state sda(4)=0, scl(15)=0" error message. Switching to SW version of the I2C constructor avoids the error.

cyberman54 commented 5 years ago

I won't switch from hardware to software i2c, since this has drawbacks. If the software i2c works but shows no i2c errors this does.not mean that there are no errors ob the i2c bus.

We need to check the root cause for this issue to solve it.

A common problem with shenzen hardware is, that there is a lack in change/version management and documentation.

This issue could point to different or missing pullup resistors on the i2c bus, or a display type which comes with a driver chip which uses different timings or has timing issues.

Do you have an oscilloscope or logic analyzer to check what's going ob the i2c bus? E.g. a Rigol 1054 can analyze i2c data.

cyberman54 commented 5 years ago

V1.7.4 re-tested with Heltec V2, no display issues. Closing this now.