I’m using Adafruit’s HUZZAH32 Feather (ESP32 WROOM) and three of their MPR121 capacitive touch sensor breakouts with I2C communication. The MPR121 breakouts have distinct I2C addresses, I2C level shifting and a regulator (it’s a 3V chip: to use 3V or 5V sources) and include the required SDA/SCL pullups. The HUZZAH does not have SDA/SCL pullups.
On PIO I’m using Core v5.2.3 with Espressif32 v3.4.0. On Arduino I’m using IDE v.1.8.15 with Espressif v2.0.1 (all latest stable releases for each platform and IDE). On both I’m using Adafruit BusIO v1.9.3 and Adafruit MPR121 v1.1.1
The following simple sketch reads the FilteredData of each sensor and prints it out.
The HUZZAH’s V-Out pin serves 3.3V & 500mA from its regulator, but the ESP32 draws about half of this. I could not find how much power the MPR121’s draw but it would seem that the 250mA remaining from the HUZZAH32 may not be enough for all three: when powering them from the V-Out, every now and then a timeout in the I2C occur (represented as negative reading from the cap sensor) when compiled with Arduino. But, when compiling the same sketch with PIO, the faults appear with nearly every attempt to read the sensors.
If powering the MPR121’s directly from battery (4.1V) or USB (5V), the timeouts disappear if compiled with Arduino but remain there when compiled with PIO.
The erratic behavior when compiled with PIO includes creating the sensor’s instance with cap.begin(), which sometimes sends this error to the serial monitor: [E][esp32-hal-i2c.c:1434] i2cCheckLineState(): Bus Invalid State, TwoWire() Can’t init sda=1, scl=1. Creation of the sensors’ instances never fails when compiled with Arduino
Is there something I could / should change in PIO’s config to fix this?
Thanks!
platformio.ini:
[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
monitor_speed = 115200
lib_deps = adafruit/Adafruit MPR121@^1.1.1
main.cpp:
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_MPR121.h>
Adafruit_MPR121 cap1 = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();
Adafruit_MPR121 cap3 = Adafruit_MPR121();
Adafruit_MPR121 cap4 = Adafruit_MPR121();
boolean c5A, c5B, c5C, c5D = false;
void setup() {
Serial.begin(115200);
Wire.begin(23,22);
Serial.println("delaying..."); delay(500);
// Default address is 0x5A, if tied to 3.3V its 0x5B, If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap1.begin(0x5A)) {Serial.println("5A Not Found"); } else {Serial.println("5A Good"); c5A = true;}
if (!cap2.begin(0x5B)) {Serial.println("5B Not Found"); } else {Serial.println("5B Good"); c5B = true;}
if (!cap3.begin(0x5C)) {Serial.println("5C Not Found"); } else {Serial.println("5C Good"); c5C = true;}
if (!cap4.begin(0x5D)) {Serial.println("5D Not Found"); } else {Serial.println("5D Good"); c5D = true;}
delay(2000);
}
void loop() {
if (c5A) {
Serial.print("5A: ");
for (int i = 0; i < 12; i++)
{Serial.print(cap1.filteredData(i)); Serial.print(",");}
Serial.println(); }
if (c5B) {
Serial.print("5B: ");
for (int i = 0; i < 12; i++)
{Serial.print(cap2.filteredData(i)); Serial.print(",");}
Serial.println(); }
if (c5C) {
Serial.print("5C: ");
for (int i = 0; i < 12; i++)
{Serial.print(cap3.filteredData(i)); Serial.print(",");}
Serial.println(); }
if (c5D) {
Serial.print("5D: ");
for (int i = 0; i < 12; i++)
{Serial.print(cap4.filteredData(i)); Serial.print(",");}
Serial.println(); }
Serial.println();
delay(500);
}