ESPHome ESP8266 -- How to allow all pins to be I/O?

I recently bought a 12V 16-channel relay board with a small ESP8266 board attached (photos).

I flashed it with ESPHome after soldering a header to the connections labelled “3v3”, “G”, “T”, “R”, “0”, and “2” – which I correctly assumed are VCC, GND, TX, RX, GPIO0 (to select flash mode) and GPIO2 (not used here). I disconnected it from the relay board and connected it to an FTDI232 board for this operation. I used a separate patch wire to connect GPIO0 to GND. That all worked well. Since it has no known ‘board’ type, it was flashed with the default ‘esp01_1m’.

The board is undocumented, apart from the sales description. It presumably uses 16 of the 17 GPIO pins for output to the relays. (The relay board is sold separately and its sales description says that each relay is operated separately, so I infer that there is no grouping or multiplexing). The layout of the opto-couplers and switching chips appears to confirm this …

My plan was to temporarily configure all the GPIO pins as switches and then determine by experiment which pin operates which relay. However, the default board ‘esp01_1m’ does not allow me to use all the GPIO pins as outputs because some pins are reserved, for flash memory etc.

How can I overcome this restriction?

You can’t get 16 pins from 8266, no matter what. And even if you would some are known to “glitch” on boot, so you’d have unwanted relay triggerings when you power on the board. Either get esp32 or get i/o chip, like MCP23017 - it has 16 outputs, it’s ideal for this situation.
I wish you’d bought relay board with this chip already built-in… is there any chip on the bottom side of esp board?

Those 2 rectangular components next to the optocouplers look suspiciously like I/O expanders. You’d have to figure out how the ESP is wired to those and then find out which model of expander the board is using.

Once you have that info, you can use the appropriate code from ESPHome (either this or this, depending on model)

Ah yes indeed! Thanks.

I assumed it was just power supply (5V to 3V3) but now see that there is indeed a PCF8575TS 16-bit I/O chip! I’m happy with working that – I just need to figure out how it is connected to the ESP8266!

Alternatively, I could just buy an ESP32 as you suggested and connect that to the relay board. No big costs either way!

1 Like

A constructive suggestion, thanks, but I was able to confirm by experiment that the relays operate independently. Grounding a numbered pin on the header strip turns on the relay with that number.

You had the right idea though: there is a PCF8575TS 16-bit I/O chip on the back of the ESP board that I failed to spot.

Yes, i found esp board “a bit suspicious” when i saw that massive connector, connected directly on the relay board…
PCF8575 is suported in ESPHome. Now you only have to figure it out which pins are SCL and SDA (use chip’s datasheet for this).

Note that esp32 also does have some “glitching” pins, so some relays could click at startup using that one, so it’s always better to use I7O chip instead.

1 Like

Naaah…those are just one of ULNxxxx series boosters only. I/O expanders usually doesn’t have current capability, required by relays. especially when relays are 5V.

2 Likes

Can any of you recommend a good online resource for learning more about circuit boards and microprocessors/components? Especially as it pertains to assembling projects like this?

I have some background with electricity and have been a lifelong tinkerer, and there’s a lot of pieces of understanding that I’d love to fill in the blanks for. Just flashed ESPHome yesterday for the first time.

As for the OP, I’m enjoying seeing this process. I’ve looked at making some projects with similar relay boards.

1 Like

Not really. I have been an electronic engineer for some time, so go straight to the datasheets for information.

Setting up ESP Home is not very well documented, so I used a lot of trial and error.

For this particular problem I found this YouTube video particularly helpful

1 Like

I am delighted to say that I got this board working with ESPHome. Since the board may be of wider interest, I post the configuration code below. Add this to the initial configuration file:

i2c:
  - id: i2c_bus
    sda: 4
    scl: 5
    scan: true
    frequency: 50kHz
  
pcf8574:
  - id: 'pcf_85745_hub'
    i2c_id: i2c_bus
    address: 0x27
    pcf8575: true

switch:
  - platform: gpio
    name: 'Relay 01'
    pin: 
      pcf8574: pcf_85745_hub
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 02'
    pin: 
      pcf8574: pcf_85745_hub
      number: 1
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 03'
    pin: 
      pcf8574: pcf_85745_hub
      number: 2
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 04'
    pin: 
      pcf8574: pcf_85745_hub
      number: 3
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 05'
    pin: 
      pcf8574: pcf_85745_hub
      number: 4
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 06'
    pin: 
      pcf8574: pcf_85745_hub
      number: 5
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 07'
    pin: 
      pcf8574: pcf_85745_hub
      number: 6
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 08'
    pin: 
      pcf8574: pcf_85745_hub
      number: 7
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 09'
    pin: 
      pcf8574: pcf_85745_hub
      number: 8
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 10'
    pin: 
      pcf8574: pcf_85745_hub
      number: 9
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 11'
    pin: 
      pcf8574: pcf_85745_hub
      number: 10
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 12'
    pin: 
      pcf8574: pcf_85745_hub
      number: 11
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 13'
    pin: 
      pcf8574: pcf_85745_hub
      number: 12
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 14'
    pin: 
      pcf8574: pcf_85745_hub
      number: 13
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 15'
    pin: 
      pcf8574: pcf_85745_hub
      number: 14
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: 'Relay 16'
    pin: 
      pcf8574: pcf_85745_hub
      number: 15
      mode: OUTPUT
      inverted: true

You can of course change the names to suit yourself. ‘Relay 01’ etc are as they are numbered on the board (and I use two digits because they sort alphabetically in Home Assistant). I will change them later to what I actually use the relays for.

4 Likes

Very nice work. Thanks for the link too!

Ah. That background helps I’m sure. Even that’s a good lead. I’ll try to find some basics of electrical engineering. Even just identifying components one circuit board would probably be useful.

Do you mind if I send you a message would a photo of a bit of a damaged board I’d like to repair to see if it could be salvageable? I’ve thought about posting it here but wasn’t sure what category to put it under.

1 Like

… I found a place to post it. Glad your project worked, I’m looking forward to playing with one of these sometime.

Do you know what you’re going to use it for yet?

1 Like

Yes, the plan it to activate this Victorian servants call indicator box, which has 10 solenoid-operated indicator flags.

I cut the board back from 16 to 12 relays to save space, so it will fit inside the box.

Channels 1-10 will operate the flags with a 1 second pulse; channel 11 turns on a modern LED light inside the box and channel 12 is for a nearby electric bell.
I added input optocouplers (on top, green), so that we can wire the existing doorbell as an input, plus a spare one, just in case.

1 Like