3. Identifying LED Types¶
When you attach your LEDs you may not know the exact LED type they, and if it is a matrix, you may not know the order of the LEDs. Sample code has been given to help you identify both LED type and matrix shape.
3.1. Connecting the LEDs to the PixelPi board¶
WS281x LEDs have three wires which are usually red, green and white. The red wire should be connected to + on a terminal, the white to - and the green to the centre.
Strings and matrices that use the same LED type may be connected together to form longer strings or larger matrices but you should note that LED brightness will diminish the further away from the start they are.
Note: | Only ever connect a 5v power supply to the PixelPi board. Higher voltage will destroy the board, the Raspberry Pi, the LEDs or all three. |
---|
3.2. Strings and Matrices¶
An LED strip, or string, is a set of LEDs on a long, flexible PCB. They come in many different lengths and LED spacing.
LED matrices are a 2D array of LEDs:
3.3. Finding LED Types¶
Once connected to the board, use the following code (in /PixelPiLibrary/examples/string_test.py or /PixelPiLibrary/examples/matrix_test.py if you are using a matrix):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/usr/bin/env python3
import time
from pixelpi import Strip
"""
Change the parameters below until you see the colours indicated on the screen:
terminal = The screw terminal your LEDs are connected to
size = The number of LEDs in your terminal (can be (x, y) for a matrix)
shape = The 'shape' of the terminal.
* `straight` - A led string (default)
* `reverse` - A led string which starts at the opposite end
* `matrix` - a normal matrix where the led order goes left to right. i.e:
1 2 3 4
5 6 7 8
9 . . .
* `zmatrix` - A matrix where the shift in the first row go left to right, the next one
right to left. i.e:
1 2 3 4
8 7 6 5
9 . . .
ledtype = One of the supported terminal types:
WS2812, SK6812, SK6812W, SK6812_RGBW, SK6812_RBGW, SK6812_GRBW, SK6812_GBRW, SK6812_BRGW,
SK6812_BGRW, WS2811_RGB, WS2811_RBG, WS2811_GRB, WS2811_GBR, WS2811_BRG, WS2811_BGR
brightness = The default brightness for all LEDs (0-255).
"""
strip = Strip(terminal=1, size=256, shape='straight', ledtype='WS2812', brightness=40)
try:
while True:
print("Red")
strip.setLEDs(rgb=(255, 0, 0))
strip.showLEDs()
time.sleep(1)
print("Green")
strip.setLEDs(rgb=(0, 255, 0))
strip.showLEDs()
time.sleep(1)
print("Blue")
strip.setLEDs(rgb=(0, 0, 255))
strip.showLEDs()
time.sleep(1)
strip.clearLEDs()
strip.showLEDs()
for led in range(strip.getLength):
print("White: ", led)
strip.setLEDs(rgb=(255, 255, 255), led=led)
strip.showLEDs()
time.sleep(0.25)
strip.setLEDs(rgb=(0, 0, 0), led=led)
except KeyboardInterrupt:
strip.clearLEDs()
strip.showLEDs()
del strip
|
Edit line 34 to set:
- Which terminal your LEDs are connected to.
- The number of LEDs in the string (or matrix size, in (width, height) format))
- The LED type.
- If you are using a matrix, the
shape
must also be set to eithermatrix
orzmatrix
.
To run the code, use the following:
sudo python3 string_test.py
or:
sudo python3 matrix_test.py
Note: | sudo is currently required. |
---|
If the LEDs do not display colours in the order RED, GREEN, BLUE followed by a white moving LED you should change the LED type to one of the following:
WS2812, SK6812, SK6812W, SK6812_RGBW, SK6812_RBGW, SK6812_GRBW, SK6812_GBRW, SK6812_BRGW, SK6812_BGRW, WS2811_RGB, WS2811_RBG, WS2811_GRB, WS2811_GBR, WS2811_BRG, WS2811_BGR
For example, your LEDs may display BLUE, GREEN then all go white. This will not damage them, but indicates you are using the incorrect type. Change the type until the colors are displayed in the right order.
For a matrix, the white LED should move in the same direction for each row. If it does not, swap the shape
between
zmatrix
and matrix
.