With the help of my testing rig, I was finally able to work on the wireless connectivity of my Automatic Curtains. The electronics already had a communication line in place, so this should just be a walk in the park. Right?
Unfortunately it wasn’t. It felt like a bit of a deja vu. When designing the electronics for my motor drivers, I decided to use PJON as an alternative for I2C. I wrote a post about this 7 months a go, and back then, I already had the feeling this could give me some issues:
… there is a chance I can’t listen for new packets during the movement of my curtains. In this case I can only listen for new packets when the curtain system is idle. Although this isn’t the desired result, it isn’t a real show stopper.
Well, 7 months later I must admit this is a show stopper. It turned out PJON is just to slow for my needs. Or to be fair: the motors demand too much of the Arduino’s controller, resulting in connectivity problems. During the development of the firmware, I ran into a few unsolvable issues:
- I can’t update the motor’s target location while it’s (smoothly) running.
- I can’t broadcast the current curtain position while the motor is running.
- I can’t communicate with any of the other curtains if one of the curtains is sending or receiving data.
All of this was caused by the fact PJON relies heavily on the microprocessor in contrast to the Serial connectivity of the Arduino, which has it’s own UART hardware backing the communication.
So as much as I like PJON, I did need to find a solution. Preferably one that did not require me to redesign the full motor controller. I wanted a solution I could just simply connect to the current controllers. Luckily, I had a small bright eureka moment. If the whole Arduino eco-system uses shields, why couldn’t I just built a shield for my motor drivers?
Just a simple PCB the I could snap onto the Arduino socket which hosts both the Arduino and an ESP8266 Wifi controller. The ESP8266 could be connected to the Arduino using the serial connection, allowing me to keep all the other Arduino pin connections unchanged.
And so I went ahead building my first prototype …
The Arduino is a 5 volt device, the ESP8266 (in this case a WeMos D1 Mini) is a 3.3 volt device. So the only real challenge would be the level shifting. Of course, I could use a proper level shifting IC. But with the lack of such an IC in my inventory, I had to use a more cheap ass solution: a voltage divider using 2 resistors.
Unfortunately, the Arduino and ESP8266 used a little bit too much power for my old school LM7805 voltage regulator. It needed to dissipate to much power and there wasn’t any room for a heat sink. Replacing the LM7805 with a switching voltage regulator solved the issue. Initially I had small custom PCB to test this, but luckily someone informed me about the RECOM R-78E5. A drop in replacement for the LM7805.
And with this issue tackled, it was time to test my level shifter. As you can guess: It didn’t work. Luckily a guy named James Reuben wrote a nice post about this issue. Which brought me to a zener diode solution.
Using my breadboard, I managed to get it working. My Rigol DS1054Z turned out to be a great help in this process. How could I have ever lived without it?
The schematics turned out to be pretty simple. It only needed a 100Ohm resistor and a 3v3 zener diode. Besides the RX and TX lines, I also needed to connect both the 5V and the ground.
To make to programming a bit easier, I added a switch allowing me to disconnect the RT and TX lines. Other than that, the shield was pretty straight forward, using a few stackable header pins.
The weird shape and size allows me to snap it onto the existing motor drivers (with the replaced power regulators).
And with a little bit of kung-fu-coding, it all turned out perfectly!
The software is currently in Proof of Concept state. But with all the Wifi boards up and running I can finally fully focus on the software.
Of course, the shield solution is a bit of a workaround. So when everything is finished, I might try building an ESP8266-only driver board. If I only had thought about that earlier …