So you are trying to program the Raspberry expansion PINS in Python, for example for this 3D LED Christmas Tree, and you’re getting the error:
GPIO.setup(self.number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Not running on a RPi!
I’m running this on Ubuntu 20.04LTS with a Raspberry 4.
The first thing:
Make sure you have an official Raspberry Pi charger.
Or at least, make sure your USB charger provides enough intensity to power the Raspberry and the LEDs.
The LED power comes from the motherboard and if Raspberry Pi has not enough energy this is not going to work.
My colleague Michela had her tree not working because of the charger was not able to provide enough energy. When she ordered a new charger, it worked like a charm.
Install the base Software
In order to communicate with General Purpose Input Output ports (GPIO) you need to install this Software:
sudo apt install python3-pip python3-gpiozero sudo pip3 install giozero
In order to run the 3D LED Christmas Tree code samples
sudo pip3 install colorzero sudo pip3 install rpi.gpio --upgrade
It may be not required in some cases.
Download the Source code
Run the samples as root
I saw many people stuck, in the forums, because of that.
To work with the LEDs you need to run the samples as root.
Some code examples
To provide a bit of “the whole package” here are some simple examples.
Turn to red the LED’s one by one
from tree import RGBXmasTree from time import sleep o_tree = RGBXmasTree() for o_pixel in o_tree: o_pixel.color = (1, 0, 0) sleep(0.1)
Turn to a different color, sleep, and again
from tree import RGBXmasTree from time import sleep o_tree = RGBXmasTree() a_t_colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] for t_color in a_t_colors: o_tree.color = t_color sleep(1)
Turn off the lights
from tree import RGBXmasTree o_tree = RGBXmasTree() o_tree.color = (0, 0, 0)
Where I used it?
I used it in my Open Source monitor Software CTOP.py in order to show the plugins/extensions capability of it. :)