Is it safe to run Inky PHAT screen writes in a separate thread?


#1

Trying to use an Inky PHAT screen for a local display on a small project. Raspberry Pi is looking for “something interesting”. When it detects this condition I want to write some status information to the screen. However, when this happens the Pi also needs to continue running. Using the simple examples in your documentation it works, but the Pi pauses for far too long while the screen updates.

In my case the “something interesting” will happen only a few times per day, so it is not that I am trying to change the display continually - just that I can’t accept the the long delay when a screen change is triggered.

The obvious solution would be to spawn the screen update off into another thread and let it run asynchronously to the main thread. Before diving in to this I would just like to ask - “Is the Inky library thread safe?” and “Are there any ‘gotchas’ I should look out for?”

Thanks.


#2

It’s not thread safe but as long as you don’t mess with the GPIO (or at least not the ones that Inky uses) while the code is doing its thing, you should be fine to stick the update in a thread.

Most of the delay before the exit is actually the update function waiting on the “busy wait” pin to indicate that the display update procedure has finished. It might be a good idea for me just to add a “wait_for_busy_wait” parameter in the update function so you can ask it to return ASAP. There’s would be no harm in doing this if you’re only updating infrequently- and, in fact, just ignoring the busy_wait and sending another screen update works fine anyway.