How to make the live streaming Christmas Tree Game. // Project


.ctx.Page.Params.thumbnail:images/Tutorial-CTG.jpg

YouTube video: How to make the live streaming Christmas Tree Game. // Project


This video is a follow up to my Christmas Tree live stream. It's pretty easy project and you should be able to make it in a day once you have all the bits.


Design

This project is pretty simple. I had a bunch of RGB addressable LED strips that would display a roaming Santa, there were ten Elves that could throw snowballs. Once Santa was hit he'd leave an Orange smear, but then re-spawn 5 seconds later.
For this project you'll need an SBC, or it could be a laptop it doesn't really matter. I used an UpBoard for this. A Teensy, some LED strips, and a power supply capable of delivering 5v at around 1A or more if you use more LEDs.
If you want to live stream to YouTube, then of course you'll also need a YouTube partner account. I used the excellent OpenBroadcast software to stream, which can stream to many other online streaming services.
How does it work?

I created a website in the cloud… well actually I prefer sheep as they sorta look like a cloud anyway, and placed two PHP files there.

One was the main page called index.php and another called throw.php which would be called when someone clicked on one of the Elf buttons.

The throw php script would connect to my broadband router, which would redirect to an SBC on the local network and issue just one byte, which was whatever snowball someone had just thrown.

The SBC then redirected the TCP connection to the serial port of a Teensy connected by USB which has 5 WS2812 based LED light strips attached.


Prototyping

The LED strips are the basic addressable type. Just be careful that you connect up the right end. Data flows this way through the strip.

Connecting up to a Teensy is simple enough as well. I used Paul Stoffregen's excellent OctoWS library.

Just make sure that you connect up in the right order.
I was a bit concerned about just how much current these strips will draw. So I loaded up a rainbow example sketch. Oh heck. Just two strips was drawing an average of 2.4A. I had 60 LEDs per strip. They wouldn't be able to go any longer I reckon as the very thin flexible track wouldn't be able to hold the current.
Interestingly enough you can ramp down the max current, but there's a point where the green and blue LEDs stop working and you're just left with RED. Around 1A for 120 LEDs was the absolute minimum. Any lower and things get funky.
So I coded up my little Christmas Tree game which I could throw snowballs just by typing in a number using a serial terminal. Just with those LEDs it drew around 100mA. Nice.

Now time to make it more permanent.


Construction

I found a box that would fit the Teensy and marked out some veroboard to cut to size. I used a dremmel with a disc blade, which went through it fairly quickly.
Then trimmed up the sides a bit so it'd fit snugly.

Next to mark out where I'll be cutting the tracks and used a Dremmel ball bit to remove the tracks. Leaving some of the tracks intact to be used for power and ground.
Next you'll need to cut the USB power line on the Teensy. This is important as you don't want to have power being supplied from USB as well as the standalone 5V power supply.

You can double check that you've completely cut it by plugging it in to a PC and it shouldn't appear.

I then soldered the Teensy directly to the Veroboard instead of using header blocks as I wasn't going to reuse it at all.

Since the power and ground lines will potentially carry a lot of current I applied a thick layer of solder to avoid any magic smoke.

Moving on to the LED strips. The ones I bought had a male and female connector on each end, so I cut the far end off on all of the strips, stripped and tinned up the wires, and started to solder each one to the power lines I'd created.
If I was doing it again I'd leave the solder thickening of the power and ground until after I'd soldered everything up.
Next on to soldering up each of the data lines. Make sure you wire up the strips in order otherwise the display will look a bit funny.
and there we have it. all the LED strip connectors wired up.
Next to wire up the power and ground wires to the Teensy. If I was doing this again I wouldn't place the LED strip wires so close to the Teensy 5v pin.
Next on to the power connector. I used a standard Molex type, (as I was intending on using a standard PC power supply which would have plenty of juice), and cut the 12v lines which aren't needed.
I made two holes for the power and ground wires in the case, poked them through
and soldered up to the two power lines I'd created.
I created 5 holes on the side for the LED strip cables to poke out. Then shoved everything in to the case as best I could, making sure that the LED strip wires were in the correct order.

There you go! I neat little package that won't catch fire.


Testing

On to testing! I connected up all the strips and temporarily powered it up from my bench power supply. Current draw was fairly reasonable at around 300mA.
The Teensy appeared as the usual serial device on my Linux PC, so a simple matter of sending commands to the Teensy like this. Poor Santa! Didn't stand a chance.
I was interested to see how much current draw was required when there were lots of dead Santas. It was a fairly respectable 400mA, nothing too strenuous.
So this was the PC supply I ended up using. Fairly basic one that didn't require a 12v load for it to work. Connected it up and powered it on.
Yup looks good. You can see poor old Santa dancing around trying to avoid the Elf snowballs.
The web interface was fairly trivial to create as well. I used JavaScript buttons to load up a PHP script which communicated to my Linux PC.


Installing

Next to install the whole thing onto the Christmas tree. First the UpBoard with Ethernet, power, Teensy USB and two cameras to be used for the YouTube live streaming.
Next arrange the LED strips on the tree
and connect them up to the little black box, then the juice from the power supply.
There you go. Nothing can go wrong! All safely hidden away at the top of a bookshelf.
I attached one camera to a mike stand pointing at the lower half.
and another attached to the bookshelf on a stick pointing at the top half.

Once everything was powered up I logged in remotely to the Up Board and ran an Xdesktop to VNC redirect, which allowed me to see what was going on the desktop…

nohup x11vnc -display :0 -reopen -zeroconf -nolookup -loop </dev/null &

…and the all important TCP port to TTY redirect. Socat is really the Swiss Army Knife tool of choice here.

nohup socat -gx TCP-LISTEN:1234,fork,max-children=10,reuseaddr OPEN:/dev/ttyACM0,b115200,flusho=1,raw,readbytes=1 </dev/null &

This will:

  • listen on TCP port 1234 for connections and redirect input and output to the Teensy serial port.
  • fork - means that for every inbound connection create sub-procss to handle it.
  • max-children - is set to 10 as we only have ten Elves.
  • flushno=1 - will flush all I/O.
  • raw - raw means that we don't want any complicated handshake.
  • readbytes=1 - and this will limit the amount of data to only 1 byte, as that's all we should be getting anyway.
  • The “nohup” will ensure that when I exit from this login the process won't be killed.
  • </dev/null - I'm also further guaranteeing no funny business by redirecting standard input away from the login session. Next on to YouTube live streaming. I used the rather excellent Open BroadCast software. This allows you to combine all sorts of input streams like static images, rotating image files, and video streams.
    First of all you will need to obtain the live stream key from the YouTube Creator Studio
    and place this key here.
    I had to fiddle around with the streaming bit rate as Ozzie Internet is pretty hopeless and I could only really stream at 1Mbit/s. I tried to reduce latency as much as possible, but was still stuck with a 10 second delay. Oh well.
    Once everything configured just click on “Start Streaming” and you're live! Easy!

Running it

I also wrote a quick and dirty perl script that would fire off random snowballs if noone was online.

#!/usr/bin/perl
$|=1;

while(1)
{
    $r=int(rand(9));
    system("echo $r | netcat localhost 1234 >/dev/null");
    print STDERR ("$r\n");
    sleep(rand(8));

    $r=int(rand(9));
    system("echo $r | netcat localhost 1234 >/dev/null");
    print STDERR ("$r\n");

    sleep(rand(32));
}

I could also throw snowballs from my phone as well.

For this I used an app called “SSH Control” which allows you to send arbitrary TCP data to servers.


Summary

So a few interesting stats for you.

Over the course of a week and a bit, around 700 of you threw over 30,000 snowballs.

Unfortunately I forgot to record how many times Santa was hit. So that's going to remain a mystery forever.

Let me know in the comments below if you made one yourself. It'd be great to see how you did it and what mods you made to it.


Mick Hellstrom avatar
About Mick Hellstrom
Hacker. Maker. YouTuber.

MickMake forums