Normally unless you are a super user you will get the following error message (or something similar) when you try to run a scripts that attempts to modify the Sense HAT display.
The key part of the error message is the bit I’ve highlighted – basically an ordinary user dosen’t have access to the device.
Fortunately there is a relatively easy solution. First we need to create a ‘udev’ rule that will give all members of the ‘video’ group access to the device, then we need to make the user a member of the ‘video’ group. Using a rule means that the permissions will be modified automatically every time the system starts.
To allow ordinary users to make use of the other sensors on the Sense HAT we will also need to install the ‘i2c-tools’ package and make the user a member of the ‘i2c’ group (this needs to be done after installing ‘i2c tools’, otherwise the group doesn’t exist).
To make the changes to the system we need to be running as ‘root’.
First create the new ‘udev’ rule and add the user to the ‘video’ group.
Then install ‘i2c-tools’ and add the user to the ‘i2c’ group.
Finally we need to ensure that the ‘i2c-dev’ module will be loaded when the system boots by checking that it is included in ‘/dec/modules’.
If the ‘i2c-dev’ entry was missing we will need to reboot for the changes to take effect, otherwise we just need to logout and log back in again for the changes in group membership to take effect.
Raspberry Pi is a trademark of the Raspberry Pi Foundation