Pointless Blinking With Python, asyncio, and libgpiod (and a Raspberry Pi of Course)

Jörg Faschingbauer

Playlists: 'glt23' videos starting here / audio

One of my more pointless projects is to blink a configurable set of
programmable patterns on a number of LEDs. This might sound like "hey,
you are reinventing the wheel". I admit I do - I am a notorious
reinventer, and it is fun.

* [Livehacking screenplay](https://www.faschingbauer.me/about/site/work-in-progress/blink/screenplay.html)
* [Proposal text](https://www.faschingbauer.me/about/site/work-in-progress/blink/glt.html)
* [Installation notes](https://www.faschingbauer.me/about/site/work-in-progress/blink/installation.html)

Lets reinvent LED blinking in a live-hacking session, and look into a
number of topics as we go:

* Python is a programming language that most of you know. It is simple
and expressive, thus *fun*.
* Python's ``asyncio`` is a parallel programming technique, similar to
multithreading in its usage, but fundamentally different in every
other respect. At its core, it maps multiple parallel control flows
onto one *single-threaded* event loop. Given that timers are events,
this gives us the possiblity to run multiple LED blinking programs
in one single thread - saving all the context switching and
scheduling overhead that multithreaded programs usually
exhibit. Blinking with less glitches caused by context switch hiccups!
* Ah, blinking patterns. Know what Python decorators are? Closures?
We'll twist our brains and create a ``@program`` decorator,
implemented as a double-closure, and use that to write a number of
amazingly simple blinking programs. Almost like functional
programming.
* Last not least, ``libgpiod``. The way to go for GPIO on Linux.

Download

Embed

Share:

Tags