I wanted to add on/off feedback and wired remote control to a Livolo switch. Their brain is a PIC16F690, but unfortunately the chip comes code protected, so I had to write this firmware from scratch.
This is work in progress. I plan to use this and I don't want to set my house on fire, so either if you want to study how the switch works internally or fork it to further work on it, I'd love to hear from suggestions or improvements!
Should be easy to work with this, too:
Note that there is no guarantee that buying from these links will get you those versions since they seem to change designs often.
The Livolo switches use a PIC16F690 to detect slight capacitance changes on a glass plate when a finger is pressed against it. The working principle is described in Microchip's AN1101 (recommended read). The differences with regards to the application note are:
Once you flash the PIC, there is no coming back!
The Livolo PIC has its CP bit on, which means its flash is unreadable, and thus you can't make a backup copy of the pre-installed firmware.
Because of this, I recommend replacing the PIC with a blank one. This way you still have a working chip with the original behavior to roll back to.
You need MPLAB X IDE + XC8 compiler. Load up the project, compile and flash.
config.h
contains a few flags that can be finetuned, ie. the trip and release threshold values.
Okay, first off the ground traces of the Livolo board (including PIC's GND) are actually referenced to the live wire. Repeat: GND IS ACTUALLY LIVE, so the challenge here is to be able to talk to a PC without electrocuting yourself.
In order to pull data safely from the circuit there are two options:
I won't go into much detail because you should know what you are doing if you want to play with 220V. But if you want to get serial data out of the PIC or just use an oscilloscope to probe the signals, one option is to isolate the Livolo power from the mains supply.
I used a cheap (150W) car battery inverter powered by a 3S LiPo because that's what I had at hand. You can use an isolation transformer as well. If you reference the PIC's Vss to ground via the scope's alligator clip, the whole board now becomes referenced to the real ground and it's a bit safer to play around with. Just don't touch the live and neutral wires of the Livolo.
I also tried this, but personally I find the battery + inverter easier and safer while debugging.
Anyhow, the idea is to use optocouplers. But apparently in the optocouplers world you can only have two of a) cheap, b) low current, c) fast. I had a few 6N137 at hand so I used that. They are cheap, they are fast, but they swallow too much current for Livolo's puny power supply.
So I had to add a battery to provide the extra oomph to light up the diode of one of the OCs and drive the collector of the other, yuck!
Of course this is only valid for debugging to get data out of the PIC. The battery thing makes this unfeasible for a permanent installation and I'm still looking for other solutions.
Note that I had to bitbang pin RB4 on the PIC for TX out because that PIN is exposed on the empty J6 header along with RX and Vss. That way we have everything we need in J6, which it's through hole and easier to solder on.
If you choose to use the real TX pin, you can track it down to a couple of empty resistor pads, but I found it harder to solder a wire on an SMD pad securely and thus I preferred the bitbang way even if it makes transmission slower.