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.
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.
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.
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!
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
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...).
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.