General

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

ESP32 DigitalRead from output pin always return LOW

Avatar
TONG GARDEN CO., LTD.

Hi , I just receive ESP32 21I/O and it work fine after I update to version 2.0.3 but I found some issue with digitalRead from output pin it will always return LOW. here is my sample code in Arduino IDE v1.8.16

void setup(){

    pinMode(Q0_0, OUTPUT); 

    digitalWrite(Q0_0, HIGH);

    Serial.println(digitalRead(Q0_0);

}

the result will be 0. And advice?


Dhanate

Avatar
Descartar
1 Respuesta
0
Best Answer

Dear Dhanate,


In the ESP32 PLC family most of the IOs work through I2C expansion chips and they do not allow to read the outputs. Although that, it is not required to read an output, if you write it with your desired state, it will have it until you change it again; you can store the state in a constant or variable and print the state when you change it, like the following example:

"""

#define HIGH_STATE HIGH

#define LOW_STATE LOW


void setup(){

    Serial.begin(9600);

    pinMode(Q0_0, OUTPUT); 

}


void loop() {

  digitalWrite(Q0_0, HIGH_STATE);

  Serial.println(HIGH_STATE);

  delay(1000);

  digitalWrite(Q0_0, LOW_STATE);

  Serial.println(LOW_STATE);

  delay(1000);

}

"""


Thank you, 

Avatar
Descartar