STEP 1 - Disassembly and prep for de-soldering work
The switch has two primary sub-assemblies. The top (white) part which contains the printed circuit board (PCB) that we will need to work on, and the bottom (black) part that contains the 120V AC Mains circuitry and low voltage power supply. We will not be doing ANYTHING inside the black housing.
Flip the switch over and remove the 4 screws (pic with arrows) with a small Phillips screw driver.
The black base separates from the white top. Before you start pulling, realize that there are 8 small pins that connect the lower base to the upper switch frame and PCB. See picture. When you pull, you need to pull straight out and slowly so you do not bend the pins.
We will not be doing ANYTHING with the lower half until reassembly. You can set it and the 4 screws aside (don’t lose the little screws.)
We now need to take the PCB out of the white switch housing. It is held in with 3 even smaller Phillips screws. Once removed, the board will simply fall out of the white housing.
Before we jump into desoldering, lets do a quick orientation on the PCB.
A - this is the Tuya TYWE2S (ESP8285) wifi/microprocessor module. The wifi radio, cpu, flash memory, and input/output circuitry is all inside that metal shield. This is where our ESPHome firmware will all live and where any customization will happen.
B - these four holes are test pads that could be used to re-program the ESP chip. They are in fact connected to 4 of the 6 pads that are soldered down across the front of the board. In the picture they are:
- VCC - 3V3 (Positive 3.3 VDC) power to run the chip
- Ground - common to the whole board (and NOT connected to AC common or Earth Ground)
- RX - The RECEIVE side of the serial (UART) communications TO the ESP FROM your flash connection
- TX - The TRANSMIT side of the serial communications FROM the ESP TO your flash connection
In fact we are not going to use those pad until testing later. But describing here for completeness. The rest of the labeling is just for your education. We will not be doing ANYTHING with any other component on this board.
C - the dimmer level LEDS (green). Controlled by the MCU.
D - the ON/OFF switch. It does not turn the power on and off. It sends a signal to the MCU.
E - the dimmer up/down switches. Same thing. They are just signaling devices to the MCU.
F - the ON/OFF switch backlight. Controlled by the MCU.
G - the MCU - microcontroller unit. This is a custom-flashed chip from Tuya that actually does all the work in this switch. It turns LEDS on and off. It listens to the switches above for commands. It sends signals to the circuitry in the black housing to actually turn the AC Mains on and off and dim the AC lights. It reports back to the TYWE2S the status and listens for requests from the TYWE2S to make changes to the light.
Think of the TYWE2S as the wifi “brain” that allows the Internet of Things to talk to the MCU. The way this switch/board was built, the TYWE2S doesn’t do much other than relay the conversation from the network to the MCU. Not all switches work this way. Some will have the ESP device controlling aspects of the board directly. The MCU is a bit of a black box. We can talk to it from the RX/TX lines and tell it things like “Turn on the light” - but it has to do the work of actually opening or closing the relay. So we are limited in how we can “get in the middle” and do more advanced controls with this switch.
Before we start actually de-soldering, lets talk about WHY we are de-soldering.
In order to “flash” this ESP with a new set of instructions, we need to make 5 connections (not 4).
- Power
- Ground
- RX
- TX
OK - we have all 4 of those right there on the board and could just push some board jumpers into the hole - right?
Well - not so fast. We have to put the board in a “state” that it is ready and willing to be flashed. Otherwise it thinks it is in a conversation with the MCU. AND - if we connect those 4 pins, the MCU will be powered and the two devices WILL be talking to each other.
In order to get in the middle of that conversation, we have to a) shut-up the MCU so it doesn’t talk and b) tell the TYWE2S to be “ready” to accept a new program.
We might be able to accomplish a) by holding one of the pins on the MCU to ground or holding it “high” to 3V3 - but in this case, that doesn’t help us because we need access to a special pin on the TYWE2S that makes it ready to be programmed.
Whether intentional or coincidence - this board has the pad to do that on the back…
Lets take a look at the TYWE2S in detail. And also - lets stop referring to it by its chip name and just call it the ESP as shorthand for the ESP8285 chip that is inside - which is VERY similar to an ESP8266 which you will hear talked about a lot in the IoT world.
Anatomy of an ESP (8285)
(Photo credit - poster Skysoft from this forum.)
A - this is the wifi antenna - which explains the cutout in the main PCB to give better wifi signal strength.
B - front side pads (none of which we will be using for this project - but we must be careful to not create a solder bridge to later)
B1. RST - hardware reset pin. Won’t help us for this project
B2. AD - Analog to Digital conversion port
B3. 13 - General Purpose Input Output (GPIO) #13
B4. O4 - GPIO4
B5. O5 - GPIO5
On the back is the “business” side of the chip we need.
(Photo credit - poster Skysoft from this forum.) I don’t have a “good” ESP dismounted at the moment. Next post will show what a botched desolder job looks like)
- 3V3 - VCC - Positive 3.3V power input
- GND - Ground (logic ground - not earth grond)
- RX - UART0 Receive (the “listening” end of the serial interface with the MCU or our flasher)
- TX - UART0 Transmit (the “talking” end of the serial interface)
- 12 - GPIO12
- 14 - GPIO14
- I05 - GPIO5
- IO0 - GPIO0 (yes - that is an “OH” (O) next to a Zero (0) - and this one is important!
- IO4 - GPIO4
- IO2- GPIO2
- IO13 - GPIO13
- RST - Reset (again)
- GND - Ground (again) and attached to the metal box.
Amazing little bit of kit. An entire microcomputer, memory, wifi radio, and serial modem all smaller than a postage stamp! And also a big pain to work with since it is soldered down completely underneath the board and has very delicate traces and pads.
Why do we have to remove it?
Because we have to have access to #8 above. GPIO0. This little solder pad is the magic to make everything happen. How we will use comes later - but we have to gain access to this pad to do everything else. Before you ask - No, you can’t just drill a hole in the main PCB. No, you can’t somehow slide a wire underneath. No, there is no easy way around this. (Or if you are brilliant enough to figure out how to do this without removing it from the PCB - you shouldn’t be reading this newbie thread!)
If you now feel daunted by the prospects, thanks for reading this far - and good luck with another brand of switch.
But if you want to learn something - or are unaware of the Fallacy of Sunk Costs - or are unaware that you could just take these switches back to Costco (BEFORE you’ve taken it apart and broke it) - FORGE AHEAD. It will be frustrating, nerve-wracking and … oh yeah … fun too!