Tree Lighting

Click Here – to see my latest work in this area, ‘painting a christmas tree’

Pi Zero

We made use of a Pi zero as a controller for the WS2812B LED strips. 15 metres (3 rolls) of these strips were
wrapped around a tree. We made use of a logic level converter to convert the 3.3V output from a Pi to 5V.

IMG_0934

We made use of this excellent library https://github.com/jgarff/rpi_ws281x to actually drive
the WS2812B LEDs, specifically the provided Python API.

We wanted each light to pulse out an ID, to enable us to locate the (x,y) coordinates of each LED. To accomplish this we used
a simple digital format.

Digital Format

We make use of the following data format for the data the LEDs pulse out. We use 16 bits for the preamble, 10 bits for the ID, and 8 bits
for the checksum (which is CRC % 256). We finally encoded the data through Manchester encoding, to ensure at most there are two successive 1s or 0s.

{signal: [
  {name:'preamble', wave: '1111010011001000' },
  {name:'data',     wave: '0000000000' },
  {name:'checksum', wave: '01000111' }
]}

wavedrom

Tree Calibration Video

In the following video you can see the pulses emitted by each of the LEDs, enabling us to determine the ID of an LED at a specific (x,y) coordinate
in the image.

OpenCV

Blob detection

We made use of OpenCV3 via Python3 to perform blob detection. We first thresholded the 720p image frame from the webcam, through the use of the following function call cv2.threshold(frame,200,255,0). We then made use of cv2.SimpleBlobDetector_create(params) to perform blob detection, to find the LEDs. In the following two images, you can see, the first is the original image from the webcam, the second shows blobs circled with a red circle.

The blob detection was performed in realtime from the webcam frames, while the frames where written to disk at 30fps, to enable later processing.

tree_normal

tree_blob

Tree Tagged

tree_label

The image to the left, shows the LEDs, which where successfully tagged, with an ID via our algorithm. We made use of a very simple algorithm to detect data bits from
the 30fps video we captured previously.

For each of the blobs in a frame, we check if a blob has been found within 8 pixels, of the current blob’s (x,y) coordinates, if it has, it is likely the same LED, so we update its (x,y) location, to that of the current blob. We then add the timestamp of the current frame to a list for the LED. If the blob hasn’t been seen before within this fixed distance, we add it.

Once we have successfully processed all frames, we are then able to discern the bits of data for each LED from the timestamps an LED was ‘on’. As we made use of manchester encoding, there can only ever be two ones or zeros next to each other.

We find the differences, between the frame timestamps, for each LED. We then iterate through each of these differences, if the difference < 60, we count the number of sucessive times we've seen a value < 60. If a blob has been present for <= 200ms, we class the LED as being on, and output a single bit. If it has been present for more than this we output two 1's.

Once we have have generated a bitstream for each LED, we then make use of a sliding window to find the preamble which is 32 bits in manchester coding. We then attempt to extract the 10 bit ID, and perform checksum computation on the preamble + ID bits, and compare it to the checksum found from the LEDs bitstream.

Once we have successfully found a valid LED, we log its x,y coordinates and ID

Convert video to lights

firevid

We downloaded a video of a fire, and obtained the colour from the same (x,y) coordinate as the LEDs we detected from the tree.

We then were able to display these colours on a representation of the tree, which you can see below. We also store the these colours for each frame, and store them in a python list, which we are then able to pickle and pass to the raspberry pi to play out on the actual LEDs

fire

Video of tree

Future work

We played around a bit with histogram backprojection to extract colours similar only to a red or green LED, to avoid ever having the LEDs completely off, however more work needs to be performed to represent data through colours.

We also intend to create a full 3D model of the tree, to light all sides of the tree.

Academic Research

This was just a hobby project to play with my WS2812B lights. For excellent academic research in this
area, checkout:


Leave Comment

Error Please check your entries!