-
Notifications
You must be signed in to change notification settings - Fork 7.6k
MPR121 with HUZZAH32 : noise from cap sensor readings via I2C #5635
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
Comments
@tahunus
But looking into Adafruit code, I can tell that this will make it reset to default I2C pins... |
Use Arduino IDE using "Adafruit ESP32 Feather" as your board. The default I2C pins in its setup are already SDA = 23 and SCL = 22. This may solve your issue. you setup with "Adafruit ESP32 Feather" should look like this: void setup() {
Serial.begin(115200);
Serial.println("MPR121");
// just to check that SDA and SCL are correctly set as 23 and 22 when using the right board setup with Arduino IDE
// remove this test latter, after checking it works fine on Adafruit HUZZAH32
if (SDA != 23 || SCL != 22) {
Serial.println("ERROR :: I2C SDA and SCL are not correct. Please check you board choice on Arduino IDE.");
}
if (!cap1.begin(0x5A)) {Serial.println("5A Bad"); while (1); }
else {Serial.println("5A Good"); }
}
|
thanks @SuGlider.
Thinking it could be a speed compatibility issue (given the speed differences between Arduinos and HUZZAH32), I tested several clock speeds on the I2C channel (from 5k to 400k), changed crystal speed on the HUZZAH32 to 40MHz and 80MHZ, and added delays of up to 1 sec between readings, but got the same results (only slower or faster serial output).
Correct. That's why I added it after the cap1,begin. In any case, with or without the Wire.begin statement I get the same result
Board: HUZZAH32 (ESP WROOM 32) Thanks! |
That is precisely the board spec I'm using. It's the one recommended by Adafruit (HUZZAH32's manufacturer) https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/using-with-arduino-ide
Done. Same result
SDA & SCL are correctly identified as 23 & 22 according to the DEBUG dump from the Arduino IDE (sample below, bigger sample in the first post above): I think the issue has to do with the stability of ESP32's implementation of I2C. Looking at the DEBUG dump, there are a lot of "bus busy" and "invalid state" that, although recovered after several cycles, by then the reading has been reported as 65535. Thanks!! |
Thanks @SuGlider. I guess I'll have to wait. Meanwhile, I'll run some other scenarios and report back in the hopes of providing further insights. |
@SuGlider , pardon my newby-ness: besides adding the link |
@tahunus Yes, I see you are already in 2.0.0, so just copy the 4 files today into their respective folders. Another way is using git, but I think it will be easier for you to just make a backup and overwrite those files as you said. |
@SuGlider when compiling with the 4 new files, these compiler errors appear: `Arduino: 1.8.15 (Windows 10), Board: "Adafruit ESP32 Feather, 80MHz, 921600, None, Default" In file included from C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal.h:79,
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:34:5: error: expected '}' before 'I2C_ERROR_ADDR_NACK'
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:24:14: note: to match this '{' typedef enum {
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:37:5: error: 'typedef enum I2C_ERROR_ADDR_NACK I2C_ERROR_TIMEOUT' redeclared as different kind of symbol
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:28:5: note: previous declaration 'I2C_ERROR_ADDR_NACK I2C_ERROR_TIMEOUT'
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:40:5: error: 'typedef enum I2C_ERROR_ADDR_NACK I2C_ERROR_NO_BEGIN' redeclared as different kind of symbol
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:33:5: note: previous declaration 'I2C_ERROR_ADDR_NACK I2C_ERROR_NO_BEGIN'
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:41:1: error: expected unqualified-id before '}' token } i2c_err_t; ^ C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:41:3: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? } i2c_err_t; ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:48:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, uint8_t* buff, uint16_t size, bool sendStop, uint16_t timeOutMillis); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:49:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, uint8_t* buff, uint16_t size, bool sendStop, uint16_t timeOutMillis, uint32_t *readCount); ^~~~~~~~~ esp_err_t In file included from C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal.h:79,
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:50:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cFlush(i2c_t *i2c); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:51:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cSetFrequency(i2c_t * i2c, uint32_t clk_speed); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:57:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cAttachSCL(i2c_t * i2c, int8_t scl); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:58:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cDetachSCL(i2c_t * i2c, int8_t scl); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:59:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:60:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cDetachSDA(i2c_t * i2c, int8_t sda); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:63:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cProcQueue(i2c_t *i2c, uint32_t *readCount, uint16_t timeOutMillis); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:64:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cAddQueueWrite(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr, uint16_t dataLen, bool SendStop, EventGroupHandle_t event); ^~~~~~~~~ esp_err_t C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal-i2c.h:65:1: error: 'i2c_err_t' does not name a type; did you mean 'esp_err_t'? i2c_err_t i2cAddQueueRead(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr, uint16_t dataLen, bool SendStop, EventGroupHandle_t event); ^~~~~~~~~ esp_err_t In file included from C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/Arduino.h:36,
C:\Users\pedro\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/esp32-hal.h:132:1: error: expected declaration before '}' token } ^ exit status 1 Error compiling for board Adafruit ESP32 Feather. This report would have more information with |
You can try copying the files from my GitHub: https://github.com/SuGlider/arduino-esp32/blob/i2c-refactoring/cores/esp32/esp32-hal-i2c.c https://github.com/SuGlider/arduino-esp32/blob/i2c-refactoring/cores/esp32/esp32-hal-i2c.h https://github.com/SuGlider/arduino-esp32/blob/i2c-refactoring/libraries/Wire/src/Wire.cpp https://github.com/SuGlider/arduino-esp32/blob/i2c-refactoring/libraries/Wire/src/Wire.h Please check the correct folder for each one. I hope it works better! |
Hi could you please re-test with this new PR: #5683 |
@SuGlider It works! I ran several scenarios and the noise in the I2C channel is gone. Operation is stable! Thanks! (apologies for the long silence, my "real world" job was too demanding these last few days. |
@me-no-dev It works! I ran several scenarios and the noise in the I2C channel is gone. Operation is stable! Thanks! (apologies for the long silence, my "real world" job was too demanding these last few days. |
Hardware:
Board: HUZZAH32 (ESP WROOM 32)
Core Installation version: 2.0.0 (Arduino core for ESP32)
IDE name: Arduino IDE
Flash Frequency: 40Mhz (also tried 80Mhz with same results)
Partition Scheme: no OTA (also tried Default with same results)
Upload Speed: 921600
Computer OS: Windows 10
Description:
When running Adafruit's sketch to debug MPR121's "raw" data using cap.filteredData(i) & cap.baselineData(i), everything works just fine if using an Arduino UNO or an Arduino MEGA. When running it on a HUZZAH32, the filtered data keeps returning wild readings (65535, 32738, etc.) on several (not all, but almost never none) of the cap sensors. The HUZZAH32 is connected via USB to my laptop (same as the tests on the Arduinos). I2C ports on HUZZAH are 23 for SDA & 22 for SCL. I ran other sample programs (not involving MPR121) on the HUZZAH32 and it works fine (so the board is ok).
A brief sample of the monitor output from the 12 sensors´ filtered and base data looks like this:
Filt: 227 216 198 195 195 189 65535 205 65535 65535 65535 32738
Base: 224 216 196 192 192 188 212 1020 196 604 180 196
0x0
Filt: 65535 65535 197 195 65535 189 65535 205 65535 185 181 197
Base: 624 216 196 192 192 188 212 204 1020 184 180 196
0x0
Filt: 228 216 197 196 195 189 214 205 196 185 182 197
Base: 224 212 1020 192 1020 188 212 204 196 184 180 196
0x0
If I grab (i.e. touch) the USB cable feeding the HUZZAH32, all sensors go wild (it does not happen with the Arduinos), so there is clearly some issue with noise from the power line feeding the HUZZAH32. I tried with different USB cables with the same result.
Has anyone seen noise from the power line in the HUZZAH32 fed into the I2C channel? Or into the cap sensors of a MPR121?
Since I intend (eventually) to make this a wireless cap sensing solution (hence the need for a HUZZAH32), there won't be a USB cable. It will all be fed by a 1200mAh LiPO battery which may solve the noise problem from the power line. But, since there's is still a lot of coding ahead of this project, I'll need the USB tether.
Thinking it could be a speed compatibility issue (given the speed differences between Arduinos and HUZZAH32), I tested several clock speeds on the I2C channel (from 5k to 400k), changed crystal speed on the HUZZAH32 to 40MHz and 80MHZ, and added delays of up to 1 sec between readings, but got the same results (only slower or faster serial output).
I'm powering the MPR121 from 3V3. The same behavior is present when running the MPR121 from the USB (5V) supply (the MPR121 has a built-in regulator and pullup resistors in the I2C pins)
HUZZAH32: https://learn.adafruit.com/adafruit-huzzah32-esp32-feather
MPR121 : https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial?view=all
Thanks in advance for any insights!
Sketch: (leave the backquotes for code formatting)
Debug Messages:
The text was updated successfully, but these errors were encountered: