petabite / uPixels

WS2812 RGB LED Strip Controller for MicroPython Enabled Micro-Controllers
https://philipzha.ng/uPixels
MIT License
14 stars 1 forks source link
embedded-systems esp8266 ledstrips microcontrollers micropython rgbled ws2812b

μPixels (microPixels)

logo

Addressable RGB LED Strip controller for MicroPython enabled micro-controllers

Contents

Features

Changelog

Release Changes Date
v2.0
  • Offical release of /execute API
  • add setStrip method
  • New rainbow chase + wipe + sparkle animations
  • Segment length on chase animation
12/31/2020
v1.2
  • New colors section
  • New Christmas lights animation
3/22/2020
v1.1
  • New status LED indicator
  • New startup animation
9/2/2019
v1.0
  • FIRST RELEASE!!
8/12/2019

Screenshots

Animations screen

Colors screen

Requirements

Dependencies

Schematic

The circuit diagram below is one possible configuration for μPixels.

schematic

Some Notes:

Setup

  1. Install MicroPython on your board if you have not already (ESP8266 installation)
  2. Install μWeb by following the INSTALLATION instructions on my repo.
  3. Head over to the releases tab on this repo. Download the source code for the latest version. Copy the μPixels project files to your board using the same method you used to copy the μWeb files. Make sure that you have transferred:
    • uPixels.css
    • uPixels.html
    • uPixels.js
    • uPixels.py
  4. Construct the circuit above (or a variation of it, depending on your board). You may also follow these hookup guides: Adafruit, Sparkfun
  5. Check out the Quick Start section for examples.
  6. Make sure you also have a boot.py for the initial setup of your board(ie: connecting to wifi) and main.py for the μPixels code.
  7. Power up your board.
  8. Navigate to your board's IP address on port 8000 using a web browser to access the UI(Ex: 192.168.100.48:8000)
  9. Enjoy the light show!

Quick Start

Example application using the μPixels user interface:

from uPixels import uPixels

pixels = uPixels(4, 30) # init a μPixels object using Pin 4 and controlling a LED strip with 30 LEDS
pixels.startServer() # start the server that hosts the UI on port 8000

Example application using Animations API:

from uPixels import uPixels

pixels = uPixels(4, 30) # init a μPixels object on Pin 4 that is controlling a LED strip with 30 LEDS

for i in range(3):
    pixels.chase(ms=40, color=(100, 0, 0), direction='right') # do a chase animation three times with delay of 40ms, red color, going right.

pixels.randomFill(ms=150, color=None) # random fill animation with 150ms delay and random colors

See the docs below for usage of all the μPixels animations!


REST API Reference

After running uPixels.startServer(), the following routes will be available at the address and port set when uPixels was initialized(Default: 0.0.0.0:8000).

GET /

Response

Parameters

Ex: To run the rainbow animation(w/ params), send a JSON body like this:

{
    "action": "rainbow",
    "params": {
        "ms": 10,
        "iterations": 1
    }
}

Ex: To run setStrip, which takes a color, send a JSON body like this:

{
    "action": "setStrip",
    "params": {
        "color": {
            "r": 255,
            "g": 50,
            "b": 50
        }
    }
}

Ex: To run clear, which takes no params, send a JSON body like this:

{
    "action": "clear",
    "params": {}
}

Response

Documentation

Objects

uPixels.uPixels(pin, num_leds, address="0.0.0.0", port=8000)

Description

Initialize a uPixels object to control a LED strip with num_leds on pin. Address and port specifies where to host the UI.

Parameters

Attributes


Server Methods

uPixels.setDeviceName(name)

Description

Sets name of device

Parameters

uPixels.startServer()

Description

Serves the UI using the uWeb server on specified address and port


uPixels.app()

Description

Renders the UI template to client


uPixels.execute()

Description

Runs when uPixels receives a POST request from the client and executes the animation from uPixels.animation_map


uPixels.setStatusLED(pin)

Description

Set the pin number for the optional status LED indicator

Parameters

uPixels.toggleServerStatusLED(status=1)

Description

Toggle the status LED indicator

Parameters

Animations API


uPixels.startupAnimation()

Description

Default startup animation played when uPixels is first initialized. Override this method to set a custom animation.


uPixels.chase(ms=20, color=None, segment_length=5, direction='right')

Description

Chase animation going left or right

Parameters

uPixels.fillStrip(ms=25, color=None)

Description

Fill strip animation starting from the first LED

Parameters

uPixels.fillFromMiddle(ms=40, color=None)

Description

Fill strip animation starting from the middle of the strip

Parameters

uPixels.fillFromSides(ms=40, color=None)

Description

Fill strip animation starting from both ends

Parameters

uPixels.randomFill(ms=150, color=None)

Description

Random filling of strip one LED at a time

Parameters

uPixels.altColors(ms=125, firstColor=None, secondColor=None)

Description

Alternating colors every other LED on strip

Parameters

uPixels.bounce(ms=20, color=False)

Description

Bouncing animation of one LED from left to right and back

Parameters

uPixels.rgbFade(ms=20)

Description

Fade of RGB values on whole strip

Parameters

uPixels.rainbow(ms=20, iterations=2)

Description

Cycle of colors in rainbow over entire strip

Parameters

uPixels.rainbowChase(ms=50)

Description

Rainbow chase animation

Parameters

uPixels.wipe(ms=20, color=None)

Description

Wipe animation

Parameters

uPixels.sparkle(ms=10, color=None)

Description

Sparkle animation

Parameters

uPixels.clear()

Description

Clears entire strip


Helper Methods

uPixels.setStrip(color)

Description

Set entire strip to a color

Parameters

uPixels.setSegment(segment_of_leds, color)

Description

Set specified segments of LEDS to a color

Parameters

uPixels.randInt(lower, upper)

Description

Returns a random number between lower and upper(not including upper)

Parameters

uPixels.randColor()

Description

Return a random RGB tuple

Returns

uPixels.wheel(pos)

Description

Rainbow wheel function used in the rainbow animations

Parameters

Additional Resources

Tested on

Special Thanks