micropython-micro-gui icon indicating copy to clipboard operation
micropython-micro-gui copied to clipboard

Adds support for I2CEncoder.

Open cameronprince opened this issue 11 months ago • 1 comments

cameronprince avatar Jan 15 '25 07:01 cameronprince

To add to my other comments, these are my thoughts on a driver for an I2C encoder.

  • There is no need to use interrupts. Polling is fast enough and avoids the problems of interrupt context. Note that the pushbutton drivers rely on polling.
  • The driver should run an async loop which periodically (~100ms?) reads the position of the encoder.
  • It subtracts the position from that last read.
  • If the difference is positive it signals the GUI for a forward step, if negative a backward step.
  • A zero difference has no effect.

Such a driver could be quite simple.

My encoder driver is something of a special case in its use of interrupts. This is to reduce the likelihood of a missed edge (even in the presence of contact bounce). The I2C chip handles all this nasty hardware stuff, meaning that long gaps can occur between reads.

peterhinch avatar Jan 15 '25 18:01 peterhinch