This is a light up, multicolored sign that activates when the user goes live on Twitch, can be controlled by Twitch chat via commands, and can be controlled in person with capacitive touch by utilizing the PSoC 4 Series Pioneer Kit (I'll be referring to the device I used as the PSoC 4100s for short).
I'm not too proud to admit that, like a moth, I am fond of shiny things. Unlike a moth, though, I am willing to spend a bunch of time and effort to make a project that is all about big shiny lights. Combine that with gaming, 3d printing, and fancy electronics you're supposed to poke and prod and we've got too many boxes checked for me to not get excited about the project. This expands on something I've wanted to make for awhile, which is the basic sign that indicates that the stream is live in person because it's not only fun, it is a useful way to give loved ones a heads up that there's a stream running to prevent embarrassing moments. I'm a big fan of giving myself cool ways to interact with gadgets, and giving fun interaction capabilities on Twitch is just fun, so the rest of the idea built itself out. With that, it's time to get into it!
Getting Going with Capacitive Touch (PSoC Setup)I started with getting the PSoC side of things up and running and utilized the PSoC Creator 4.4 software to get things up and running. The device comes with a very nice color selector and two buttons, which is absolutely perfect for what I'm looking to make here. It also comes with an example Color Gamut project, which serves as an excellent starting point for what we're trying to accomplish. Instead of just utilizing the base functionality, though, I altered how the buttons work to give myself a little bit more control.
The color pallet is fantastic, but it can be tricky to get a specific color, particularly because I'm a big dude and my finger press takes up half the pallet. As such, I setup one of the buttons to rotate through a selection of colors. This works by maintaining a color index, such that when the button is pressed, it increments the index until it has gone through each color then goes back to 1.
Similarly, I do still want to control the brightness, as well as be able to turn the LEDs on and off. As such, I used the other button to maintain a brightness index, which goes 0-5. This can be very conveniently utilized by multiplying the index value by 51 to get values 0-255, where 0 obviously turns off the sign.
For the other aspects of the project that we'll get to momentarily, I utilized an Arduino setup to control the LEDs directly and listen for Twitch messages, so the ideal setup to integrate the PSoC device was to forward the input of the device to Arduino via serial messages. I added the TX pin for UART in the pin tab, and added the code for sending the serial messages via UART. This was setup to send the values for Red, Green, and Blue (RGB) coloration from the color gamut, the color index we setup, and the brightness index. Since we've setup the serial messages, we'll know exactly what to look for on the Arduino side. The TX pin is used to transfer information, and the RX pin receives it, so the setup is to use a jumper cable to connect the TX pin of the PSoC 4100s to the RX pin of the Arduino device.
With that, the capacitive touch aspect is functional, so it's time to make things bright and colorful!
Light It Up! (LED Setup)As I'll shoutout in the credit section, I referenced an article by "makeuseof" for setting up the LED strip. It's an ideal setup, because it can put LED strips to use that aren't specifically made for Arduino, which is what I happened to have available. In short, it uses Logic Level N-channel MOSFETs and 10k resistors to put together a simple breadboard setup that can safely connect the LED strip with the Arduino. This also requires a separate 12v power supply. The schematics are included in this project.
I waited until I was confident the project was fully complete before putting on the finishing touches, but it's a lot more fun to rock a custom light-up sign than it is a plain ol' LED strip so I went ahead and put the two together. The sign I used is a 3d printed sign I had designed. Thankfully, I had already printed it, which was more than a little convenient since my printer is all kinds of out of commission due to a tragic blob incident. While a 3d printed sign is cool, if you're following along and that's not your thing, there are plenty of other options for the same general setup using something like foam boards.
Adding the LED strip is just a matter of inserting it into the sign where it isn't directly in view. The LED strip I had was actually so old that I couldn't use its sticky side and had to tape it in place, but this was fine because I could just keep the tape out of sight. It's very satisfying to find purpose for unused components, and I was very happy with how it looked when I plugged it in.
The lights are all controlled via Arduino and the code for this is all included in the project, but the gist is that you give the Arduino values for red, blue, and green to light up the sign. If it's 255 for red, 0 for blue, and 0 for green, it's red at full brightness. However, you can also control the brightness with these numbers. Using the same example, if it's 50 for red, 0 for blue, and 0 for green, it's still red but dimmer. In the code, we retain the values, such that we can determine what color is being utilized such that if we increase the brightness we maintain the color that is currently being shown.
It's Mighty Morphin Microcontroller Time (Arduino Setup)We have the lights, and now it's time for action. At this point, we can use Arduino to listen to serial messages from the PSoC device and update the sign accordingly. We process the messages coming in and use the RGB values to update the coloration. We can use the brightness index multiplied by 51 to create a value of 0-255 and use the logic I described in the previous section to update the LED's brightness. Finally, we'll shortly be delving into adding the Twitch commands, but the color index matches up with the color options I've associated with Twitch chat commands such that as we rotate through the index, it goes from one color to the next.
I normally tend to like seeing how much I can accomplish with cheap parts, but for this particular project I intend to use it long term and continue adding to it and tweaking it indefinitely. As such, I splurged a little bit on the components. I utilized an Arduino Mega, which has the advantage of extra serial ports and the capacity for longer programs. This turned out to not be necessary, but as we'll get to I thought the program was going to be much heftier. I also sometimes have issues with spotty Wi-Fi and want this to be consistent and reliable, so I used an Ethernet Shield. I, admittedly, also just wanted an excuse to try out an Ethernet Shield.
Fun fact, your ethernet cable has to actually work for your Ethernet connection to cooperate. Once the non-functional cable gets thrown into the trash and a good one is used, the setup for Ethernet is quite straightforward (as you'll see with the attached code)! That means that it's time to move onto giving Twitch the power to control the LEDs as well, because, after all, why shouldn't random people on the internet be able to control things in my house?
I've Got the Power! Hey! (Twitch Setup)The first key aspect to this is being able to listen to Twitch Chat messages with Arduino. To do so, you need a Twitch Chat Bot setup to provide a way to get access. You can go to the following URL and click "Register Your Application" to set this up: https://dev.twitch.tv/console.
You'll also want a valid oauth token, and can use something like https://twitchapps.com/tokengen/ to set that up.
Once we're online with Ethernet, we start by connecting to Twitch. At this point, we can send a message in Twitch chat, which doubles as a way to let chatters know that they can use these commands as well as a way to visualize that the code is working. Afterward, we begin listening for messages in Twitch chat. Note: it seemed more straightforward to accomplish this by setting up a continuous loop, so I added in a call to listen for PSoC messages here as well, since it won't be running the main loop during this time.
The standard way to setup Twitch commands is to just use an "!" followed by the command. In this case, I set it up !color <value> and !brightness <value> commands. The code that listens to the Twitch messages looks for these and processes the commands by calling the functions we setup earlier that change the color and the brightness. If it's an invalid command, nothing happens. No harm, no foul.
Since the code is provided and I've already gone through the debugging process, it should just cooperate. However, if you have any issues with any of the client calls, I highly suggest using Postman. It's easy to use and provides very clear error messages, whereas sometimes it can be difficult to see what's going wrong with something like Arduino.
The... Easy Part?? (Stream Status Setup)This still leaves adding the functionality to automatically turn the sign on and off based on the stream status. I was certain this would be one of the easiest parts of the project. After all, we were already making connections to Twitch and messing with the lights in more advanced ways. What could go wrong?
As it turns out, it was disinclined to acquiesce to my request. I received absolutely no response of any kind when trying to make the connection, despite confirming that everything was correct in Postman. My understanding at this point is that this is largely due to the fact that Arduino (or at least the libraries I tried) struggles with SSL and this was indeed an https call.
For science, I put together a quick program in Python and tried it out and it worked right off the bat, as Python does. Thankfully, it was about this time I had a very pleasant revelation. In preparation for this project I had been dabbling in other fun Twitch-related projects and I had very recently built a chat bot that hosts murder mysteries which runs in Python. This meant I had a Python program I fully intended to have running at all times as part of my intended full setup, and I could integrate just a little bit of extra logic into it to announce when the stream is live as well as when the stream ends. I'm aiming to all around have a nice and elegant project, and wanted to ensure this fit the bill. Once I realized that I would be able to delete all the Arduino code I added for this and add a simple extra segment to listen for chat messages and then turn the lights on and off, the functionality of which both exist in the project already, I realized it actually made the overall solution much cleaner. Since I want to provide everything needed for anyone following along to create a fully functional version of this project themselves, I created a simple, generified Python program that can be utilized and modified and have included it in the project. It can either be continuously run on a separate device like I intend to do, or you could utilize something like an esp32, which can run python code.
I modified the murder mystery chat bot to send a message in Twitch chat that says how to use the bot when the stream goes live, and a simple message that says that the stream has ended when it's over. This gives me simple messages to look for that are intuitive for the chat, and keep the chat clean of pointless messages like "the stream has started".
There is one concern you may be considering, which is that Twitch users can use the same messages to trick the Arduino. However, that just turns the lights on and off, which is the same functionality I'm giving them. It's almost like an Easter egg to reward clever chatters. But, if it ever did cause problems of some sort, I can always just modify the Arduino code slightly to look for who sent the message.
The Glam Up (Finalizing the Project)I may or may not have had to google to make sure "glam up" was, in fact, a saying out there. Either way, it's time to make this thing pretty with some finishing touches and cable management.
This started with soldering. The PSoC device is the only one that needs to be accessible for use, since it's how I can control the sign. To do this neatly, I utilized a much longer cable that I could then conceal. Before beginning the process, though, I carved out a little notch in the case for the cable to fit through so that I could reattach the back of the case. Once that was done, I soldered the cable onto the same TX pin as before.
The nuances of the cable management would heavily depend on the setup, but I'll share what I did because I'm quite happy with the result. To be well positioned for the stream, the sign sits atop a box. I carved a hole in the box and fed the excess led strip through it and out the side. I then reconnected the LED strip and moved the Arduino and breadboard to where they sit underneath my desk out of sight. The cables run along the underside of my desk, such that all that is really visible is the sign and the PSoC device.
The finishing touch was attaching a back to the sign to make sure it shines nice and brightly. For this, I just used a thin piece of cardboard that I painted to match the rest of the sign. The difference once the back was added was pretty notable and really made the sign glow nicely.
With that, we're good to go. The sign turns on at the start of the Twitch stream, listens for Twitch commands and serial messages from the psoc device to change the colors and brightness of the sign, and turns off at the end of the stream. Hope you enjoyed the ride, and if you followed along and made this yourself I hope you enjoy your nifty new sign! Have a good one.
Comments