It's raining and I'm stuck inside. So I modified the ESP8266 sketch so that I could use an ESP8266 to monitor multiple similar resistive inputs i.e. a group of thermistors, RTDs or a panel of potentiometers.

It uses the digital outputs to energize your resistors in sequence to a common lower divider resistor and read the resulting voltage from A0. Inactive outputs are switched to inputs to put them in a high impedance state. These pins were selected because they tri-state fairly cleanly with high impedance so that they won't throw off the resistance being read. Other pins have LEDs or internal hardware connected that cause them to have significantly lower impedance in an input state.

"High impedance" is relative, but this setup appears to work fine in the 1k-100k range that would match a standard 10k pot or thermistor. Output is not completely linear but "close enough" and this can be corrected in software if desired.

Connect a common lower divider resistor from A0 to ground. Then connect your variable resistors between A0 and D1, D5, D6, D7 and D8. The values are polled asynchronously in rotation every 100ms and can be read from input registers %IW0-4.

D0 is configured as coil %QX0.0 so you can blink the LED, active low. D2, D3 and D4 are digital inputs %IX0.0-3. All are active low with pullups.

Register 5 is used for a keepalive that is incremented on every Modbus message. Since most PLCs (including OpenPLC) freeze the inputs when communications are lost, this is a good way for a program to know if the input state is actually valid.

In OpenPLC's Slave Devices tab, add this device as a generic Modbus TCP device, with 3 discretes, 1 coil, 6 input registers, and 0-0 holding registers.

I have all sorts of uses planned out for this sketch so hopefully others may find it useful as well.
Quote 0 0
This is an awesome project. Thanks for sharing
Quote 0 0