I have a project on an UNO that has run out of I/O pins.
I know one answer is to use a MEGA, but what fun would that be...
Devices. [Current assigned pins]
2 wire serial device, clock/data. [2,3]
LED 4 digit Seven segment display that uses 4 lines for CS and 4 for BCD write, and 1 for decimal point
[4,5,6,7-8,9,10,11-12]
1 pulse count device input. [13]
5 buttons. Start, Stop, Up, Down, Mode. [A0,A1,A2,A3, A4]
Now i want to add an 16x2 SPI LCD display. But the SPI needs the pins 10,11,12 and 13....
Any thoughts how to achieve adding in this SPI display?
You need to free up the pins from the other display. SPI pins are built into the Uno and not reassignable.
You could also use SPI to drive a shift register for the LED pins. Then you just need a unique chip select pin for that shift register and one for the display, both share SCK and MOSI.
You might also be able to put all 5 of your buttons onto 1 analogue input pin ...
I'm not sure this will work, but if you had 1 resistor between VCC and A0, and then 5 different value resistors from A0 through each pushbutton to GND, then when a button is pressed, you would get a specific voltage on A0 - effectively 5 potential dividers.
Choose your resistor values to spread out the voltages so maybe you have VCC with no buttons pressed, 4V with button 1, 3V with button 2, 2V with button 3, 1V with button 4 and 0V with button 5.
I guess that if you got it right, you could decode several buttons pressed at once.
I think driving a shift register with SPI would be the way to go. It's gonna be fun. 74HC595 would work. Fingers crossed. They're not rated for high current
I like this animation:
If you want, you can also use a shift in register to read button pushes, double the fun factor
markd833:
You might also be able to put all 5 of your buttons onto 1 analogue input pin ...
I'm not sure this will work, but if you had 1 resistor between VCC and A0, and then 5 different value resistors from A0 through each pushbutton to GND, then when a button is pressed, you would get a specific voltage on A0 - effectively 5 potential dividers.
Choose your resistor values to spread out the voltages so maybe you have VCC with no buttons pressed, 4V with button 1, 3V with button 2, 2V with button 3, 1V with button 4 and 0V with button 5.
I guess that if you got it right, you could decode several buttons pressed at once.
So I took a look at this. See image.
Looks like it might work. I don't know about analog read with some pins set as digital I/O... Guess I can try.
@Qsilverrdc - yes that's what I had in mind. The voltages you've worked out look correct as well. You may have to sample the analogue value more than once to get a best guess of the button pressed.
My most basic analogue electronics escapes me now but you may be able to put a small value capacitor between A5 and GND if you get too much noise.
I'm sure one of the gurus will jump in and suggest improvements.
I will have to learn about shift registers.
I also think I can loose the SPI display and substitute an I2C 20x4 line display.
I will do a re-draw of the circuit and see...
CrossRoads:
You could also use SPI to drive a shift register for the LED pins. Then you just need a unique chip select pin for that shift register and one for the display, both share SCK and MOSI.
Interesting. My LED 7 segment 4 digit is driven by 4, CD4511 latch bcd to 7 seg chips, going to transistor array to drive 9v segments. The display is about 3 inches tall by 7 wide... old technology. Anyway 4 bits select the latch enable and 4 bits for the BCD data. As the program is now, bcd is set then a segment is enabled which loads the bcd data to outputs, segment is then disabled latching the data. Update the bcd data, select next digit, and so on.
So as I understand a 8 bit value is clocked in to the shift register and then latched.
I like the idea of only 3 I/O lines...
This sounds simple enough...will see.
liuzengqiang:
I've done the "analog" keypads in the past with 5-6 buttons in a similar arrangement. I didn't like it. Too much uncertainty and noise.
My feeling as well, given the number of commercial devices I have encountered (MP3 players, video monitors/ TVs, car dashboard) which use this "trick" and become unusable as the "tact" switches accumulate moisture.