MPR121 with HUZZAH32 : noise in cap sensor readings

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

Hello,

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 12C 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 an 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).

Thanks in advance for any insights!

Code: Select all

#include <Wire.h>
#include "Adafruit_MPR121.h"

#ifndef _BV
#define _BV(bit) (1 << (bit)) 
#endif

Adafruit_MPR121 cap1 = Adafruit_MPR121();

void setup() {
 Serial.begin(115200);
 Serial.println("MPR121"); 
  if (!cap1.begin(0x5A)) {Serial.println("5A Bad"); while (1); }
   else {Serial.println("5A Good"); }
   Wire.begin (23, 22, 4000);
}
 
void loop() {
  Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap1.touched(), HEX);
  Serial.print("Filt: ");
  for (uint8_t i=0; i<12; i++) {
    Serial.print(cap1.filteredData(i)); Serial.print("\t");
  }
  Serial.println();
  Serial.print("Base: ");
  for (uint8_t i=0; i<12; i++) {
    Serial.print(cap1.baselineData(i)); Serial.print("\t");
  }
  Serial.println();
  delay(1000);
}

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

Adding more info: 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)

Below is a partial dump of the Arduino IDE Debug on monitor:

Code: Select all

Filt: [  4196][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
227	216	197	196	195	190	214	205	196	185	181	196	
Base: 224	216	1020	192	192	1020	212	204	1020	[  4207][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
[  4207][W][esp32-hal-i2c.c:1437] i2cCheckLineState(): invalid state sda(23)=0, scl(22)=1
[  4214][D][esp32-hal-i2c.c:1445] i2cCheckLineState(): Recovered after 1 Cycles
1020	180	196	
													 0x0
Filt: 227	216	198	195	195	190	214	205	196	65500	182	197	
Base: 224	216	196	192	192	188	212	204	196	184	180	196	
													 0x0
Filt: 227	216	197	[  6288][D][esp32-hal-i2c.c:1371] i2cProcQueue():  Gross Timeout Dead start=0x185d, end=0x188f, =50, max=50 error=1
[  6288][E][esp32-hal-i2c.c:336] i2cDumpI2c(): i2c=0x3ffbdb68
[  6293][I][esp32-hal-i2c.c:337] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[  6299][I][esp32-hal-i2c.c:339] i2cDumpI2c(): lock=0x3ffb90dc
[  6305][I][esp32-hal-i2c.c:341] i2cDumpI2c(): num=0
[  6310][I][esp32-hal-i2c.c:342] i2cDumpI2c(): mode=1
[  6314][I][esp32-hal-i2c.c:343] i2cDumpI2c(): stage=3
[  6319][I][esp32-hal-i2c.c:344] i2cDumpI2c(): error=1
[  6324][I][esp32-hal-i2c.c:345] i2cDumpI2c(): event=0x3ffb9164 bits=200
[  6331][I][esp32-hal-i2c.c:346] i2cDumpI2c(): intr_handle=0x3ffb9198
[  6337][I][esp32-hal-i2c.c:347] i2cDumpI2c(): dq=0x3ffb9278
[  6342][I][esp32-hal-i2c.c:348] i2cDumpI2c(): queueCount=2
[  6347][I][esp32-hal-i2c.c:349] i2cDumpI2c(): queuePos=1
[  6352][I][esp32-hal-i2c.c:350] i2cDumpI2c(): errorByteCnt=0
[  6358][I][esp32-hal-i2c.c:351] i2cDumpI2c(): errorQueue=2
[  6363][I][esp32-hal-i2c.c:352] i2cDumpI2c(): debugFlags=0x00000000
[  6369][I][esp32-hal-i2c.c:329] i2cDumpDqData(): Debug Buffer not Enabled
[  6376][I][esp32-hal-i2c.c:372] i2cDumpInts(): Debug Buffer not Enabled
65535	[  6393][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
195	190	65535	205	196	185	182	65535	
Base: 224	216	196	1020	[  6399][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
[  6400][W][esp32-hal-i2c.c:1437] i2cCheckLineState(): invalid state sda(23)=0, scl(22)=1
[  6408][D][esp32-hal-i2c.c:1445] i2cCheckLineState(): Recovered after 3 Cycles
608	188	212	204	196	184	180	196	
													 0x0
Filt: 227	216	197	196	195	65535	214	205	196	185	182	196	
Base: 224	216	196	192	192	1020	212	1020	196	1020	180	1020	
													 0x0
Filt: 227	216	197	196	195	190	214	205	196	185	182	197	
Base: 224	[  8490][D][esp32-hal-i2c.c:1371] i2cProcQueue():  Gross Timeout Dead start=0x20f7, end=0x2129, =50, max=50 error=1
[  8490][E][esp32-hal-i2c.c:336] i2cDumpI2c(): i2c=0x3ffbdb68
[  8494][I][esp32-hal-i2c.c:337] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[  8501][I][esp32-hal-i2c.c:339] i2cDumpI2c(): lock=0x3ffb90dc
[  8507][I][esp32-hal-i2c.c:341] i2cDumpI2c(): num=0
[  8512][I][esp32-hal-i2c.c:342] i2cDumpI2c(): mode=1
[  8516][I][esp32-hal-i2c.c:343] i2cDumpI2c(): stage=3
[  8521][I][esp32-hal-i2c.c:344] i2cDumpI2c(): error=1
[  8526][I][esp32-hal-i2c.c:345] i2cDumpI2c(): event=0x3ffb9164 bits=200
[  8532][I][esp32-hal-i2c.c:346] i2cDumpI2c(): intr_handle=0x3ffb9198
[  8539][I][esp32-hal-i2c.c:347] i2cDumpI2c(): dq=0x3ffb9278
[  8544][I][esp32-hal-i2c.c:348] i2cDumpI2c(): queueCount=2
[  8549][I][esp32-hal-i2c.c:349] i2cDumpI2c(): queuePos=1
[  8554][I][esp32-hal-i2c.c:350] i2cDumpI2c(): errorByteCnt=-1
[  8560][I][esp32-hal-i2c.c:351] i2cDumpI2c(): errorQueue=0
[  8565][I][esp32-hal-i2c.c:352] i2cDumpI2c(): debugFlags=0x00000000
[  8571][I][esp32-hal-i2c.c:329] i2cDumpDqData(): Debug Buffer not Enabled
[  8578][I][esp32-hal-i2c.c:372] i2cDumpInts(): Debug Buffer not Enabled
1020	[  8595][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
608	192	192	188	212	204	196	184	180	196	
													 0x0
Filt: 227	216	197	196	195	190	214	205	65535	185	181	197	
Base: 224	216	196	192	192	188	212	612	196	184	180	196	
													 0x0
Filt: 227	216	197	196	195	190	214	204	196	185	182	197	
Base: 224	1020	[ 10622][I][esp32-hal-i2c.c:1156] i2cProcQueue(): Bus busy, reinit
[ 10623][W][esp32-hal-i2c.c:1437] i2cCheckLineState(): invalid state sda(23)=0, scl(22)=1
[ 10626][D][esp32-hal-i2c.c:1445] i2cCheckLineState(): Recovered after 9 Cycles
196	192	192	188	1020	204	608	184	1020	196	
													 0x0
Filt: 227	216	197	195	195	190	214	205	196	185	181	197	
Base: 224	216	196	192	192	188	212	204	196	184	180	196	


User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

Someone mentioned that I should add this to my post:
ORDER #2639075-6762668115
ORDER DATE August 20, 2021 @ 4:56 PM

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by adafruit_support_carter »

Can you post a photo of the HUZZAH32 with MPR121 setup.

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

Thanks @adafruit_support_carter

I'm powering the MPR121 (VIN) from HUZZAH32's 3V (red) + ground (black) and connecting SDA to SDA (blue) and SCL to SCL (yellow). The cap sensors on the left (with dupont cables) are the wires to the copper strips. The HUZZAH is fed by the microUSB port connected to my laptop's USB port. At the top you can see a portion of the second MPR121 which is currently disconnected to simplify tests, although I get the exact same behavior either way. When using Arduino MEGA or UNO instead of HUZZAH32 in the same setup, everything works fine.
Attachments
Setup of HUZZAH32 + MPR121
Setup of HUZZAH32 + MPR121
image1.jpg (241.13 KiB) Viewed 133 times

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by adafruit_support_carter »

Thanks for the photos. That all looks fine.

Try running your sketch with the cap sensors removed from the breadboard. So just the bare MPR121 module connected to the Feather ESP32. I just set that up and ran your sketch from above and I'm not seeing those weird readings.
Screenshot from 2021-09-08 08-57-24.png
Screenshot from 2021-09-08 08-57-24.png (57.1 KiB) Viewed 129 times

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

I ran it like you suggested and got the same result.

By chance, I grabbed the USB-microUSB cable powering the HUZZAH and the weird data became even worse. So I powered it with a LiPO battery and used WebSerial as a serial monitor https://github.com/ayushsharma82/WebSerial to run totally untethered. The output data was totally clean!

More tests: when touching the LiPO battery, noise on the output data returns. If touching the micro USB connector on the HUZZAH with the USB cable (not connecting it, just touching it), noise on the output data returns.

So it seems that either there's an issue with HUZZAH's grounding of the power circuits or my board is defective.
Have you heard anything about the first alternative? If not, any ideas on what can I try on the electrical side (i.e. grounding) to fix this?

Thanks!

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by adafruit_support_carter »

Does seem like some kind of odd grounding or other connection issue. In your photo, are the red/black wires going straight from Feather to the MPR? Or is there more going on?

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

red/black go straight from Feather to MPR. Nothing else in between.

I used a different breadboard. No change
I used female to female dupont cables (connecting the headers of the feather and the MPR) with no breadboard. No change

Since GND is common to power and logic, this could be the "leak" that's feeding the SDL/SCL with noise? -> when I touch the battery (when running untethered) or touch the cable (when running with USB connection to laptop) the I2C readings go wild. Is there a way to isolate GND for logic and GND for power?

Using multimeter, when running on battery alone (i.e. USB jack not connected), I get 3.3V between GND and USB "...this is the positive voltage to/from the micro USB jack if connected. ." (from documentation). Shouldn't this have 0V if no USB jack is connected? BTW, this also generates wild readings

Using one of the multimeter probes to touch any of the pins on the feather generates also wild readings

User avatar
tahunus
 
Posts: 33
Joined: Fri Aug 20, 2021 4:24 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by tahunus »

FIXED: So it was an instability in the Arduino I2C implementation of the ESP32. The fix can be found at https://github.com/espressif/arduino-esp32/pull/5683

This PR is a complete refactoring of Wire Library and I2C HAL in order to use IDF instead of current Register manipulation approach. It implements Thread-safe Arduino Wire.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MPR121 with HUZZAH32 : noise in cap sensor readings

Post by adafruit_support_carter »

Interesting. Thanks for pointing that out. That's affecting several things right now. Hopefully they'll get something merged and a new BSP release done soon.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”