touchRead(32) and touchRead(33) pins are swapped

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

touchRead(32) and touchRead(33) pins are swapped

Postby OutOfLine » Thu Oct 15, 2020 6:29 am

After some long debugging sessions I just found out that the Arduino function touchRead(pin) swaps pins 32 and 33. So touchRead(32) does in fact check pin 33 and vice versa.
Quite unexpected result ;)
Will have to explore further when I'll have the time...

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

Re: touchRead(32) and touchRead(33) pins are swapped

Postby OutOfLine » Sat Oct 17, 2020 2:57 pm

Somehow my follow up has disappeared, so I summarize:
The issue is in the esp32-arduino software.
Please react in the thread in the Arduino subforum
"How to check Arduino version" https://www.esp32.com/viewtopic.php?f=19&t=17741

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

Re: touchRead(32) and touchRead(33) pins are swapped

Postby OutOfLine » Tue Oct 27, 2020 10:54 am

Short summary of what i found out so far:
In esp32-arduino touchRead(32) and touchRead(33) do read the pins swapped, while analogRead() works as expected.
I see this on all the different boards I have tested.

try this:

Code: Select all

void setup() {
  Serial.begin(500000);
  Serial.println("TEST: touchRead(32) and touchRead(33) are swapped\n");
  delay(3000);
}

void loop() {
  Serial.print("touch(32) ");
  Serial.print(touchRead(32));
  Serial.print("\ttouch(33) ");
  Serial.print(touchRead(33));

  Serial.print("\tanalog(32) ");
  Serial.print(analogRead(32));
  Serial.print("\ta(33) ");
  Serial.println(analogRead(33));
  delay(500);
}
If you touch pin 32 or pin 33 you will see what I mean.
Even better when you connect one of the pins to ground:

Code: Select all

// pin 32 connected to GND
touch(32) 136	touch(33) 0	analog(32) 0	a(33) 732

// pin 33 connected to GND
touch(32) 0	touch(33) 131	analog(32) 1001	a(33) 0
Workaround based on the following commit:
https://github.com/espressif/arduino-es ... 1a63579378
change file esp32-hal-gpio.c

Code: Select all

// ~/.arduino15/packages/esp32/hardware/esp32/1.0.4/cores/esp32/esp32-hal-gpio.c
// lines 62, 63
    {0x1c, 9, 4, 9},
    {0x20, 8, 5, 8},
 // change to
    {0x1c, 9, 4, 8},
    {0x20, 8, 5, 9},
This is a bad hack, as it bypasses git, but it works for me.

I had no success trying to find and checkout the right development branch yet.
I have started here https://github.com/espressif/arduino-es ... structions

Help would be much appreciated...

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

SOLVED: touchRead(32) and touchRead(33) pins are swapped

Postby OutOfLine » Wed Nov 11, 2020 9:34 am

Installing new esp32-arduino version 1.0.5-rc1 fixes the issue :)

Who is online

Users browsing this forum: axellin, Vitalii_Bondarenko and 86 guests