Not enough pins?

Maybe you have an idea to solve my current problem. I just faced it.

I need 5 digital pins for different sensors (dht22, ds18b20…). 2 digital pins (d0, d1) for I2C communication. So for, we have covered D0-D6.

I also have a SPI screen, following library (and the way I connected it) I have covered from A0 to A5:
A0: RESET
A1: DC/RS
A2: CS
A3: SCK
A4: SDO/MISO
A5: SDI/MOSI

Apart from those pins, I need 4 buttons. I have tested them with 4 digital pins as inputs so I can read the value of each one. But as I see the photon, there is just one free pin, D7. Is it possible to use this pin as analog input? So I can use different resistors for each of my buttons and read the current value to determine the button pressed.

I also see ADC pin but it seems to be just an output pin, is this correct? Could I use for my “1 pin-4 buttons” idea?

Any IC which could have 4 inputs (or more) and provide a digital output in one pin with the button pressed? I guess I just could have 2 possible values in one output but not sure about this.

I have a pca9685 in my I2C port. I have some free outputs there, (6 or so). I think I could modify the tft library so reset and cs pins fo through this IC instead of an analaog pin. What is the use of DC/RS? Could I do the same?

I see those 3 pins are used in pinResetFast and pinSetFast functions (core functions?). I don’t see their code to know what to do here.

The pins A6 (DAC), A7 (WKP), RX, and TX can all be used as digital inputs for buttons. I’d just use those. But if you need even more GPIO inputs, I’d use an I2C GPIO expander, something like a PCA9538. I2C is designed for multiple devices per bus, so you should just be able to connect it with your other I2C devices.

2 Likes

oh, I didn’t know about those pins, then I think it will be ok with them. Which numbers should I use for rx/tx?

I will also check that ic, maybe it is useful in future.

Thank you.

TX and RX can be used with pinMode, digitalRead, etc… For example:

pinMode(TX, INPUT_PULLUP);

If you have multiple DS18B20 sensors you can also attach them to the same pin since OneWire is an addressable bus.

If you want to free up some analogRead() pins, you could move A0, A1 and/or A2 to any other pin and as @rickkas7 said when DAC & WKP are available they are also analogRead()able to multiplex your buttons via voltage dividers.

Just to cover all the bases you can also use a multiplexer like https://www.sparkfun.com/products/13906
To convert 8 discrete signals into 3 pins that can be read as a binary number

@Tims, you would need 4 control pins (3 for input select, one for control) plus one analog input pint to used that device.