H801 Wifi in case

H801 Wifi in case

I don’t remember how I found this, but a while ago I ordered one of these modules from china. It’s called H801Wifi, and it’s sold for nine Euros. There’s also an app that controls the lamps from a phone, but I didn’t even bother to test that.

Two years ago I built a project that runs by the name of IRlicht (I was sure that I published it at that time — seems that I still have to). It does almost the same: it controls the brightness of LED strips. My own projekt does that on four channels: RGBW. Red, green, blue and white. This device controls RGBWW, meaning that it would be possible to attach for example a warm and a cold white strip, in addition to the RGB one.

My DIY-one is controlled via infrared remote control. This module is driven by an ESP8266, so it works in a WiFi network. I’m fooling around with a firmware for small WiFi-devices for a while, that communicates with the MQTT protocol. This module would be a great platform to use it on. It’s just questionable if it’s possible to get my own firmware to this off-the-shelf-device…

Turns out: yes. It’s possible. :-)

Flash-jumper set, connected to serial

Flash-jumper set, connected to serial

I’m not the first one to try that. Andreas Hölldorfer did it, and he wrote about it. I didn’t expect it to be that simple. Almost disappointing… ;-)

On the PCB — and thanks to great photos in most of the offering shops I knew that ahead of the purchase — is a well labeled serial interface. And right next to that is a connector that literally wants a jumper to be set on it. When the jumper is set, it’s possible to flash a new firmware over the serial interface. Right from the Arduino IDE. I just connected my USB-serial-interface between computer and the module (without connecting external power to it, I don’t know if that would have damaged anything), and I configured the module in the IDE like this:

  • Board: “Generic ESP8266 Module”
  • Flash Size: “1M (64k SPIFFS)
  • Upload Speed: “1152200”

After connecting RX and TX in the right way, I was able to upload my firmware.

I mentioned to have an almost fully working firmware for my use, based on the excellent Homie for ESP8266 framework. ‘Almost’, because till now it just does RGB, not RGBWW. But the only thing I had to adapt for using RGB on this device instead of my usual hardware were the IO-Pins. The “Generic ESP8266 Module” header file doesn’t know any readable names for the pins, so I had to use the numbers. Andreas Hölldorfer already found out the mapping, though it seems that he’s got a different revision of the hardware. This worked for me:

Pin Function
15 Output red
13 Output green
12 Output blue
14 Output white 1
4 Output white 2
1 Internal LED green / Signal
5 Internal LED red / Power

I like that, after initial flashing the OTA-Update (Over The Air) works. This way, I could already close the box again. All further updates will be uploaded over the air. :-D

This text hasn’t been in the blog in 2006, I took it from my old CMS in 2015.

The device in action.

The device in action.

The USB-LED-Fader is a device to control a number of LEDs via USB. I built it to display the online status of my internet connection, the recording status of my video recorder (VDR), and warnings if the available disk-space is low. You can imagine an endless number of applications for this.

The LEDs are controlled with pulse width modulation (PWM). That way, they are not only on or off, it is possible to control the brightness. Included in the device are a number of ‘waveforms’ that can be displayed through the LEDs. That way, one LED can display some kind of a sine- or triangular wave without any interaction with the controlling host.

Every LED can be controlled individually; each one can display its own waveforms.

You can assign three different waves to every LED. The first two (0 & 1) are ‘eternal’ waves. They are displayed alternating until anything different is required. The third wave (2) is only displayed once; afterwards the device will switch back to alternating between the first two waves.

They are displayed alternating until anything different is required. The third wave (2) is only displayed once, afterwards the device will switch back to alternating between the first two waves.

One wave is described by three parameters: the waveform, the duration for one repetition of the wave and the number of repetitions before switching to the next wave.

This version supports four LEDs. It should be quite easy to change that number to between one and eight. I have not tested any number greater than four, but I can imagine that the load on the controller may be too high to reliably communicate via USB.

There are three parts included in the distribution: The firmware for an ATmega8 microcontroller, a command line client that can be run under Linux, and the circuits needed to build the device.

This project is based on the PowerSwitch example application by Objective Development. Like that, it uses Objective Development’s firmware-only USB driver for Atmel’s AVR microcontrollers.

Objective Development’s USB driver is a firmware-only implementation of the USB 1.1 standard (low speed device) on cheap single chip microcomputers of Atmel’s AVR series, such as the ATtiny2313 or even some of the small 8-pin devices. It implements the standard to the point where useful applications can be implemented. See the file “firmware/usbdrv/usbdrv.h” for features and limitations.

Building and installing

The circuit contains only a few standard components. There's no special USB-chip involved.

The circuit contains only a few standard components. There’s no special USB-chip involved.

The installation is described in the documentation.

Usage

Connect the device to the USB port. All LEDs should flash up to indicate that the device is initialized.

Then use the command line client as follows:

When using the set function, it is possible to define several waves at once. You simply have to give the parameters for all waves. See examples below.

Parameters

  • ledId: ID of the LED (0-n, depending on the number of LEDs in your circuit).
  • waveId: ID of the wave (0-1: constant waves, 2: override).
  • waveformId: ID of the waveform (0-31: brightness, 32-37: patterns). For a reference to the patterns, use the show function.
  • periodDuration: Time in sec/10 for one repetition of the waveform. A value of 0 can be used to reset the wave.
  • repetitionCount: Number of repetitions before switching to the next wave. A value of 0 can be used to repeat this forever.

Examples

Get the status of all LEDs

This will result in output similar to this:

In this output, the values curvalue, curpos, nextupd and updtime are for debugging purposes only. They shouldn’t be of interest to the common user. The meaning of the other values should be clear.

Set the first LED to keep a moderate brightness

So, on LED 0 the wave 0 is set to waveform 15. It will stay there for one second and will be repeated once before switching to the next wave. There is no next wave because we didn’t define one, so this waveform will stay forever.

Now set a second wave on the first LED, a little brighter than the one before

This is wave 1 on LED 0. Waveform 25 has been defined as a constant level of brightness. After setting the second wave, it will alternate with the first one after every second, because both waves have the same duration and the same number of repetitions.

Set a third wave on the first LED

This sets the third wave (wave 2) on the first LED. Waveform 36 is a nice sine-like wave, so the LED starts to fade. One period of the fading takes 2 seconds, it is repeated for 5 times. Since this is the third wave, after the repetitions the LED returns to alternating between wave 0 and wave 1, this wave is discarded.

Set multiple waves at once

This will set all of the above waves at once. Thus, the first LED will first fade the sine-wave five times, then start alternating between the two brightnesses in one-second-rhythm.

Clear the first LED

This will clear all three waves on the first LED.

Reset the device

All LEDs will flash once, to indicate that the device is reset and the LEDs are working.

Show a waveform on the screen

This will lead to an output like the following:

Keep in mind that the width of the displayed wave corresponds to the length of the waveform. If you display a very simple one like the constant brightness levels (0-31), the length is 1. Therefore only one column is displayed.

Test the device

This function sends many random numbers to the device. The device returns the packages, and the client looks for differences in the sent and the received numbers.

Drawbacks

I know that I could have soldered that in a more beautiful way... ;-)

I know that I could have soldered that in a more beautiful way… ;-)

As mentioned above, controlling the PWM for several LEDs is a lot of work for one small microcontroller. So is speaking the USB protocol. Together, these result in a lot of load on the device, so the communication with the device is not 100% reliable. More than 99%, though, at least in our tests.

SO BE WARNED: You should not use this device to control the state of your nuclear reactor. If you intend to use it in that way despite of this warning, please let me know… ;-)

Thanks!

I’d like to thank Objective Development for the possibility to use their driver for my project. In fact, this project wouldn’t exist without the driver.

And I’d like to give special credit to Thomas Stegemann. He wrote the PWM-stuff, and I guess it would have been nearly to impossible to me to write the rest of the project without his help since C isn’t my natural language. ;-)

About the license

Our work – all contents except for the USB driver – are licensed under the GNU General Public License (GPL). License.txt is a copy of the GPL. The driver itself is licensed under a special license by Objective Development. See firmware/usbdrv/License.txt for further info.

Download