Skip to content

Neopixel initialization affects SDA and SCL pin direction on QT Py ESP32-S2 #425

@bjfischb

Description

@bjfischb

I have had an application running on a QT Py ESP32-S2 for about 4 months. The application uses most of the GPIO as digital inputs/outputs, and also uses the built-in neopixel as a status indicator.

I updated libraries and the ESP32 board package regularly based on notifications in the Arduino IDE that a library can be updated. After updating libraries, I re-compile and upload the code to all my projects. I don't keep strict track of all the changes, so I can't pinpoint exactly when this problem ocurred.

I noticed a few weeks ago that my application had failed, and my debug pointed to a strange behavior on the QT Py ESP32-S2: the code location of the pin direction declarations (for pins used as digital I/O) relative to the neopixel initialization causes the direction settings to either be correct or incorrect. I narrowed down the code to create illustrative examples:

This code results in GPIO6 and GPIO7 correctly being configured as inputs with pullup resistors

#include <Adafruit_NeoPixel.h> 

//GPIO39 is PIN_NEOPIXEL on QTPY
Adafruit_NeoPixel neoLED = Adafruit_NeoPixel(1, 39, NEO_GRB + NEO_KHZ800);

void setup() {


//GPIO38 is NEOPIXEL_POWER on QTPY
  pinMode(38, OUTPUT);
  digitalWrite(38, HIGH);  

  neoLED.begin();  
  neoLED.setPixelColor(0, 20, 8, 20);
  neoLED.show();

  pinMode(7, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  
}

void loop() {
}

But this code results in GPIO6 and GPIO7 incorrectly being configured as outputs pulled to ground

#include <Adafruit_NeoPixel.h> 

//GPIO39 is PIN_NEOPIXEL on QTPY
Adafruit_NeoPixel neoLED = Adafruit_NeoPixel(1, 39, NEO_GRB + NEO_KHZ800);

void setup() {

  pinMode(7, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  

//GPIO38 is NEOPIXEL_POWER on QTPY
  pinMode(38, OUTPUT);
  digitalWrite(38, HIGH);  

  neoLED.begin();  
  neoLED.setPixelColor(0, 20, 8, 20);
  neoLED.show();
}

void loop() {
}

Some additional information:

  1. For the working case with pinMode statements after neopixel initialization, I confirmed that the I/O are inputs with pullup by measuring short circuit current to ground and seeing that the effective resistance to Vdd was 45k-ohm, consistent with the ESP32-S2 datasheet
  2. For the non-working case with pinMode statements before the neopixel initialization, I confirmed that the I/O are outputs driven to ground by (very) briefly measuring short circuit current to Vdd and seeing about 30mA, consistent with the ESP32-S2 datasheet
  3. The problem seems to happen only with GPIO6 and GPIO7 (SDA and SCL on the QT Py ESP32-S2 board). All the other GPIO I am using in my application are initialized correctly, even if the pinMode statements are before the neopixel initialization
  4. I ran the same code on a Feather ESP32-S2 TFT and I did not see a problem with SDA or SCL when the pinMode statements were before the neopixel initialization (the Feather uses different GPIO for neopixel power and data, so I changed the code for that). So, this seems specific to the Qt Py ESP32-S2
  5. Like I said above, I noticed the application failure in the past month or so. Before that, the application was working correctly with the pinMode statements before the neopixel initialization. So, I'm thinking a recent update may be responsible.
  6. Here are the versions I am running:
  • ESP32 board package: 3.1.3
  • Adafruit NeoPixel 1.12.5

Any help on this would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions