Parallel to Serial on Loop

Thread Starter

sc0tch

Joined Nov 6, 2018
64
Hello,

I have a raspberry pi with few GPIO headers to add several buttons to. The project is a raspberry pi monitoring liquid flow out of containers with flow meters. The buttons will be pressed signalling that the container is replaced or refilled. I do not have enough GPIO headers so I am currently using 5 pins for 16 buttons using the posted schematic. Untitled.png
My current approach uses a PCB with a normally open button, when pressed feeds a set of 4 dip switches, and an interrupt signal with diodes in between each output and the button. Each output is pulled low with resistors to ground. The dip switches act as a four bit address for each switch, when the Pi get's the interrupt signal it reads the 4- bit address in parallel, and polls the inputs for 2 seconds, or until the interrupt goes low, if interrupt stays high and the address remains the same for two seconds it performs an action to signal the container is refilled.

This has worked for a while now, but now I want to add a 7 segment display next to each button and therefor i need more GPIO pins. My plan to feed each of these displays is to signal an address to a SIPO shift register from the Pi. The outputs of the shift register will feed AND gates that will use the 4 bit address to close a pair of mosfets corresponding to that address to forward both the clock and the serial data to a SIPO register attached to the display. I have tested this with a couple displays and a smaller version of my gate tree and it works, but i need a couple of pins back from my button bus.

My problem is that the Pi is set to only acknowledge the button press if it holds state for 2 seconds, and I can not figure out how to get a PISO to loop the input. I also tried using a UNIVERSAL shift register or PIPO by making Qa work as a serial output to the Pi and Qd feeding back to S1 to try and loop the data through the register while the Interrupt Output of my button circuit was feed to Vcc on the register and the register receives a clock signal from a 555 circuit. But this doesn't work because S1-S4 are still receiving signal from the button press. I have also considered using a RC circuit to only pulse the signal of S1-S4 but that doesn't seem to be working either.

I'm sure i am greatly overthinking this and there will be a simpler more cost efficient way of handling this problem and any input will be greatly appreciated.
 

geekoftheweek

Joined Oct 6, 2013
1,201
Do you still have your I2C pins available? If so maybe a PCA9532 LED driver or three can run your displays for you... assuming you're not using an already built display. They can run 16 LEDs each and you will be able to use up to 8 before you use up the address pins.

If you have a few more open pins you could also run a multiplexing scheme and switch on and off power to rows of 7 segment displays to add even more...

Another thought.... maybe something along the lines of a SN54HC157 to halve the inputs needed for your buttons.

An one more thought.... is it possible to run a timer in your program on your PI? Gather the switch data at an interval like (100 mSec) and keep track of how long the button is pressed? You could then eliminate the interrupt altogether and base the program on which switch is on at the moment.

I just realized that eliminating the interrupt will make it so you have to use individual switches so maybe not the best idea.

What language is your program? The Qt libraries have a QCoreApplication class that provides a timer function and will run without a window or GUI (if needed).
 
Last edited by a moderator:

MrChips

Joined Oct 2, 2009
30,706
I suggest that you step back for a moment and assess what you want and what resources you have.

How many push buttons do you need?
How many displays do you need?
What functions do you need to perform with these?

How many resources do you have, i.e. number of free GPIO pins?

There are many ways to skin a cat.
 

Thread Starter

sc0tch

Joined Nov 6, 2018
64
Do you still have your I2C pins available? If so maybe a PCA9532 LED driver or three can run your displays for you... assuming you're not using an already built display. They can run 16 LEDs each and you will be able to use up to 8 before you use up the address pins.

If you have a few more open pins you could also run a multiplexing scheme and switch on and off power to rows of 7 segment displays to add even more...
The i2c bus has 2 thermometers on it. Not sure if there's a limit to how much can he on that pin, but bone of the switches or displays are changed to frequently so data bandwith isn't a real concern. Basically I own a restaurant with 16 beer taps. Each tap has a hall effect flow sensor. The displays are 7 segment displays mounted to the beer line with a button to measure 0-9 of how much beer is left in each keg. And a button on each to reset the counter and log that it was changed. Currently the module with the button is connected via RJ45. There are 4 ports for these modules on the main PCB with another plug on the module to chain more to them.

Switch matrix N x M yields N x M buttons for N + M pins.

Another approach is a serial string of Rs from Vdd to Vss, and buttons
that short out R's in a series string, ADC that measures V of the divider.

http://forum.arduino.cc/index.php?topic=20125.0

https://www.edn.com/design/analog/4439796/Read-multiple-switches-using-ADC


Regards, Dana.
Wouldn't that require more pins then the 5 pins I'm using for 16 buttons using a 4 bit address and interrupt?
 
Last edited by a moderator:

danadak

Joined Mar 10, 2018
4,057
You have to work out the error budget for the R tolerance and A/D accuracy.
I think I saw somewhere where 8 or more buttons/pin were possible done
this way, just cannot find the article.

You look at A/D accuracy/resolution, and divider accuracy/resolution, and switch
on state resistance, and calc the minimum detectable V change you can rely on
and worst case error V that occurs for each button activation.

Regards, Dana.
 

Thread Starter

sc0tch

Joined Nov 6, 2018
64
I suggest that you step back for a moment and assess what you want and what resources you have.

How many push buttons do you need?
How many displays do you need?
What functions do you need to perform with these?

How many resources do you have, i.e. number of free GPIO pins?

There are many ways to skin a cat.
Thanks,

I am trying to run 16 Hall effect flow sensors flow sensors, 16 buttons, and 16 7 segment displays, and 2 temperature sensors.

Temperature sensors are over i2c,
flow sensors are hooked up to 16 gpio pins.
1 pin is used to read the clock signal used across the circuit for all the shift registers.
5 pins are used for the 16 buttons.

Now to use the method of controlling the 16 7segment displays I was initially planning to use would require 4 pins. 2 for the addressing shift register and 2 for the shift register controlling the display.

As it stands I only have 2 pins left to add the displays, which I could reduce the 4 I need to 3 by using the main clock to step the shift register controlling the display when it's addressed by the addressing register

You have to work out the error budget for the R tolerance and A/D accuracy.
I think I saw somewhere where 8 or more buttons/pin were possible done
this way, just cannot find the article.

You look at A/D accuracy/resolution, and divider accuracy/resolution, and switch
on state resistance, and calc the minimum detectable V change you can rely on
and worst case error V that occurs for each button activation.

Regards, Dana.
I understand. I'm just thinking that n*m buttons requires n*m pins for this method puts me at a minimum of 8 pins to use(with 8 pins I could currently address 255 buttons). While I'm assuming this would have the added benefit of allowing to differentiate multiple simultanius button presses, my application will never have multiple buttons simultanius pressed.

My current method allows for 2 to the n power of switches per n= number of pins with the drawback of not being able to register multiple simultanious buttons. My goal is to serialise this address or button ID as either a 4 or 8 bit address.

Please correct me if I'm reading your method incorrectly however I've never tried using an analog to digital converter for buttons. Thank you so much!
 
Last edited by a moderator:

danadak

Joined Mar 10, 2018
4,057
I understand. I'm just thinking that n*m buttons requires n*m pins for this method puts me at a minimum of 8 pins to use(with 8 pins I could currently address 255 buttons). While I'm assuming this would have the added benefit of allowing to differentiate multiple simultanius button presses, my application will never have multiple buttons simultanius pressed.
NO, using 8 buttons (if error budget works out) requires 1 pin.

Example for 5 buttons, I ran out of schematic space to do more.

upload_2018-11-12_5-55-56.png

Actually I could have added another switch to the A/D pin which would
force the A/D to read Vdd in this schematic....You have to do the error budget
for the A/D resolution you have and R tolerance. You will wind up having a range
for each switch voltage that A/D will produce. Ranges of switches of course
cannot overlap.

Regards, Dana.
 
Last edited:

geekoftheweek

Joined Oct 6, 2013
1,201
The i2c bus has 2 thermometers on it. Not sure if there's a limit to how much can he on that pin.
Generally speaking up to 126 devices can be on the I2C bus. It's just a matter of making sure each part you add uses a unique address not already used by another device (your thermometers in this case). There are switch ICs that you could use to branch the buss into two or three or more separate buses if need be to cover overlapping addresses. Then there's also a limit to how much wire you can use before the capacitance of the wire starts messing with the signals and causes problems. I believe I've read somewhere along the lines of three meters is about the limit.

You could also maybe use something along the lines of a MCP23009. It would be possible to use one for the buttons and it also has an interrupt pin that if set up and programmed would interrupt your PI when the button is pressed much the same as your current set up. When looking around try "i2c bus expander" for a search and you'll come up with some other options.
 
Last edited:

Thread Starter

sc0tch

Joined Nov 6, 2018
64
Generally speaking up to 126 devices can be on the I2C bus. It's just a matter of making sure each part you add uses a unique address not already used by another device (your thermometers in this case). There are switch ICs that you could use to branch the buss into two or three or more separate buses if need be to cover overlapping addresses. Then there's also a limit to how much wire you can use before the capacitance of the wire starts messing with the signals and causes problems. I believe I've read somewhere along the lines of three meters is about the limit.

You could also maybe use something along the lines of a MCP23009. It would be possible to use one for the buttons and it also has an interrupt pin that if set up and programmed would interrupt your PI when the button is pressed much the same as your current set up. When looking around try "i2c bus expander" for a search and you'll come up with some other options.
I see. The other issue is that these buttons and displays are over an Ethernet line currently with some switches on up to 5m of wire and there are 16 of them.
NO, using 8 buttons (if error budget works out) requires 1 pin.

Example for 5 buttons, I ran out of schematic space to do more.

View attachment 163625

Actually I could have added another switch to the A/D pin which would
force the A/D to read Vdd in this schematic....You have to do the error budget
for the A/D resolution you have and R tolerance. You will wind up having a range
for each switch voltage that A/D will produce. Ranges of switches of course
cannot overlap.

Regards, Dana.
I see, makes a lot of sense, however; will the 24awg wire at about 2-5 meters effect the error margin of this substantialy or should I build the matrix using mosfets instead of switches with the switch closing the transistor to prevent the impedance of the wire and switch from interfering.
 

geekoftheweek

Joined Oct 6, 2013
1,201
I see. The other issue is that these buttons and displays are over an Ethernet line currently with some switches on up to 5m of wire and there are 16 of them.
Ahhh.... that does throw the proverbial wrench in the works.

Some shift registers for the displays and @danadak's idea look promising. Good luck!

How about using a shift register to enable your shift register for the display you wish to change at the moment? Each display's clock and data signals would be tied together with the first register selecting which one on the branch reads the data.
 
Last edited:

Thread Starter

sc0tch

Joined Nov 6, 2018
64
Ahhh.... that does throw the proverbial wrench in the works.

Some shift registers for the displays and @danadak's idea look promising. Good luck!

How about using a shift register to enable your shift register for the display you wish to change at the moment? Each display's clock and data signals would be tied together with the first register selecting which one on the branch reads the data.
That is the current 0lan for the display. One shift register works as an 8 bit address register to feed into some and gates that forwards the clock and data signal to the right shift register! I'm really interested in learning if a much 9r multiplexer could be used in reverse to accomplish this however. By taking a single input and forwarding it to the correct output based on the address register
 
Top