New repository is here: https://github.com/Emilurenius/RGB-Controller/blob/main/README.md
A controller for WS2812b RGB strip on raspberry pi
To set up the lights, run this command in the terminal:
curl -L http://coreelec.io/33 | bash
This command will download all required dependencies and files.
Test if the download was successful by writing these commands:
cd rpi_ws281x/python/examples
sudo python3 strandtest.py
If you get an error saying ImportError: No module named _rpi_ws281x
, follow these steps to fix it:
sudo apt-get install python-dev git scons swig
git clone https://github.com/jgarff/rpi_ws281x.git
cd rpi_ws281x
sudo scons
cd python
sudo python3 setup.py install
sudo pip3 uninstall rpi_ws281x
sudo pip3 install rpi_ws281x
The error should now be gone! Double check by trying to run strandtest.py again. Source:
Now for my part of the script:
When You got everything set up, and strandtest runs fine, you will need to download the newest version of node on your raspberry pi:
with terminal:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
export NVM_DIR="$HOME/.nvm "[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install stable
Then when node.js is up and running on your computer, you are ready to install the github repository. Use your desired way to download the repository, and then open the directory called RGBserver. In here there are some files you have to run, and some files you can use if you want:
- app.js: Webserver for graphical interface (Needed)
- lightController.py: The script that acutally talks to the lights (Needed)
- ButtonController.py: A button controller I made for my own makeshift button. (Optional)
- clapSensor.py: A script taking information from a sound sensor that measured DB. Connected with the digital output. Sends 3.3 volts when DB over certain threshold. (optional)
To start the server, make sure you are in the RGBserver directory, and write this in the terminal: node app.js 3000
The number at the end is the port you want the server to run on. If you want another port, simply change this number. Make sure the server is running by trying to open the website. To open the website, you need to know the IP address of your Pi. You can check that by writing this in the terminal:
hostname -I
The first number is your ipv4 address on your localhost. It should look like this: 192.168.1.124
Your numbers are most likely different
Now that you have the ipv4 address, check that the server is live by writing this in the address bar on any browser with any device on the same internet:
Remember to put in your own ip and port if they are different.
Now for lightController.py: This file shouldn't need any setup, so just open another terminal, and navigate to the same directory. Then write this in the terminal:
sudo python3 lightController.py
Using sudo is very important, since the script needs some access that linux won't give it otherwise in order to interface with the lights.
To start the other python scripts I listed above, simply use the same method as for lightController.py. I will warn you though, those scripts are very experimental, and large changes may occur to them in future updates. I would suggest you use them as inspiration for your own scripts, as they are made specifically for the hardware I have set up.
Have you installed the library used by the script? If not, that might be the issue.
Needed library can be found here: https://github.com/jgarff/rpi_ws281x
If you are not sure if you have downloaded the library, check if the following directory exists: /home/pi/rpi_ws281x
If it's not there, navigate to "/home/pi" in the terminal on your raspberry pi (This is the directory that the terminal opens in) and write the following: git clone https://github.com/jgarff/rpi_ws281x
Now try again. If the script still won't run, create an issue in this repository, and I will do what I can to help you.
index page: This is the main page of the website, and where you will get the control panel for the LED strip.
API page that returns the brightness level currently in use
API page that returns the red value currently in use
API page that returns the green value currently in use
API page that returns the green value currently in use
API page that allows control of brightness and RGB values of the server, and hence the lights.
API page that allows control of what mode the lights are in.
To talk to these addresses, you can use the module called "requests" https://pypi.org/project/requests/
write the following code to send a get request: response = requests.get("http://localhost:3000/br")
Then write this to print out the value returned: print(response.text)
This address can be used to control the brightness and color of the LED ligts. Here are the different queries you can use to control it:
- br: Control brightness in a range from 0 to 100. Values under or over the range may cause a crash for lightController.py
- r: Control the red channel of the LED lights in a range of 0 to 255. Values under or over the range may cause a crash for lightController.py
- g: Control the green channel of the LED lights in a range of 0 to 255. Values under or over the range may cause a crash for lightController.py
- b: Control the blue channel of the LED lights in a range of 0 to 255. Values under or over the range may cause a crash for lightController.py
This is how you can interface with the API through the requests module for python:
response = requests.get("http://localhost:3000/rgb?br=255&r=255&g=255&b=255")
print(response.text)
This will change the lights to white with maximum brightness, and print the response from the API
This address can be used to select a mode that is defined in lightController.py
If you set the mode to one that is not defined, this will not crash the server, or the script.
This is the way you can interface with the API through the requests module in python:
response = requests.get("http://localhost:3000/modes/set?mode=standard")
print(response.text)
This will change the mode to standard, and print the response from the API