October 21, 2018

Controlling my NUC's LEDs using Python

Wrapping everything in a Python API

Controlling my NUC's LEDs using Python

Part 2 of a series on messing with controlling NUC LEDs

This is going to be a relatively short post as it's a useful but not a particularly earth-shattering addition compared to the last post.

Last time we left off with a kernel module which allowed me to control the LEDs on my NUC by writing to a /proc file. This is all well and good, but in every program I write to control the LEDs I'd need to track the LED state and parrot it back to the driver along with what I wanted to change... every single time.

For this and DRY (let's be real... laziness) reasons, it's natural to wrap all this up in a Python package so we can forget all about /proc and just think Python. This led me to make the nuc_led Python package which simplifies interacting with the LEDs greatly as you can see below.

from nuc_led import RingLED

ring = RingLED()


ring.set_state({'brightness': 100, 'style': 'blink_fast'})



Note: remember that the user running Python still needs to have write access to /proc/acpi/nuc_led (or whichever file your kernel module is watching).

If you're interested in integrating this control into your Python projects, it can be installed using

pip3 install nuc_led

If you'd like to have a look at the code, you can find it on my Github.

In the next post I'm going to be rambling on about a couple of things I found out while trying my hand at making (well... adapting) my own kernel module.