ESP-12 + Relay board - can I flash it to ESPHome?

I have this 16 channel relay board from ebay, it looks like the one from SainSmart but it’s a 5v one.
The board includes an ESP-12 module with the PCF8575 i/o expander soldered together on a small PCB, it connects right on the 20 pin header of the relay board.

I was planning on desoldering the ESP-12 module off the PCB board then flashing it either with the nodeMCU or a FTDI converter to ESPHome and then try to code it in home assistant. I am having a hard time reading the wiring diagram of the board but if I understand correctly the i/o expander connects to SCL/SDA (GPIO5 and GPIO4?) and VCC + ground?

Will something like this work if I flash it with ESPHome or is there something I’m missing?

esphome:
  board: d1_mini
  name: esp8266-d1-mini-1
  platform: ESP8266
i2c:
- id: i2c_1
  scan: true
  scl: GPIO5
  sda: GPIO4
logger:
  esp8266_store_log_strings_in_flash: false
  level: DEBUG
pcf8574:
- address: '0x21'
  id: pcf8575_1
  pcf8575: true

switch:
  - platform: gpio
    name: "relay 1"
    pin:
      pcf8574: pcf8575_1
      # Use pin number 0
      number: 0
      mode:
        output: true
      inverted: false

  - platform: gpio
    name: "relay 2"
    pin:
      pcf8574: pcf8575_1
      # Use pin number 1
      number: 1
      mode:
        output: true
      inverted: false

Picture of PCB module: https://imgur.com/a/Uv9xtJQ

not as hard as I am having. Where is the diagram?

I don’t have one, I asked the seller on eBay about it but they don’t have one either. Sorry, should have made that clear.

I posted a picture of the PCB on the bottom of my post, but I’m having a hard time tracing the connections.

Use continuity tester and check if GPIO4 and GPIO5 beeps at contacts SDA and SCL. It shouldn’t be that hard… you don’t really need schematic for this since you only need to find those two pins, correct?

When you find those two connections it shouldn’t be any problem running with esphome. I didn’t explore much but it could be that you’ll have to define addresses, since you have two chips on board, if i see correct.

1 Like

Good point to check for continuity. But is it really necessary if I am only flashing the ESP-12 and then soldering it back in its original position? The connections from ESP to i/o expander remain the same, SDA and SCL from i/o should go to GPIO 5 and GPIO 4 of ESP, then I just define the connection in ESPHome, right? I see no other way of connecting it.

The other chip on the back of the board is a voltage regulator.

I just wanted to make sure I’m not missing anything before I start to take apart and potentially ruining a working product.

I would socket it. But why unsolder it at all? Just solder some small wires to the back side of the board to connect to an FTDI.

1 Like

Ok, i asked because there are two 18-pin chips on board, at least on one from your link…

You don’t need to remove nothing - continuity test can be done with all chips and modules inserted, you won’t destroy anything.

1 Like

I am not sure why you assume gpio 4 & 5 are for i2c. Sure that is common, but not necessary. See ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

The ESP8266 doens’t have hardware I2C pins, but it can be implemented in software. So you can use any GPIOs as I2C. Usually, the following GPIOs are used as I2C pins:

  • GPIO5: SCL
  • GPIO4: SDA

Are you sure your board uses PCF8575 expanders ??

The only reference I can find on a board that looks the same uses ULN2803 relay drivers though none of the images I have seen are clear enough to read the chip ID.

OK, found an image of the real (?) Sainsmart board and it has relay drivers.

Aha… those two chips i asked about are ULN drivers… ok, in this case PCF is probably at the bottom of PCB

1 Like

I was wondering if that was possible, didn’t want to risk anything and thought it would be the safer option to take out the board before anything. But thanks so much! That makes it a lot easier.

I can’t find my FTDI converter and I tried flashing it with a nodemcu, but I can’t get it to work. I followed "Brian Lough"s video on youtube with both 100uF and 10uF capacitors but the led on the ESP12 doesn’t blink. So I will be waiting for the new FTDI converter.

Did you remove esp board and checked that chip at the bottom side is indeed pcf8575? Just to be sure…

I see that on esp module there are pins 3V3, G, T, R, 0 and 2. It’s all you need for flashing. Solder wires to pins G, T, R and 0. Connect: pin G to FTDI ground, pin T to pin Rx and pin R to pin Tx of FTDI. Hold pin 0 to GND while powering the board (use power supply 12V or 5V on blue connector). That way you’ll enter programming mode.
If you didn’t find sda/scl pins with beeper then some trial/error will be needed… you can’t burn anything by trying… but i’d still rather find them. Scl pins on PCF8575 is pin 22 and sda is pin 23 (on ssop casing). You can find esp01 pinout on google to see where gpio4 and 5 are. Then just “beep” them to check out.

1 Like

It was not necessary to remove the ESP12, the pcb module had two sides it was on the opposite side of the ESP. I got the FTDI converter now, but I must have ruined the ESP12 module while trying to flash it with the nodemcu because the it won’t flash and the led on it is dead.

Luckily I ordered a PCF8575TS module at the same time. I hooked the relay board up to 5V 2a power supply, and powered the nodemcu and pcf module off the relay board.
1 issue I’m having is that the i2c address of the pcf module keeps changing, I thought it was supposed to be 0x20 but I’m getting 0x21-0x25. There are solder pads under the pcf module (a0-a1-a2) but I’m not sure what the address should be set to? I can change state of individual relays for a minute before the address of the pcf changes.
2 issue is that after connecting more than 10 relays it seems to stop connecting all together, I can’t switch state on any relay suddenly, this seems like a power supply issue to me but shouldn’t 2a be enough for this application?

Thanks for the help guys! I didn’t want to start a new thread as it’s kind of the same subject but someone let me know if I’m wrong

It doesn’t really matter which address you have set if you have only one module. The main point is that A0-A1-A2 must be polarized: either tied to GND or to +Vcc, so make sure you have that - either directly or via resistor.
2A should be more than enough for more than 10 relays, i agree. Try to measure voltage when energizing relays to see if it drops…that should indicate….bad supply…?

1 Like

I tried soldering A1-A2 pads first and now A0-A1-A3 but the voltage regulator on the PCF8575 module is burning up now. Which pads am I supposed to solder exactly?

Here is a look on the back of the PCF8575 module.

Edit: Also I forgot to mention about 2 seconds after power up all leds on relay dim and the relay board starts making a constant low volume buzzing noise.

From pics i see that neither of address pins are connected to anything, that’s why address floats. For each address pin: solder either left and center, or right and center pad. Left pads are +Vcc, right pads are GND, center pads are chip inputs. Just don’t connect all three together!

1 Like

Thanks so much for the great help Pavel! My bad I rushed it a bit, now I connected the center and right pads and got 0x20 address and its not floating anymore.

1 Like

hey did you ever got it working with original esp module ? got the same board and struggling to get esp working with relays :frowning:

No, because I think the original esp module that came with the board was defective.
Instead I connected to the board with an Esp8266 and i/o expander. It’s the same concept if you get to flash the original module.
Check out documentation for PCF8574 on esphome.io

Hope that helps :slight_smile:

thanks for your anwser, yeah i can flash original module no problem,
tried :slight_smile:

i2c:

- id: i2c_1

  scan: true

  scl: GPIO5

  sda: GPIO4

pcf8574:

- address: '0x21'

  id: pcf8575_1

  pcf8575: true

switch:

  - platform: gpio

    name: "relay 1"

    pin:

      pcf8574: pcf8575_1

      # Use pin number 0

      number: 0

      mode:

        output: true

      inverted: false

  - platform: gpio

    name: "relay 2"

    pin:

      pcf8574: pcf8575_1

      # Use pin number 1

      number: 1

      mode:

        output: true

      inverted: false

but still no luck, any chance you can review above and let me knowq what i am doing wrong ?:slight_smile: