Example 2 – PiGlow

The PiGlow is a piece of add-on hardware for the Raspberry Pi that consists of 18 LEDs interfaced with the SN3218 chip. This chip permits controlling the LEDs via the I2C interface. The chip's 7-bit address is 0x54.

To interface the add-on hardware, the SCL pin is connected to GPIO 3 and SDA pin to GPIO 2; the ground pins and the power supply pins are connected to the counterparts of the add-on hardware, respectively.

The PiGlow comes with a library that comes which abstracts the I2C communication: https://github.com/pimoroni/piglow.

Although the library is a wrapper around the I2C interface for the library, we recommend reading through the code to understand the internal mechanism to operate the LEDs:

PiGlow stacked on top of the Raspberry Pi