Giter VIP home page Giter VIP logo

legacy-rgb-controller's Introduction

!!! This repository is no longer under development, but a new one has been created !!!

New repository is here: https://github.com/Emilurenius/RGB-Controller/blob/main/README.md

RGB-controller

A controller for WS2812b RGB strip on raspberry pi

Setup:

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:

https://stackoverflow.com/questions/53045343/adafruit-raspberry-pi-neopixel-library-throws-error-importerror-no-module-name

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:

http://192.168.1.124:3000

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.

Reasons things might not work:

LightController.py not running:

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.

Server Addresses and what they do:

index page: This is the main page of the website, and where you will get the control panel for the LED strip.

/br:

API page that returns the brightness level currently in use

/r:

API page that returns the red value currently in use

/g:

API page that returns the green value currently in use

/b:

API page that returns the green value currently in use

/rgb:

API page that allows control of brightness and RGB values of the server, and hence the lights.

/mdoes/set:

API page that allows control of what mode the lights are in.

How to use the server API with python script running on the raspberry Pi:

/br, /r, /g, /b:

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)

/rgb:

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

/modes/set:

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

legacy-rgb-controller's People

Contributors

emilurenius avatar

Stargazers

Marcus Osland-Rong avatar

Watchers

Kostas Georgiou avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.