Skip to content

Latest commit

 

History

History
135 lines (96 loc) · 3.49 KB

File metadata and controls

135 lines (96 loc) · 3.49 KB

MicroPython P9813

A MicroPython library for P9813 RGB LED drivers.

For example, the Seeed Studio Grove - Chainable RGB LED.

demo

Example

Copy the file to your device, using ampy, webrepl or compiling and deploying. eg.

$ ampy put p9813.py

Basic usage

from machine import Pin
import p9813

pin_clk = Pin(5, Pin.OUT)
pin_data = Pin(4, Pin.OUT)

num_leds = 10
chain = p9813.P9813(pin_clk, pin_data, num_leds, False)

# set the first LED to red
chain[0] = (255, 0, 0)

# set the second LED to green
chain[1] = (0, 255, 0)

# write data to all LEDs
chain.write()

# make all LEDs red
chain.fill((255,0,0))
chain.write()

# turn off all LEDs
chain.reset()

See p9813_examples.py and examples for more.

Parts

#Connections

WeMos D1 Mini Grove Chainable RGB LED
D1 (GPIO5) CI (clock) (yellow)
D2 (GPIO4) DI (data) (white)
3V3 (or 5V) VCC (red)
G GND (black)

If you are chaining multiple LEDs, clock out -> clock in, data out -> data in, eg.

LED1 LED2
CO CI (yellow)
DO DI (white)
VCC VCC (red)
GND GND (black)

Links

Example for BBC micro:bit

Software Setup - mu

  • Download and setup the mu editor.
  • Copy the p9813.py file from this repository into your mu code directory (usually USER_DIR/mu)
  • Create a new file with the code below
  • Flash it to the micro:bit. This will fail, the mirco:bit will display an error message
  • Go into the files section of mu and copy the p9813.py file over.
  • micro:bit will restart and it should work

Software Setup - micro:bit editor

  • go to the micro:bit python editor
  • select Load/Save
  • Unfold the Project Files at the bottom of the pop-up
  • Select Add File and select the p9813.py file from this repo
  • paste the sample code below
  • flash the mirco:bit

Example Script

from microbit import *
from p9813 import P9813

pin_clk = pin14
pin_data = pin0

num_leds = 2
chain = P9813(pin_data, pin_clk, num_leds, True)

# set the first LED to red
chain[0] = (255, 0, 0)

# set the second LED to green
chain[1] = (0, 255, 0)

# write data to all LEDs
chain.write()
sleep(200)
# make all LEDs red
chain.fill((255,0,0))
chain.write()
sleep(2000)
# turn off all LEDs
chain.reset()

Parts:

License

Licensed under the MIT License.