Multipurpose, Multichannel ADC GPIO Board... thing. For ESPHome

This might be a dumb idea, but lets see.

I have some esp12f relay boards that are great for esphome projects.

One project is my solar hot water controller. I’m using. 4 channel relay board for this to balance available gpio against relays.

I need to control:

  • a pump,
  • tank power,
  • and a relay to swap off controlled load in certain situations.

so one spare relay.

I have minimum 3 thermocouples to track. A PT1000 in the solar array, and a NTC 10K B3950 in the top/bottom of tank. Theres some other ones that would be good to put in the system but those are the minimum.

The esp12E only has one ADC pin. So what to do.

The ESPHome docs on thermocouples points out that you need to have a resistor inline and pull the value off the voltage divider to the ADC pin. So, in order to get more adc pins, I need a muxer. ESPHome already supports the MCP3008 which gives 8 channels on SPI. If we stick with the SPI stuff, theres the MCP23S17 which gives 16 extra digital gpio, which is useful on these gpio restricted boards. We could just throw some resistors on the board with some headers, but to make it more versatile i was thinking of using a set of MCP4261 digipots which theres some code already out there for. again, sticking with SPI. You dont want to run power through every sensor all the time, it can heat up the thermocouples and give bad readings. so you need to be able to swap them on and off. To do this something like a power gate array like L9825TR or MCZ33999EK to do low side switching.

So my thinking is provide 16 analog, 16 digital, 16 digipot and 16 low side switches. That makes a pretty powerful little expander board that can read thermocouples and other analog sensors (like gas sensors, current clamps etc) while doing general digital gpio and being able to drive small components like leds, solenoids etc. on the power gate array might even be able to do something fancy to support multiple supply voltages, since you might want leds at 5v and solenoids at 12v or something. Those power gate arrays can also support some interesting shared pwm functions, so you could drive a bunch of leds at a shared intensity or something.

I’m thinking of just throwing all of this stuff on a jlcpcb board and setting it up with a bunch of headers so it can be wired for each project with jumpers / solder bridges / dip switch arrays or something. I could potentially do something fancy with more gpio expanders to do ‘configurable wiring’ but its probably a bit much. at what point do you just plug in an fpga lol. Plus cost management is a thing, and the boards dont need to be dynamic at run time, just dynamic for each use case at build time.

I could do it all with I2C chips as well, i just started with and stuck with SPI. Might be worth refiguring the chips to save the 2 pins but was working for the parts that are already supported.

For those who actually know what they’re doing, whats the big fatal flaw here? I can see some obvious ones like ‘isnt it easier to have an esp32 dev board and a separate relay array?’. Kinda, kinda not. You still can run out of adc (or otherwise) pins fairly easily. still gotta wire up resistors and its nicer to have it on a board and just configure esphome yaml to get the right settings. Plus these little esp12e boards get nice bonuses like 240v ac or 5-30v dc input and switching, 3.3/5v regulation etc. They’re just great to integrate.

I probably should redo this with I2C, otherwise I have to muck about with spending gpio expander pins for spi device selection. hmmm.

looool chip shortage.

Ok, so digipots are basically not attainable. plus the minimum resistance characteristics mean i need to have a bypass. considering it doesnt need to change on the fly. plus cost wise it would be cheaper to fill the board with actual trimpots although that would be super annoying. probably the sanest move is to throw a couple of common resistors on the board and just jump in the one you want. leave a pad for a custom value.

while the power gate arrays would let higher power components work, it might be a ‘leave a pad for it’ thing. most things i want to do i can do with the gpio expander as a breakout.

so that cuts it down to the adc mux and gpio expander. which makes more sense. consider the esp32 pinout:

Theres a good 16 adc pins on the esp32. its not equivalent because you need the gpio to sink the circuit for each thing, but you could get 8 out of it like that. but these boards are like $8 and an esp dev board is $15 + relay board + power supply etc. So if this expander whatsit can stay under $20ish thats probably a win.

This looks like an ok mux. its not supported by esphome by default, but its pretty close to the ones that are. and those are breakouts $15ea. so should be relatively little code change. It’s I2C to save pins.

This gpio expander is supported by esphome, so thats straightforward.

$12 for the 2 adcs and $3 for the gpio expander. add a few bucks for resistors. i think the rest is just headers/vias. should give 16 channels of ‘general sensing/gpio’ that can be thrown on these boards. If i drop it to 8 channels then it might come in under $10, or close to.

The switch to I2C means we retain as many pins on the controller as possible. on the 8ch relay boards theres precious few so thats worthwhile. Although honestly the 4ch boards are so versatile you’re kinda better off using those and adding dumb relay boards.

hmmmmmm. $20 for the esp32 variant of the board. 8ch adc equivalent.

6 of one, half a dozen of the other.

having an adc/gpio expander module in general is useful. but buying the esp32 version is ‘faster’ in that i dont have to design anything…

Yep I would agree, using a esp32 would make sense. Less hassle and still compatible with esphome