Scroll pHAT is a LED display designed by Pimoroni working with Raspberry Pi. The first version contains 11x5 LEDs while a more recent releases of Scroll Phat HD and Mini with 17x7 pixels. Although there are good documentation, set up guides and one-line installers (which don’t work for me), in this tutorial I aim for collecting everything that is required for making it work from scratch.
Although this guide focuses on the above display, the process to set up a very popular 16x2 LCD Display is quite similar.
One reason I’ve made this guide is to have this years later when I’m going to use this display again for something else. Also hoping that it can help others who would like to set something similar up. For similar reasons I’ve created a guide to Spin down HDD in Raspberry Pi.
As an example I am going to set up a clock on the display that is scrolling infinitely.
I am using a Raspberry Pi 2 with a Raspbian based distro (OSMC) installed on it.
Please note that while Scroll Phat HD and Mini are a newer version of this, it requires a different library to make it work (github.com/pimoroni/scroll-phat-hd).
Required items
- Raspberry Pi (any type would work)
- Scroll pHAT
- Soldering kit (unless your display/RPi are pre-soldered)
- Cables (26pin ribbon or Dupont cables)
Soldering
Although most of the Raspberry Pis are coming soldered, there are some (especially some old Pi Zeros, where you need to solder a 26pin connector to the board).
The same is with the Scroll Phat display boards, the old one I have was not pre-soldered.
Since I’m not a soldering expert and wouldn’t like to repeat that is already written, I recommend checking out Pimoroni’s The Ultimate Guide to Soldering.
If you happen to do the soldering yourself, and wouldn’t like to chase your luck by creating a lot of messy solder joints and solder bridges (when two joints accidentally connect together), you can just solder only those pins that are required for Scroll pHAT.
These are:
- GPIO 2
- GPIO 3
- 1x 5v Power
- 1x Ground
Screenshot from pinout.xyz
Shining my (mediocre) soldering skills
If you need to solder, please checkout pinout.xyz for full reference!
Connecting to the Raspberry Pi
You can either connect your pi with a full 26-pin GPIO Ribbon Cable or just connect those four pins that is need for the display with Dupont cables. (I had a bunch of Dupont for my Arduino so I was using those).
Enable I2C
This guide is assuming you have a Raspbian based OS installed on your RPi and you can SSH into it.
Scroll pHAT is communicating over I2C so, that needs to be enabled to be able to make it work. For that we need to edit config.txt
pi@raspberry:~$ sudo nano /boot/config.txt
and add
dtparam=i2c_arm=on
then save the file. Also we need to load i2c-dev
module on boot, you can either do it with
sudo modprobe i2c-dev
or add i2c-dev
to /etc/modules
.
After the above steps reboot your Pi.
Let’s check if the display is connected properly. In order to that let’s install i2cdetect
pi@raspberry:~$ sudo apt install i2c-tools
then execute one of the following two commands to list the connected I2C devices. Should have similar responses:
pi@raspberry:~$ sudo ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 1 Nov 14 19:02 /dev/i2c-1
pi@raspberry:~$ sudo i2cdetect -l
i2c-1 i2c bcm2835 I2C adapter I2C adapter
To check if the connection is proper and everything is working properly, let’s run the following command where 1 should be your device ID is the number that is trailing i2c-
in your results. The result should be similar as below, stating at least one integer number in the resulting sheet.
pi@raspberry:~$ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
If the below sheet only contains --
double dashes, your display is powered, but some of the GPIO pins are not connected.
Install dependencies for running code
Pimoroni has a Python library for Scroll pHAT that is available at https://github.com/pimoroni/scroll-phat. At the README.md
of this repository there are a bunch of ways to install this library (including a one-time installer), but most of these not seemed to work for me, so I’m listing here what worked for me.
sudo apt install python
sudo apt install python-smbus
sudo pip2 install scrollphat
(The above should work with python3
and pip3
as well.)
Let’s clone my source to get a working example:
git clone https://github.com/tomhudak/py-scroll-phat.git
(You can also clone Pimoroni’s repository and use the examples there.)
Now you can navigate to the cloned folder, make your script executable and run it:
pi@raspberry:~$ cd py-scroll-phat
pi@raspberry:~/py-scroll-phat$ chmod +x clock.py
pi@raspberry:~/py-scroll-phat$ sudo python clock.py
The current time should be scrolling now.
Run as non-root
I2C requires root access by default, but you can use bcm2835 devices without root if your user is added to the i2c group.
When you listed the I2C devices above you could see that it belongs to the group named i2c
.
pi@raspberry:~$ ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 1 Nov 14 19:02 /dev/i2c-1
Let’s add your user to the above group.
pi@raspberry:~$ sudo usermod -a -G i2c pi
Make sure to log in again. Now you should be able to run your scripts and i2cdetect
without root permisson (sudo
).
Register service
If you want your Scroll pHAT to display when you restart your Raspberry Pi and even without an active SSH session, you can register your script running as a service.
Let’s start with registering a new service definition in /lib/systemd/system/
.
pi@raspberry:~$ cd /lib/systemd/system/
pi@raspberry:/lib/systemd/system$ sudo nano scrollphat.service
The service file should look like this:
[Unit]
Description=Hello World
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/py-scroll-phat/clock.py
Restart=on-abort
[Install]
WantedBy=multi-user.target
Save the file, then let’s add some rights so that RPi could run it:
pi@raspberry:~$ sudo chmod 644 /lib/systemd/system/scrollphat.service
If that is ready let’s refresh our services, enable our new scrollphat.service
and start it!
pi@raspberry:~$ sudo systemctl daemon-reload
pi@raspberry:~$ sudo systemctl enable scrollphat.service
pi@raspberry:~$ sudo systemctl start scrollphat.service
After all this now you should have a new clock running!
If you want to display something more complex I can recommend my
weather.py
(github.com/tomhudak/py-scroll-phat/blob/main/weather.py) script
that is displaying the current temperature and pollution data for the set city.
Resources
Scroll pHAT (old one)
Scroll pHAT HD/Mini (newer ones)
I hope it helped you kick start your project. I am happy to get feedback or answer your questions if you have any.
Thank you for reading and happy tinkering!