Reading from GPIO takes ~80ms #49
Description
When running the following code:
r = Robot()
gpio = r.servo_board.gpios[3]
while True:
gpio.read()
The gpio.read()
operation consistently takes ~80ms to run, meaning GPIO can only read signals at about 10Hz. Looking through the source code, it appears the read() operation is encoding a message as JSON, sending it over to the serial to the ardiuno (where the arduino supposedly has to decode it, do a trivial GPIO read, encode another message), and then sent back to the pi where it's then decoded again.
https://github.com/sourcebots/robot-api/blob/master/robot/board.py#L112-L129
Is there a faster way of doing this? Seems like quite a lot of overhead to just read a pin. We're trying to use rotary encoders but we'd need to read a 250Hz square wave (2 or 3 milliseconds for reading the GPIO) - this would be easy on the Arduino itself or using the Pi's GPIO where a read takes just a few microseconds.
Are there any other solutions that would speed this operation up? Are we allowed to just use the Pi's GPIO and read from that without the expensive overhead?
Thanks,
Mikel