Lets you control neopixels from your PC using a board.
Project description
Control your neopixels from your PC!
Installation
pip install neobridge
Setup (board)
To start controlling neopixels directly from your PC, you have to setup your circuitpython board to receive serial commands. This is already programmed in the client.py
script. Copy the code below and paste into your main.py
script on your board so this is run every bootup.
import neopixel
import supervisor
import board
import sys
import time
import json
WAIT_FOR_RESPONSE = -1
SET_ALL = 0
SET_ONE = 1
SHOW = 2
# Replace these if this is different!
PIXEL_PIN = board.GP15
NUMBER_OF_PIXELS = 30
ORDER = neopixel.GRB
neo = neopixel.NeoPixel(
PIXEL_PIN, NUMBER_OF_PIXELS, brightness=1, auto_write=False, pixel_order=ORDER)
neo.fill((0, 0, 0))
neo.show()
serial = sys.stdin
while True:
if supervisor.runtime.serial_bytes_available:
data_in = serial.readline()
data = None
if data_in:
# To prevent errors, data is set to whatever is in sys.stdin. Else, it'll fetch commands.
try:
data = json.loads(data_in)
except ValueError:
data = {"raw": data_in}
if isinstance(data, dict):
try:
command = data['command']
# Easy way of dealing with commands.
if command == WAIT_FOR_RESPONSE:
print('\r\n')
elif command == SET_ALL:
r,g,b = data['r'],data['g'],data['b']
neo.fill((r,g,b))
elif command == SET_ONE:
r,g,b = data['r'],data['g'],data['b']
i = data['index']
neo[i] = (r,g,b)
elif command == SHOW:
neo.show()
except:
pass
time.sleep(0.0001)
Setup (PC/Linux/MacOS)
Now that the board is ready for serial communication, you can now control it from your PC directly. This lets you program a lot of cool lighting effects! The example below creates a 'loading' bar like effect.
from itertools import cycle
from neobridge import Neobridge
import serial
import time
FRAME_RATE = 12 # How many frames per second to run code as.
# You have to provide the serial object.
a = Neobridge(serial.Serial(
'LOCATION OF BOARD',
baudrate=115200,
timeout=0.05,
write_timeout=1), 30)
# Set all LEDs to black (nothing)
a.setall((0, 0, 0))
a.show()
c = cycle(range(0, 30))
for i in c:
a.setone((255, 255, 255), i)
a.show()
a.setall((0, 0, 0))
time.sleep(1 / FRAME_RATE)
Before you can start controlling from PC, you have to enter the location of your board.
- On Windows, this is usually under a name such as
COM3
, this can be different. - On Linux, it looks like
/dev/ttyACM0
- On MacOS, the name looks like
/dev/tty.usbmodem1d12
These names can be different! Make sure to find the right one for the board!
Documentation
a = Neobridge(ser: serial.Serial, n_of_leds: int)
"""
Args:
`ser (serial.Serial)`: Takes a `serial.Serial` object, this is from **pyserial**
`n_of_leds (int)`: Number of LEDs on the board.
"""
neobridge.wait_for_response(self)
"""
*Sends a command to the board to wait for a response.*
"""
neobridge.setall(self, rgb: tuple)
"""
*Sets all LEDs on the board to the given RGB values.*
Args:
`rgb (tuple)`: RGB values to set.
"""
neobridge.setone(self, rgb: tuple, index: int)
"""
*Sets a single LED on the board to the given RGB values.*
Args:
rgb (tuple): RGB values to set.
index (int): Index of the LED to set.
"""
neobridge.show(self)
"""
Sends a command to the board to update the LEDs.
"""
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file neobridge-0.1.0.tar.gz
.
File metadata
- Download URL: neobridge-0.1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.13.2 CPython/3.12.2 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3ed69272f4267230b79a48791d5e8687d29e0bc0be3aa1eab525a7762b3521 |
|
MD5 | 363bf7e1f3bd3e23fba2f6e6bb3cda5b |
|
BLAKE2b-256 | 54edf9e6aef94da29eab7f2004055f5453de4b6d770cad17b8effcdecd1cf9b2 |
File details
Details for the file neobridge-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: neobridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.13.2 CPython/3.12.2 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cbe66391d37350013fcc26f261267b272675f31e1bad6345d172f0d95ca9de1 |
|
MD5 | 09f935e0dfbdba08976f5f98b567c14d |
|
BLAKE2b-256 | 9bcd49ff4dd5a6031deea244c7a20c4a4e445b0c8e37e142039df1c0ecf9e16c |