Some quick notes on how to get a Pimoroni Led-Shim widget working on a Pi3 running Kali Linux.

The Pimoroni install script says that Kali Linux doesn't work with the Led-Shim. Sadly it doesn't say this on the shopping page, so I only found out once I had it in my hand.

But hey, this is Linux, and that's a Python script, I can get this to work, surely!

I think the only reason they've stated it won't work is because they have their installer scripts registered in the Raspbian (and Debian?) package repos, so for any distros based on those, the installer is easy to maintain.

90 degree header attached First up, soldering on a 90degree GPIO header so the shim can sit outside the official Pi3 case. That went well - after a huge faff of removing the original straight-up GPIO header.

led-shim attached After that, attaching the led-shim is laughably simple - it just slides on. No soldering, no messing with pogo-pin alignment, just get it the right way round, line up the pins with the holes and push gently.

I don't know how firm the connection is, because it relies on very slightly deforming the shim board to hold the pins. Also I doubt the connection is rated for many insert-remove cycles. But it's amazingly simple and quick to get up and running - and if it becomes a permanent fixture, I can solder it later.

Top tip for removing old GPIO headers: Resign yourself to destroying the old header, remove the plastic in bits and desolder each pin individually.

Now it's onto the software side of things...

Luckily the Pimoroni guys seem to have a standardised install script for all their widgets, with all the config for an individual widget stated at the top of the script. So we can peek inside the led-shim install script and see what's going on. The important config lines appear to be:

spacereq=50 # minimum size required on root partition in MB
gpioreq="yes" # whether low-level gpio access is required
i2creq="yes" # whether the i2c interface is required
osdeny=( "Darwin" "Debian" "Kali" "Linaro" "Ubuntu" ) # list os-releases specifically disallowed
gitreponame="led-shim" # the name of the git project repo

So, it needs 50MB free, needs GPIO and I2C enabling, we have a GitHub repo to grab from, and they explicitly say Kali isn't allowed << makes rude gestures at that >>

Further down, there are some packages mentioned which look like they may be important...

SMBUS2="python-smbus_3.1.1+svn-2_armhf.deb"
SMBUS3="python3-smbus_3.1.1+svn-2_armhf.deb"
SMBUS35="python3-smbus1_1.1+35dbg-1_armhf.deb"

SPIDEV2="python-spidev_2.0~git20150907_armhf.deb"
SPIDEV3="python3-spidev_2.0~git20150907_armhf.deb"

RPIGPIO1="raspi-gpio_0.20170105_armhf.deb"
RPIGPIO2="python-rpi.gpio_0.6.3~jessie-1_armhf.deb"
RPIGPIO3="python3-rpi.gpio_0.6.3~jessie-1_armhf.deb"

Hmm, are these part of the standard script and get defined for everything, or will we definitely need them for the led-shim widget? Dunno, but I only care about Python3 for the moment, so that halves the amount of stuff to check.

That SMBUS and RPIGPIO stuff appears to be important, but the SPI stuff doesn't appear to be needed for the led-shim, so I'll ignore that unless things go wrong.

Before doing anything else, sudo apt update && sudo apt full-upgrade. That gets me the latest packages. If you haven't updated your Kali this year (2018), you may also need to follow the steps from the Kali website about updating your repo GPG keys.

Just because I'm paranoid, I did a sudo reboot too, but that probably isn't needed.

Finally, on to the first installation step: Getting the hardware and OS talking to each other. Libraries, APIs, examples scripts and so on are things to worry about later.

There are 2 files to be fiddled:

  • /etc/modules tells the kernel which drivers to load. We need to tell it to handle doing GPIO and I2C comms with the Broadcom chip the Pi uses.
  • /boot/config.txt tells the Pi bootloader what hardware config to use. We need to tell it that our kernel will be wanting to talk I2C.

The trickery here is that Kali Linux by default doesn't mount the /boot partition and doesn't make the contents available for fiddling from within the OS (it doesn't have raspi-config like Raspbian). It also doesn't have a config.txt by default, so I'll be creating a new one.

My set of command line scribbles looks like this:

$ sudo bash
root$ nano /etc/modules
root$ mount /boot
root$ touch /boot/config.txt
root$ nano /boot/config.txt

After which I had an /etc/modules which looked like this:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

# added i2c support so we can talk to the LED shim
i2c_bcm2708
i2c_dev

And a /boot/config.txt which looked like this:

# created this file just to add i2c support
dtparam=i2c_arm=on

I could reboot after this to get the bootloader and kernel loaded up with the I2C support, but before I can access them there is some apting to be done, so I'll do that beforehand.

To talk I2C from Python, there are a few packages to be installed. These are fairly low-level Python libraries which the led-shim stuff will expect to be in place. Installing the Python 3 variants of these libraries is nice and simple (praise be to the Debian demi-gods)...

$ sudo bash
root$ apt install python3-rpi.gpio # how to talk GPIO
root$ apt install python3-smbus # how to talk I2C
root$ apt install python3-setuptools # bundle of common installer tools
root$ reboot

I had already attached the led-shim widget. If you haven't - do a shutdown instead of a reboot attach the widget and boot up again

Once the reboot completes, I have a kernel and hardware that are happy to give access to the GPIO pins to talk I2C and a set of Python3 libs which knows how to talk I2C. Time for some Pimoroni code to make use of all that.

You can check the hardware stuff is working properly by doing i2cdetect -y 1. If you get an ASCII-art table with a "75" in it, you're good.

Handily, Pimoroni are nice people and make their code available on GitHub, with a bunch of nice documentation and all. So, for that "living on the bleeding edge" experience, I can just grab their latest code release into a suitable directory and follow their "Development" comments about how to install their library in the right place. Which basically means:

$ cd ~
$ mkdir Pimoroni
$ cd Pimoroni
$ git clone https://github.com/pimoroni/led-shim
$ cd led-shim/library
$ sudo python3 setup.py install
$ cd ../examples
$ python3 rainbow.py &
$ echo 'Look at all the pretty colours!!!'

If you are missing any Python libs that make the setup.py script fail, figure out the right Debian package name and apt install it, then try the setup.py again.

And that's about it. Here's a final glamour shot of it running the rainbow.py example. In the background you can just make out a Pi Zero wearing a Unicorn pHat inside an old spice jar - the green lights mean all my servers are happy.

Some of the examples make use of other libraries (Twitter, hardware monitoring, Numpy maths, etc), but I can install those whenever I feel the need - for now, it's all working and I can start hooking up some of the Kali security scanning tools to the array of pretty lights.

Previous Post Next Post

© Me. Best viewed with a sense of humour and a beer in hand.