How to read gpio configuration?

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

How to read gpio configuration?

Postby OutOfLine » Sat Feb 24, 2018 2:00 pm

I want to my program to read state of gpio pins.

On old Arduino hardware i did things like

Code: Select all

// ATTENTION:  example code is for old Arduino boards, *not* ESP
  // input or output?
  reg = portModeRegister(port);
  if (*reg & mask) {      // digital OUTPUTS
   ...
    // high or low?
    reg = portOutputRegister(port);
    if (*reg & mask) {          // HIGH
        ...
    } else {             // LOW
      ...
    }
  } else {         // digital INPUTS
    ...
    // pullup, tristate
    // similar code ...
  }

How can I get similar informations on an ESP32?

User avatar
Champ76
Posts: 2
Joined: Fri Feb 16, 2018 8:30 am

Re: How to read gpio configuration?

Postby Champ76 » Mon Feb 26, 2018 2:41 pm

If you are using Arduino core for ESP32, than use digitalRead(pin); which will return value 0 or 1.
You need to pass one parameter which is GPIO pin number. For example,

Code: Select all

#include <Arduino.h>

#define MyPin 15
#define LED_BUILTIN 2
 
//-----------------------------------------------------
void setup(void) {
  Serial.begin(115200);
  pinMode(MyPin , INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
 }
 
//-----------------------------------------------------
void loop(void) {
  int pinState = 0;
  digitalWrite(LED_BUILTIN, pinState);
  delay(1000);
  pinState = digitalRead(MyPin);
  Serial.print("Pin State= ");
  Serial.println(pinState);
  digitalWrite(LED_BUILTIN, ! pinState);
  delay(2000);
}


By default pin value set to 0. In above example LED connected to pin 2 will OFF for 1 second and On for 2 second. This will repeat continuously.

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

Re: How to read gpio configuration?

Postby OutOfLine » Tue Feb 27, 2018 9:37 am

thank @Champ76 for replying

but this is not what i need

i want to read *configuration* of a pin
like is the pin an input, output, pullup, and more

main use is debugging

robert

Who is online

Users browsing this forum: loboris and 10 guests