EPS32C6 digital input not working

I tested 3 of my EPS32C6 units and all of them behaves the same. I can only use D0 to D2 for digital INPUT, the rest of of the pins are always reading high even if I connect it to the ground.

Any one has same issue?

How did you check?
If you can show me the sketch you used to check, I will try it on my C6.

I’m using platformio:

for simple main.cpp

#include <AccelStepper.h>
#include <Encoder.h>
#include <OneButton.h>

#define ENCODER_BTN 7

void setup() {
  Serial.begin(9600);
  pinMode(ENCODER_BTN, INPUT_PULLUP);
}

void loop() {
    int result = digitalRead(ENCODER_BTN);
    Serial.print("Encoder button value: ");
    Serial.println(result);
    delay(500);
}

and for platformio.ini

[common]
lib_deps =
	waspinator/AccelStepper@^1.64
	paulstoffregen/Encoder@^1.4.4
	mathertel/OneButton@^2.6.1

[env:seeed_xiao_esp32c6]
platform = https://github.com/mnowak32/platform-espressif32.git#boards/seeed_xiao_esp32c6
platform_packages =
    framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2
    ;framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip
	framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.3/esp32-arduino-libs-3.0.3.zip
board = seeed_xiao_esp32c6
framework = arduino
lib_deps = ${common.lib_deps}

You can just change the ENCODER_BTN for testing. When I tried to short this pin to ground it still read HIGH except for D0, D1, D2 which is working fine.

Define the pin according to the “XIAO ESP32C6 Pin List” in the ESP32C6 Wiki.

//#define ENCODER_BTN 7
#define ENCODER_BTN 17
1 Like

Thanks. I missed that GPIO matching number.

It’s possible that those pins are internally pulled up. You can use

pinMode(pin, INPUT_PULLDOWN);  

And see if it continues behaving the same.

1 Like

I found that instead of looking for the matching GPIO pin number, I can also just use D7 (instead of 17 GPIO17) for better mapping when working on different board and it will be consistent.

Example:

#define ENCODER_PIN_A D5 // instead of 22
#define ENCODER_PIN_B D6 // instead of 23
#define ENCODER_BTN D7 // instead of 17
1 Like

For pin definitions, the following folders are helpful.

C:\Users\xxxx\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7\variants\XIAO_ESP32C6

1 Like

And for macOS it is
/Users/xxx/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/XIAO_ESP32C6