Changing IO from input to output delay (ESP32)


#1

How long does it typically take to switch an I/O from input to output and vice versa?

pinMode(D0, INPUT_PULLUP)
print(digitalRead(D0))
#TIMER START

pinMode(D0,OUTPUT)
digitalWrite(D0, HIGH)
#TIMER STOP AND RESULT

#2

Hi, I tried to write a simple benchmark in Zerynth:

import streams
import timers

count = 100000
pin = D0

streams.serial()
t=timers.timer()
t.start()

for i in range(0, count):
    pinMode(pin, INPUT_PULLUP)
    digitalRead(pin)
    
    pinMode(pin, OUTPUT)
    digitalWrite(pin, HIGH)

elapsed = t.get()

print("Changed pin mode %s times" % count)
print("Total time: %sms" % elapsed)
print("Average per switch: %.2fms" % (elapsed/count))

Output from my ESP-32:

Changed pin mode 100000 times
Total time: 2455ms
Average per switch: 0.02ms

#3

@a.pitasi, thanks! Seems fast enough for my application :slight_smile: