Testing Out RGB Manual Control

I’ve been thinking about how to control the hamstercage light project, and what is really needed. My first idea was to see if I could control the project via WiFi, perhaps by using an app (via Blynk, likely). However, seeing as Blynk uses a freemium model, I felt reticent to go ahead with it. After all, what if Blynk changes its terms of service? What if what I need takes a monthly payment? What if adding a second user isn’t possible? I don’t like trading ownership for convenience, so I’ve decided to abandon that idea. That did mean I had to thoroughly consider alternative controls.

As I’d considered before, I quickly settled on manual controls. After all, the idea is to automate the hamstercage lights nearly all of the time, with exceptions for when we want to see more clearly into the cage (for cleaning, or finding the hamster). Clearly, we’d be next to the hamstercage when we’d want to have direct control of the lights, ergo having manual controls makes the most sense. Doing a quick read online made me conclude that the usual means of controlling RGB leds manually is using potentiometers. Fortunately, I had a few ones lying around, so I quickly wired something up to test:

Figure 1: The breadboard test of controlling RGB lights with potentiometers

I’m breaking a bit with my usual color conventions here, as I’m using black as ground and orange as 3.3V. The WS2812B take 5V but I figured this would work well for the time being. You may notice that I also don’t have a resistor between the powerline and the WS2812B LEDs right now; that’s firstly because the setup wasn’t working when I started, so I reduced components to see when it would work, and secondly because the 3.3V certainly wouldn’t exceed it’s Vmax of 5.5V in any case.

The ESP32 has a really nice number of ADC pins (which I’ve learned stands for Analogue to Digital Convertor), so I had a bevy of choice to connect the potentiometer to. Essentially, the ESP32 compares the voltage from the middle pin of a potentiometer to 3.3V, and then outputs a value between 0 (for 0V) and 4095 (for 3.3V). Since the WS2812B takes a value between o and 255, it’s a simple case of dividing the value from the ADC pin by 4096/256=16 (The off-by-one programming mistake isn’t catching me here!). That gives me three 8-bit values to put into the RGB LED.

After some uploading problems (I had not connected the ground pin, which apparently was a problem for uploading to the chip), I had a working prototype. This setup managed to control the color decently, though I didn’t seem to get as much color variation as the FastLED library demo gave me. Moreover, the results were a little inconsistent. The cause of both issues would be the potentiometers. Firstly, the values aren’t precise, which of course the FastLED library demo does have, seeing as the values are specified in code rather than by analogue input devices. So, when I’m turning a potentiometer, the numbers go up in rather large jumps. One challenge to overcome, then, is to get a better resolution (for lack of a better word). The second problem I ran in to was that the color seemed to flicker a little, which again I attribute to the potentiometers. The potentiometers I’m using are not quite a comfortable fit in the breadboard, and I suspect that the connection they make is shoddy. I noticed that there was quite some wobble to them, and if I’d touch them, the hue would change.

All in all, then, I’d call this quite a succesful test. I have a proof of concept, in that I know I can control the colors of the LED strip using potentiometers. The follow-up is to get better control. The next test I want to do, however, is to work on the WiFi-side of things, and test out getting the current time from an NTP server. Once I’ve tested that, I’ve established all the ground principles I need to create the hamstercage light project, and I know I can start working on refining all the individual elements of it.

First Experiments with RGB and ESP32

The past few days, I’ve been experimenting with both RGB LEDs and ESP32. I’ve never worked with either before, so I wanted to get some experience with the basic functions before I dove into the more complex task of building the hamstercage lighting.

My first experiment was trying to get the RGB LEDs working. I have a strip of 60 WS2812 RGB LEDs, which are one of the apparently two common types of RGBs. The WS2812 distinguish themselves by having some manner of IC included in the strip, so that there’s a single data line in along with the power and ground, making coding quite easy. The other most common RGB strip also includes a clock signal, so that still seems fairly elementary. To get this working, I hooked it up to my Arduino Uno clone, added the FastLED library, and loaded up the first couple of examples. Everything pretty much worked without a hitch, which was great. About the most complex part was that the examples mostly used pre-defined colors (::red, for example) whereas I potentially want to use a whole host of RGB values. However, one quick online search and that was already solved.

ESP32, however, was a little more tricky than that. My first very practical problem is that the breakout board is just slightly too big for my breadboard. I can only just about fit it on one, leaving a single row of headers for additional pins. Nevertheless, that’s all we need to test the single RGB strip. The bigger issue was trying to figure out the pin-outs of this board. There seemed to be a number of potential pinouts provided online, and they just didn’t seem to work for me. In fact, nothing worked until I switched to a different example – I guess I must have messed something up in the example, causing all my other issues! Once I fixed that, the pin-out diagrams seemed to make sense again, so that was one hurdle taken.

However, somewhere in this testing, I seemed to have messed up one of my ESP32-WROOMs. I’m not too sure what’s going on, but it’s no longer registering on the USB port. However, I’d bought three of the chips (potentially for three separate parts of the cage, though I appear to not need that), so a secondary one took its place. I’m noticing that the problematic ESP32 has a rapidly blinking LED, which may be a hint to its condition. If I press the boot and enable buttons at the same time, I can upload a program again, but as soon as it’s reset, the chip seems stuck again and the LED is back to blinking rapidly. It’s possible that while I was probing the board with my multimeter, I may have shorted something, I’m assuming. However, for now this will remain a mystery.

Having tried out the basics of RGB LEDs and the ESP32, and being able to light the LED strip with any RGB value, I have two of the three fundementals ready to work on my hamster cage project. The last one is a way to control the lights. The most basic option is to provide some physical controls at the cage. This is quite sensible, as there’s no need to control the lights unless we’re at the cage doing something. The second option is to use Blynk. Blynk is some manner of visual app development program that has interface possibilities with ESP32 chips built-in. It seems like an easy way to make an app, but it also comes with a rather limiting fremium model that I’m not a fan of. We have the features that it offers right now, but how long before those become premium features? The last option is to personally write some manner of HTML interface. I’ve looked into it, and making an elementary one doesn’t seem too complex. The most difficult parts (having a slider for the RGB colors, for intance) are already worked out in basic java snippets available on countless forums. I like the home-made aspect of that, though it may make the controls a little less polished.

I’m not too sure what route I’ll end up taking but whichever route it will be, my next step has to be to control the color of the LEDs live in some form or another.

First Time Working with RGB

I did some research on the upcoming challenge of making a lighting system for the hamster cage. I have to admit it was a little bit intimidating, and part of me almost wanted to avoid the challenge. There’ll be a few new elements to this: firstly, I’ve never worked with RGB LEDs before; secondly, I’ve only once actually put a project in a project box, and I wasn’t happy with the results there; thirdly, this will be something I’ll end up plugging into a socket; and, lastly, it’ll be something that needs to be used via Wi-Fi and Android phones. That’s a lot of new things all at once. Part of me wanted to chicken out and buy some pre-made thing that could only do part of what we wanted it to do.

Tracy’s preferred solution for the hamster cage is to have consistent lighting that will mimic some sort of circadian rhythm for the (future) hamster. The cage we built is rather large, and because it’s made of wood it’s also quite dark. On top of that, we’ve put it in a corner away from the windows, which makes it even darker. So, she would like to have a lighting system that mimics daylight in a way, both in color and intensity. However, it will also need to be able to be overriden manually, so that we can put it on a bright white light in case we need to check inside the cage or clean it.

I’ve been trying to do some initial research and discovered that authentic daylight imitation is quite complex, even when simplified. Now, firstly, I’m not intending to mimic actual sunlight here, so I’m already side-stepping issues of infrared and ultraviolet, and the other qualities that actual sunlight has. I’m not looking to grow crops or to take care of fish, so that’s going too far. Even when just trying to imitate the color, however, there’s a deep rabbithole of color temperatures, color perception, white balances, and so on. The minimum we really need is just to have light differ over a 24-hour period. I think I’ll see if I can play a bit with making the light blueish or greenish at night, reddish at dusk, and white at noon.

This will certainly be the biggest electronics challenge I’m tackling to date. It’s scary and exciting at the same time. So, right now, I’m looking at the following rough specifications:

  • The light should illumate the three compartments of the hamster cage
  • The light should be automatically set
  • It should be possible to manually override the light
  • The light should be powered from a socket
  • The light should simulate a day/night rhythm in intensity
  • The light should simulate a day/night rhythm through color
  • The fixtures and cabling should be neatly tucked away
  • The light should be controlled from a distance

We’ll see where we end up with the project.

Exploring ESP32

I recently got three ESP-WROOM-32 Dev Boards in from AliExpress, in anticipation of my next electronics project. A few months back, we built our Syrian hamster a large cage, based on a video by ErinsAnimals (see below for the tutorial we followed).

ErinsAnimals video tutorial on how to build a three-tiered hamster cage, which we built for our Syrian hamster Latte.

Now, this cage is amazing. Before this, we had a terrily small cage for the hamster, which meant she showed all manner of bad behavior. She was stressed and dissatisfied, and needed larger living space. When we moved apartments, we also wanted to give her a more fitting place to live. The cage is amazing, but due due its size, it also blocks quite some light inside. Tracy thought it’d be a cool idea if we could install some LED lighting inside. At its simplest, it is just for us to have light inside to ease cleaning. Potentially, however, we could use RGB lights to even simulate a day/night-cycle for Latte. She gets some from the natural light in our room, of course, but because the cage is built out of wood pieces, it also blocks a lot of light.

So, the lighting part is for me to solve. I figured to have a look at ESP32 uC to see if that can help me solve this problem. It has WiFi capabilities, which would mean I could somehow figure out how to control the lights from our mobile phones, or have it check the time or perhaps lighting values, or something along those lines. I bought three of these from AliExpress, to give me the most flexibility. If I end up with the most expensive solution, I’ll wire up each section of the cage individually; however, it should be quite possible to control the entire cage with just one controller (though Tracy does not want any wires available for Latte to nibble on).

My first challenge will be to figure out how I can program this thing. I see online that there are options to use the Arduino IDE to program the thing, which is likely to be the easiest route. Apparently, the microUSB connector on the board allows me to communicate with it via UART. I also noticed that the board has some familiar pin functions (MISO, MOSI, SCLK), which seem familiar to how I used AVRDUDE to program the ATtiny. However, AVRDUDE is focused on the AVR uC family, so I don’t quite know yet how to approach this. So, step one is learning how to communicate with this board. Step two will be getting a standard blinky example working (Ahh, blink, the “Hello, world!” of the electronics hobby). I look forward to learning more!