How to read output states?


I’m working with the Olimex EVB. I have a
thread that activates a relay randomly, and I would need
to be able to read the relay status from another thread. I
know I could save the state of the relay in a variable and check this
variable from the second thread, but I wonder if there is any method to
read directly the register of the digital output corresponding to the


Hi Manuel,

to turn on/off the relay, I think that you defined the related pin of the Olimex device as OUTPUT so there is no possibility to read its status with a digitalRead method (only for INPUT pin).

From python scripts, ESP32 internal registers are not accessible; you can build a dedicated class (ex: class Relay) with set() and read() methods protected by a Lock() and an internal flag that holds of the status of the relay.

Hope this can help you :slight_smile:


Hello Matteo,
It is a good idea to create a class with a SET/RSET/READ functions where the status of the outputs is stored. But there is the problem of knowing the initial state: Normally, after a reset of the equipment, the outputs are automatically set to ZERO, but if the reset is produced by a FOTA update, the outputs maintain their status, if they were previously activated, then after the FOTA reset they remain activated. It would be desirable to be able to access internal registers to make sure we know the initial state.


Hi Manuel,

if you want to maintain the same status before and after the reset you can store the status on the flash and read it from the same sector after the reset (you can perform store operation each time the status will change and the system, when will restart after a normal or FOTA reset, will be able to run with the same internal status as before the reset).

Alternatively, you can implement an initialization sequence to configure each pin you need before starting your application where you can force in a particular state/condition your system to be sure that in every moment you know the internal state.

Let me know if this can help you :wink: