cyberman54 / ESP32-Paxcounter

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

Usage of Wire library. #156

Closed Koepel closed 5 years ago

Koepel commented 5 years ago

In the file "ESP32-Paxcounter/src/lorawan.cpp", in the function get_hard_deveui(), the functions to read and write data with I2C are mixed together.

The first part has the sequence: Wire.begin - Wire.beginTransmission - Wire.write - Wire.endTransmission That is good.

The second part has the sequence: Wire.beginTransmission - Wire.write - Wire.requestFrom - Wire.available - Wire.read - Wire.endTransmission That is a mix between reading and writing. Writing data should always have Wire.endTransmission() at the end, and the Wire.beginTransmission() and Wire.endTransmission() may not be used together with Wire.requestFrom().

See my alternative explanation of the functions of the Wire library.

A similar issue is in the file: "ESP32-Paxcounter/src/gps.cpp". In that file the Wire.requestFrom() is encapsulated by Wire.beginTransmssion() and Wire.endTransmission(). Explanation: Common-mistakes, number 2 and 3.

cyberman54 commented 5 years ago

Thanks for the hints, i will look at this. I assume I2C problems with the HAL from the display library, u8g2, too. Could you take at look at i2c driver in hal file of u8g2 lib, too?

Koepel commented 5 years ago

Do you mean the u8g2 library itself? I think it is okay. There is only one Wire.requestFrom() in u8g2, and that one is correct (link valid on sep 20, 2018). Everything else is writing data, and as far as I can tell, they are also correct.

cyberman54 commented 5 years ago

There is a long thread on some wired kind of interrupt problems possibly caused by i2c hal of u8g2. Indeed, display speed on paxcounter is very low since last updates.

https://github.com/espressif/arduino-esp32/issues/1588

Koepel commented 5 years ago

Thanks, I will read it, but I don't think I can help them. The ESP32 Wire-compatible library has changed, perhaps they still have few things to fix.

cyberman54 commented 5 years ago

i made changes in lorawan.cpp and gps.cpp according to your hints. Could you please re-check? You find the changes in the development branch. Thanks.

Koepel commented 5 years ago

The usage of the Wire library is correct in the development branch. I don't know what the result was of the wrong use of the Wire library. I hope it still works, because it is now doing something different.

cyberman54 commented 5 years ago

oh, it should do still the same.