Ambi/Atmo-Light implementation using ATmega328 micro-controller and WS2812b LED strips
Go to file
King Kévin 384cc5e11b add boblight config for atmolight 2015-07-18 12:22:07 +02:00
firmware add buffer message 2015-07-17 10:07:49 +02:00
test-patterns add videos test patterns (generated from pictures using ffmpeg) 2015-07-14 15:51:04 +02:00
README update README for AtmoLight 2015-07-17 13:25:42 +02:00
boblight.conf add boblight config for atmolight 2015-07-18 12:22:07 +02:00
test.rb add atmolight tester 2015-07-17 10:02:04 +02:00
vlc-amtolight-dump.txt cleaning dump 2015-07-17 12:48:14 +02:00

README

project
=======

The CuVoodoo AtmoLight mimics the Philips ambient lighting.
The idea it to have LED on the back to the screen shine one the side with the same color as the border colors displayed on the screen, creating and ambient light.

recipe
======

To implement this I used:
- VLC with the included AtmoLight video filter to ouput the colors to be shown on the LEDs
- an Atmel ATMEga328P microcontroller at 16 MHz (i.e. Arduino Nano 3.0) to control the LEDs and show the values received from VLC over serial
- strips of WS2812B chains LEDs, individually controlled using a data line

The original AtmoLight offers only has 4 channels: top, bottom, left, right.
Each channel correspond to an LED strip, but all LED on the strip will show the same color.
The BlinkyTape LED strip offers 60 LEDs WS2812B LEDs.
To match the 16/9=1.78 aspect ratio of my screen I divided the LED strip in 19 LEDs for top and bottom, and 11 LEDs for the sides, for a close aspect ratio of 19/11=1.73.

Although the LEDs are individually controllable, they will have the same color per side.
To have a more fine grained ambient light VLC comes with several AtmoLight device types, such as fnordlicht, which offers more channels.
See the fnordlich branch for the corresponding implementation.

code
====

firmware
--------

This is the microcontroller (e.g. Arduino Nano 3.0) code.
Use `make` to compile and flash it.

`lib/uart.c` allows to talk over serial.
VLC will send the coloer values over USB, going to the serial UART.

`lib/ws2812b` allow to control WS2812B LED strips.
The data transmission is done implemented in assembly since it is time critical
The LED strips are connected in parallel as follows:
- 11 LEDs on pin D2 (PD2) for the top first LED strip
- 08 LEDs on pin D3 (PD3) for the top second LED strip
- 11 LEDs on pin D4 (PD4) for the left LED strip
- 11 LEDs on pin D5 (PD5) for the bottom first LED strip
- 08 LEDs on pin D6 (PD7) for the bottom second LED strip
- 11 LEDs on pin D7 (PD8) for the right LED strip

`main.c` will parse the UART input data for AtmoLight messages and set the LED colors on the strip.
It will use the AtmoLight channel color values to set the colors on the corresponding WS2812B LED strips.

other
-----

`test.rb` will connect to the microcontroller and run standard tests to see if all is working.

The easiest way to see what messages VLCs AtmoLight (AtmoLight device type) is sending, use 2 USB to UART converter with TX/RX interconnected.
VLC should use the first (ttyUSB0), and you get the data on the other (ttyUSB1).
To set the baurdaute: `stty -F /dev/ttyUSB1 38400`.
To get the data: `xxd -ps /dev/ttyUSB1 > dump.txt`
A summary for diffentes pictures is available in `vlc-atmolight-dump.txt`

limitation
==========

Don't forget to short the reset pin of the microcontroller with 5V to prevent reset when the serial port is open.
Else the firmware will miss the start of VLC's communication while booting.
This will automatically be corrected after some short time though since the firmware synchronises on the AtmoLight message header.

In the current WS2812B implementation setting an LED colors requires 36 us.
Thus setting 11 LEDs (left/right strips) requires 396 us, and 19 LEDs requires 684 us.
Outputting the data to the WS2812B strips requires 48 us for a single LED on all pins/strips in parallel.
For 11 LEDs per strip it requires 348 us.

The AtmoLight protocol uses a baud rate of 38400 bps with 8N1 configuration.
Thus receiving one byte requires 1.0s/(38400bps/(8+1)bits) = 234 us.
Since the ATmega buffers one received byte while the next one is shifted in.
This leaves enough time to ouput WS2812B data, particularly since this code is not interruptable, without loosing an incoming byte.
This also leaves enough time set the color of 11 LEDs.
But this does not leave enough time for setting the color of 19 LEDs.
Thankfully the LED color setting code is interuptable.
The colors will be set, while new data is coming in and saved in the interrupt routine.
A buffer of 2 AtmoLight messages is thus enough to handle setting the LEDs and output the data.

To set the color of all channels VLC sends a 19 bytes AtmoLight message.
Thus the AtmoLight refresh rate is 38400bps / (8+1)bits/byte / 19bytes/frame = 224 fps.
This is faster than any (almost) video frame rate.

Finally the VLC AtmoLight video filter module is only available in VLC <= 2.2.
This module has been removed for VLC 3.0.

links
=====

VLC AtmoLight video filter module README: https://github.com/videolan/vlc/blob/2.2.0-git/modules/video_filter/atmo/README.txt
VLC AtmoLight removal announcement (2015-05-10): https://mailman.videolan.org/pipermail/vlc-devel/2015-July/103679.html
VLC AtmoLight removal (2015-05-10): http://repo.or.cz/w/vlc.git/commit/6713041eebe0c4245de4f78dfeb5effecb797faf
VLC changelog: https://github.com/videolan/vlc/blob/master/NEWS
AtmoLight protocol: http://www.vdr-wiki.de/wiki/index.php/Atmo-plugin
WS2812B LEDs: http://www.world-semi.com/en/Driver/Lighting/WS2811/WS212B/