Page 1 of 1

Read Rotary BCD Coded Switch

Posted: Mon Apr 01, 2019 12:19 pm
by dikkehenk
Hi,
This is my first time I am asking a question on this forum. Thanks to everyone who is contributing. Learned a lot here.

At the start of my code I want to read a 10 Position Rotary BCD Coded Switch (I only need 8 positions -3 bits-)
I am using GPIO 12-13-14 of the ESP. On my DOIT board the pinout is 6 =GPIO 13, 7 = GPIO 12, 8 = GPIO 14. I will correct that with the wiring. A simple way is to read the input register of the ESP32. Then shift right (12 times -from pin 12-) to get the dec. value of the rotary switch.

Before I can use (read) the input register I have to write/clear the GPIO_ENABLE_W1T(Clear) with 3 bits (0x07) shifted for the right pin positions.

Examples of ESP32 direct port manipulation are hard to find. With the knowledge I've collected so far I've written this code.
Am I on the right track?

Thanks Henk
  1. void setup() {
  2. pinMode(12, INPUT_PULLDOWN);
  3. pinMode(13, INPUT_PULLDOWN);
  4. pinMode(14, INPUT_PULLDOWN);
  5.  
  6. REG_WRITE(GPIO_ENABLE_W1TC_REG, 0x07 << 12); //Enable pin 12-13-14 (0x07 = bin 00000111 only need 3 bits)
  7.  
  8. uint32_t input = REG_READ(GPIO_IN_REG); //Read the Input 32bit register
  9. input = input >> 12; // Shift the found value 12 times to the right to calc the value
  10.  
  11. Serial.print (input); //Check the found decimal nr.
  12. }
  13.  
  14. void loop() { }

Re: Read Rotary BCD Coded Switch

Posted: Mon Apr 01, 2019 9:35 pm
by username
I've collected so far I've written this code. Am I on the right track?
Well, does it work, if so then your on the right track. :D

Re: Read Rotary BCD Coded Switch

Posted: Tue Apr 02, 2019 11:52 am
by dikkehenk
Just trying to get an expert view on this code

Re: Read Rotary BCD Coded Switch

Posted: Wed Apr 03, 2019 3:42 am
by ESP_Sprite
Looks good, but can I ask what the reason you don't want to use the GPIO read functions given by ESP-IDF/Arduino is?