Four almost-free extra digital inputs on the ESP8266 (or other MCU with A-D)!

Hello!

The ESP8266 WiFi module has a single A-to-D converter input that will digitize an analog input voltage between 0 and 1 volt. If you don't need the A-to-D in your project, you can use it to create an additional four (or more!) digital inputs for the ESP8266 (or any other module with a spare A-to-D input).

The scheme is to connect the A-to-D input to a simple R-2R ladder network D-to-A (digital to analog) converter with four inputs. A good introduction to the R-2R ladder can be found here:

Note that you'll need to put a two-resistor voltage divider at the output of the ladder illustrated here to constrain the output voltage to the 1 volt allowable maximum (a trimpot will let you set the limit precisely). And note too that the values of the ladder resistors don't need to be exactly R and 2R. They just need to be selected so that any combination of the four digital inputs will generate a distinctly different analog voltage at the ladder output.

By reading the A-to-D in your code, you can determine exactly which state (high or low) each of the four digital inputs is in.

Trouble with a real R2R ladder is that you must now put every bx in a HIGH or LOW state. Aka, no floating allowed.

But yeah, with a R2R you can disguise between every pin and all it's combinations. But besides that, the ADC as multi input is a pretty old trick.

Thanks for the thought.

It's generally a bad idea to leave any digital inputs outside your MCU floating as the practice can cause some really hard-to-troubleshoot problems. Your MCU will probably pull unused inputs HIGH to prevent such issues -- although in a high-noise environment, I'd advise terminating them properly as well.

Cheers,
Curt

Your MCU will probably pull unused inputs HIGH to prevent such issues

Not on the Arduino it won’t without you doing it in the code shortly after it boots.

B0-3 will have to be 0V or Vcc.

Any offset on an input could result in an error, offset must be kept to a minimum.
SPDT switches make this less of a problem.

You may have to add an amplifier too.

Yes, thanks for the reminder GM. For clarification and completeness (per an ATMEL data sheet for example):

If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode).

I'd be curious to know what sort of problems you've encountered by leaving unused MCU I/O pins unterminated GM, and how you troubleshot them.

I drive the R-2R ladder inputs from standard 74LS logic larryd. This means that the output of the ladder shown in the sketch will swing from about 100mV to 4 V. The trimpot I suggested in my note can be adjusted to reduce this swing by 1/4 for compatibility to the ESP8266 1-volt(max) A-to-D input.

The exact levels read by the A-to-D don't matter, as long as all sixteen different levels can be told apart in your program.

I'd be curious to know what sort of problems you've encountered by leaving unused MCU I/O pins unterminated GM, and how you troubleshot them.

Never do it and never had any problems because of it. But only been playing with the Arduino about 11 years so not much experience yet :slight_smile:

Used a great many MC1408 DAC in the past, no problems.

And R 2R resistor networks.

CurtCarpenter:
I drive the R-2R ladder inputs from standard 74LS logic larryd. This means that the output of the ladder shown in the sketch will swing from about 100mV to 4 V.

Eh? Why on earth would you be using an obsolete logic series with such indeterminate logic levels? This is the 21st century! :astonished:

I pretty much use what I've accumulated over the last fifty years or so, and that includes a lot of TTL and 4000-series CMOS. The advantage of the families is that I've memorized most of the pinouts over the years.

I've attached a photo of one of my 4-bit ESP8622-compatible DAC modules (I think...).

Yes Larry -- I'm sure many of us have used an array of packaged DACs, although I think they would be massive overkill if all you want to do is capture a few more digital inputs. Still, whatever makes one happy or has on hand...

I remember my first commercial unit -- a 12 bit DAC that was made using thick film technology with a laser-trimmed ladder. It cost a fortune -- a few orders of magnitude more than the cost of eight resistors and a trimpot from the junkbox :slight_smile:

The SIP R2R version is reasonably small.

CurtCarpenter:
I pretty much use what I've accumulated over the last fifty years or so, and that includes a lot of TTL and 4000-series CMOS. The advantage of the families is that I've memorised most of the pinouts over the years.

I have a pile of 20 year old LEDs that you could have then! They are an embarrassment as you can't really see them in daylight. The converse is the indicator and particularly, "pilot" LEDs on the Arduino modules which you can't not see; they are in fact, a great nuisance.

Need I say it, but the 74HC series is a direct pin-for-pin replacement of the obsolete 74LS, though you may have to replace all chips at once or use the harder-to-get 74HCT ones as well. On an old Kyokuto FM144-10SXRII this vastly enhances the stability of the synthesiser as it runs so much cooler.

So whether or not you know the pinouts is not germane to this matter.

Electricity prices are inflating these days (well they certainly are in Australia, just kyboshed a Prime Minister) so for example, old computers have to go as their processing power no longer justifies their electricity diet.

CurtCarpenter:
I've attached a photo of one of my 4-bit ESP8622-compatible DAC modules (I think...).

DAC.jpg
Hey! I have some of those resistors somewhere too! They are a problem as well - I could not think of a project where I would actually justify using them! Maybe I keep them in case there is a deserving technology museum somewhere that needs them. :astonished:

And phenolic Vero!

That's great Paul! Whatever makes you feel better about yourself is OK with me!

CurtCarpenter:
That's great Paul! Whatever makes you feel better about yourself is OK with me!

Problem is that most things are not OK with you.