Re: GPIO Interface hardware & Power Maintenance

340 views
Skip to first unread message

Luke Weston

unread,
Sep 4, 2012, 6:38:33 AM9/4/12
to connected-commu...@googlegroups.com


1) I have some buttons that I am using to control my RasPi (in the car playing MP3's) via the GPIO pins, the issue is that I am using momentary switches to achieve this and as a result then 'check' times need to be quick low in order to not 'miss' that the button has been pressed. It was suggested that a 'latch and release' type of circuit would be a good solution to this, however I have absolutely no idea where to even start with this.
What I need assistance with with building a circuit that:
  • When a button is pressed 'holds' that the button has been pressed (up to 4 buttons)
  • Uses another GPIO output to 'release' the button press for all buttons
You might use a flip-flop for this, where the pushbutton press is connected to the set input of a SR flip-flop, so it turns on (and stays on) once set, until it is reset by the Raspberry Pi with the GPIO output from the Pi connected to the reset input of a SR flip-flop.

Alternatively, if you want to have a good number of buttons without using up all your GPIOs, you might have an external microcontroller, like an AVR, which handles the more "time critical" task of handling the buttons, then it communicates the button information back to the Raspberry via UART or SPI or something.

Or, alternatively, how about a cheap mass-market PC USB HID input device such as a keyboard or touchscreen, trackpad, trackball etc, or a hacked keyboard controller connected to a few pushbutton switches, connected to the RPi's USB port?
 
2) The second circuit that I need some assistance with is a power circuit, as I am using the RasPi in my car I need some kind of 'trigger' curcuit that is able to (a) turn the RasPi on (apply power) using a battery to supply power (so switching the battery source on) then once the car is turned off flag (via GPIO 3v3) to the RasPi that a shutdown is required so that the system can be gracefully halted (I can handle the software side easily, it is the hardware that I am having issues with)
The basic idea is:
  • Car Turns On --> 'Activates' the power line from the Battery to the RasPi (Battery charged from Car Power)
  • Car Turns Off --> Power from the battery remains on, GPIO signal sent to RasPi Header, RasPi Halts, 'Deactivates' Battery Power
OK, so, how about we take the 12V from the car's accessories bus or whatever it's called (only on when the car is running), and we use that to set the set input of a flip-flop, with a series resistor and a zener diode to clamp it so the flip-flop's input is protected from the 12V.

The flip-flop would need to be powered from the auxiliary battery which is "always on" and powers the raspberry pi.

When that flip-flop is on, it turns on a P-channel MOSFET which switches the 5V rail (which has to come from a decent voltage regulator) going into the Raspberry Pi. Even when the car's accessory 12V rail is removed, the flip-flop stays on until it is told to change state.

We also take the car's +12V accessory rail, and divide it down to 3.3V and clamp it with a zener diode for protection, and that is connected to the RPi GPIO so the RPi is aware of the state of that rail.

For example you might look at the schematic here, where the throttle position sensor input line (which is presumably about 14V while the alternator is running) is protected using a zener diode and two resistors.


The output voltage from the voltage divider would be expected to be about 14.4V * 510k / (510k + 1M) = 4.86V.

Since we want a 3.3V input to the microcontroller in this case, the 510k resistor should be smaller so that the voltage is smaller, for example I'd be tempted to change the 1M resistor and 510k resistor to 10k and 2.7k respectively.

Now, you'd need to have one of the RPi GPIO pins that is set to always be high when the RPi is running, and when the RPi OS halts, that GPIO pin goes low, and we use that pin going low to reset the flip-flop via its reset input. (Might need an inverter there.)

But that creates a problem where the flip flop would be held in reset with its reset line asserted prior to the RPi starting up its OS and asserting that GPIO pin - so the flip-flop can never be set and the RPi can never turn on in the first place.

It's a little bit more complicated then it sounds at first - maybe, instead of trying to do it with hardware logic, it might be easier to do it with an external microcontroller such as an AVR, which monitor's the car's power rail, controls the FET, and communicates with the RPi over serial or SPI or whatever, and has an awareness of when the RPi has been shut down.

I think this can be broken up into a bunch of discrete problems which can all be solved individually and then strung together.

- Charging the auxilary battery from the car's 12V supply.
- Regulating the battery voltage down to clean 5V for the Raspberry Pi.
- Switching the 5V rail into the Raspberry Pi using an appropriate P-channel MOSFET.
- Connecting the car's 12V rail to the microcontroller so the microcontroller is aware of its state, with appropriate protection.
- A little bit of logic which can either be hardwired logic or implemented in a microcontroller.
- External microcontroller or logic circuit communicating with the Raspberry Pi and having an awareness of when the RPi OS has halted and can be safely powered down without corruption.

Hopefully that is helpful to get you started thinking about the problem.


It's an interesting problem.

It would be nice to have a button connected to a Raspberry Pi that powers on the machine and boots when you press the button, and when you push the button again tells the OS to safely halt, and then once it is halted it turns off the power. And that's a very similar problem to the problem we're discussing above.
 
 

kspn

unread,
Sep 4, 2012, 7:01:00 PM9/4/12
to Connected Community HackerSpace
Hmm, turns out to be more complex than I though, I will break it down
into 2 items (solving them one at a time :)

First the buttons.
As this is sitting in my car i can't really use a keyboard or anything
like that (I tried that and it was less successful than using the GPIO
buttons).
Where am I likely to find a reasonably 'simple' flip-flop circuit that
will do the job?

I was talking to Andy on Saturday and he suggested the Latching
solution so that I only have to poll the switches once per second or
so (so I can update, the screen I am using mainly), as a result I am
not 100% certain where I should be starting with the circuit. (I can
send an image of my current setup if that would help). A quick Google
search returns this result:
http://www.daycounter.com/Circuits/Latching-Momentary-Switch/Latching-Momentary-Switch.phtml
However I am unsure if:
(1) it would be easily expandable to 4 buttons,
(2) It is more complex than I really need. (I already have a
'debounce' circuit for my current switches)
(3) How would I 'reset' the switch state without pressing the switch
again (using the output from the GPIO)

Thanks for your help
Karel

On Sep 4, 8:38 pm, Luke Weston <reindeerfloti...@gmail.com> wrote:
> > 1) I have some buttons that I am using to control my RasPi (in the car
> > playing MP3's) via the GPIO pins, the issue is that I am using momentary
> > switches to achieve this and as a result then 'check' times need to be
> > quick low in order to not 'miss' that the button has been pressed. It was
> > suggested that a 'latch and release' type of circuit would be a good
> > solution to this, however I have absolutely no idea where to even start
> > with this.
> > What I need assistance with with building a circuit that:
>
> >    - When a button is pressed 'holds' that the button has been pressed
> >    (up to 4 buttons)
> >    - Uses another GPIO output to 'release' the button press for all
> >    buttons
>
> > You might use a flip-flop for this, where the pushbutton press is
>
> connected to the set input of a SR flip-flop, so it turns on (and stays on)
> once set, until it is reset by the Raspberry Pi with the GPIO output from
> the Pi connected to the reset input of a SR flip-flop.
>
> Alternatively, if you want to have a good number of buttons without using
> up all your GPIOs, you might have an external microcontroller, like an AVR,
> which handles the more "time critical" task of handling the buttons, then
> it communicates the button information back to the Raspberry via UART or
> SPI or something.
>
> Or, alternatively, how about a cheap mass-market PC USB HID input device
> such as a keyboard or touchscreen, trackpad, trackball etc, or a hacked
> keyboard controller connected to a few pushbutton switches, connected to
> the RPi's USB port?
>
> > 2) The second circuit that I need some assistance with is a power circuit,
> > as I am using the RasPi in my car I need some kind of 'trigger' curcuit
> > that is able to (a) turn the RasPi on (apply power) using a battery to
> > supply power (so switching the battery source on) then once the car is
> > turned off flag (via GPIO 3v3) to the RasPi that a shutdown is required so
> > that the system can be gracefully halted (I can handle the software side
> > easily, it is the hardware that I am having issues with)
> > The basic idea is:
>
> >    - Car Turns On --> 'Activates' the power line from the Battery to the
> >    RasPi (Battery charged from Car Power)
> >    - Car Turns Off --> Power from the battery remains on, GPIO signal

Scott Penrose

unread,
Sep 4, 2012, 7:58:54 PM9/4/12
to connected-commu...@googlegroups.com
Sorry I have not read the whole thread, but I noticed the Keyboard vs GPIO comment here, and I thought I would talk about keyboard hacking. The first is just pulling apart an old keyboard and using (USB or PS2) on a device. USB for modern stuff (e.g. Raspberry Pi or Beagle*), or PS2 if you want to access it from an embedded like Arduino.

The board is tiny inside those old keyboards, so you can easily hack any number of buttons to it, and it covers all the debounce etc. Also decoupling, so you can afford to have long wires and not worry :-)

The other thing I have used recently is Teensy boards (which are similar to the new Leo sticks or Leonardos) which act as a keyboard for you - although redundant in this case since you would then be turning a GPIO into a keyboard just to go back to a GPIO :-)

Scott
> --
> You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
> To post to this group, send an email to connected-commu...@googlegroups.com.
> To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Zac Watts

unread,
Sep 4, 2012, 8:34:55 PM9/4/12
to connected-commu...@googlegroups.com
You could use a a 555/556 monostable type circuit to go high on a button press and reset automatically after say, 2 seconds, and poll it every 1 sec. 

--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.

kspn

unread,
Sep 4, 2012, 8:47:43 PM9/4/12
to Connected Community HackerSpace
Hi Zac,

That sounds like a possibility, it would require a bit of a code
change to handle it (I would have to ensure that I don't poll the GPIO
twice within the 'held live' state, say 0.2/1.2) but that is certainly
one option that would work :)

Would that kind of circuit be able to accept a 'reset' signal?

Also where would I be able to find a circuit diagram and parts list
for that?

K

On Sep 5, 10:34 am, Zac Watts <zwa...@gmail.com> wrote:
> You could use a a 555/556 monostable type circuit to go high on a button
> press and reset automatically after say, 2 seconds, and poll it every 1
> sec.
>
>
>
>
>
>
>
> On Wed, Sep 5, 2012 at 9:01 AM, kspn <ksp...@gmail.com> wrote:
> > Hmm, turns out to be more complex than I though, I will break it down
> > into 2 items (solving them one at a time :)
>
> > First the buttons.
> > As this is sitting in my car i can't really use a keyboard or anything
> > like that (I tried that and it was less successful than using the GPIO
> > buttons).
> > Where am I likely to find a reasonably 'simple' flip-flop circuit that
> > will do the job?
>
> > I was talking to Andy on Saturday and he suggested the Latching
> > solution so that I only have to poll the switches once per second or
> > so (so I can update,  the screen I am using mainly), as a result I am
> > not 100% certain where I should be starting with the circuit. (I can
> > send an image of my current setup if that would help). A quick Google
> > search returns this result:
>
> >http://www.daycounter.com/Circuits/Latching-Momentary-Switch/Latching...

Zac Watts

unread,
Sep 4, 2012, 9:09:48 PM9/4/12
to connected-commu...@googlegroups.com
Theres a reset pin on a 555, presumably it resets on being pulled low, but I've never used that function. the 555 wikipedia page is fairly good and would get you going, im sure googling can get you something better. A 555 calculator would be worth looking for to find the R and C for the timing you want.

Others may have an alternative monostable circuit suggestion, I'm no means an expert, but this would be my solution.

kspn

unread,
Sep 4, 2012, 9:32:26 PM9/4/12
to connected-commu...@googlegroups.com
Hi Zac,

I found this Wiki Page http://en.wikipedia.org/wiki/555_timer_IC#Monostable

The Monostable looks like what you were talking about, I 'think' I can insert this into the switch line on Pins 2/3 so that the switch is on Pin 3 (trigger) and the GPIO is on Pin 2 (output).
In this version, press switch, chip outputs 'high' for a time period that depends on 1.1RC timeframe

I could also do it via the 'bistable' variation on the 555 chip (which might be easier as it doesn't need to Cap & resister and I can send a reset signal from the RasPi once the current value has been 'read'
In this version, press switch, chip outputs 'high', RasPi sends 'Reset Signal', chip sends 'low'

Can I get these assumptions checked by someone with more hardware knowledge that I have?

Of course I first actually need a 4x version of the 555 chip to handle the 4 switches, but that should be doable.

K

> > To unsubscribe from this group, send email to

> > For more options, visithttps://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.

Zac Faragher

unread,
Sep 4, 2012, 9:41:45 PM9/4/12
to connected-commu...@googlegroups.com
As already suggested by Luke, you could consider using a Set-Reset (SR) Flip Flop. This is basically what you are aiming to implement with the Bi-Stable 555 timer, however, it should be easier to find these in quad packages.

Only problem with an SR flip-flop, is that if you are holding the button down while resetting the flip flop from the R-Pi, it will give an ambiguous output (http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/setreset.html#c1) which can be fixed by using a J-K flip flop (apparently).
I don't have much experience with these myself....

Zac (a different one).

To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/wSwYjkHF5AUJ.

kspn

unread,
Sep 4, 2012, 9:48:13 PM9/4/12
to connected-commu...@googlegroups.com
Hi Zac (#2) :)

Unfortunately a 'quick' google search didn't yield a circuit diagram that I can use, do you (or anyone else) know where I could find such a diagram, then I can decide between the 2 types 8-)

Karel

> > To unsubscribe from this group, send email to
> > connected-community-hackerspace+unsubscribe@googlegroups.com.
> > For more options, visithttps://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hackerspace...@googlegroups.com.

To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.

To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.

Clifford Heath

unread,
Sep 4, 2012, 11:33:49 PM9/4/12
to connected-commu...@googlegroups.com
Switch debouncing is really easy with a Schmidt buffer like a 4050
or a 74hc7014 hex non-inverting buffer. No need for anything like
a 555.

Fit a resister from output to input with a cap to ground, a resister
from +ve to input, and resister+switch in series from input to ground.
This circuit uses essentially no power until the switch is pushed,
then only a tiny bit. The R's and C's determine the debounce time
constants.

Clifford Heath.

kspn

unread,
Sep 4, 2012, 11:39:04 PM9/4/12
to connected-commu...@googlegroups.com
Hi Clifford,

I already have a switch debounce circuit, what I am missing (and am looking at using either the 555 chip, or the flip-flop for) is switch 'latching' so that I don't have to check the switch state every 0.01 seconds (which kills the CPU).

I am currently using the debounced switches with my RasPi, but want to improve the circuit to make better use of the avaialble resources and not have to check the switch state so often.

Karel
> To post to this group, send an email to connected-community-hacke...@googlegroups.com.
> To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
> To post to this group, send an email to connected-community-hacke...@googlegroups.com.
> To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.

Clifford Heath

unread,
Sep 5, 2012, 12:26:38 AM9/5/12
to connected-commu...@googlegroups.com
On 05/09/2012, at 1:39 PM, kspn wrote:
> I already have a switch debounce circuit, what I am missing (and am looking at using either the 555 chip, or the flip-flop for) is switch 'latching' so that I don't have to check the switch state every 0.01 seconds (which kills the CPU).
> I am currently using the debounced switches with my RasPi, but want to improve the circuit to make better use of the avaialble resources and not have to check the switch state so often.

Sorry for not reading more carefully.

0.01 seconds is an eon in RasPI terms - and that's too often if you've
debunked properly - 0.05 seconds is the fastest you need to poll.

However, if you have an interrupt pin you want to tweak each time a
switch changes state, then invert the output of your debounce, and
use a small capacitor from both the inverted and non-inverted output
into a gate with a pulldown resister. This gate can be shared between
many switch. Each switching event (up or down) will tweak the gate
input to produce a short pulse at the output - which goes to your
interrupt line.

Clifford (analog-logic-is-me) Heath.

Ken Ihara

unread,
Sep 5, 2012, 12:41:04 AM9/5/12
to connected-commu...@googlegroups.com
Hi Karel,

Attached is a schematic for the SR implementation.  I think this is what Andy was talking about on Saturday.  The 4013 is available at Jaycar and costs $.95 each.  You'll need 2.

Cheers,
Ken

> > For more options, visithttps://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hackerspace...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsu...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/wSwYjkHF5AUJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/_GNGZ73uU9QJ.
ZC4013.pdf
d flip flop.pdf

kspn

unread,
Sep 5, 2012, 12:51:42 AM9/5/12
to connected-commu...@googlegroups.com
Hi Ken,

That looks like it may be exactly what I need, I take the run form the switch, put it into the 'set' pin and then take the 'out' pin and plug that into the RasPi.

I also then have a ping running form the RasPi into the Reset pin to clear the switch. Nice :)

Thanks for that, I will just need to work out exactly how it will need to plug into my setup to ensure that I don't cause issues (at the moment I have GPIO 'high' until the switch is pressed, I ill need to work out how to get the input into a 'low' state and button push becomes 'high'.

This gives me a great pace to start next weekend :)

Karel
> > For more options, visithttps://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/wSwYjkHF5AUJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-community-hacke...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-hackerspace+unsubscribe@googlegroups.com.

Ken Ihara

unread,
Sep 5, 2012, 1:07:34 AM9/5/12
to connected-commu...@googlegroups.com
Hi Karel,

Use pin 2 (!Q, which is always opposite of Q) as output from flip flop.  That pin will be high until button is pressed.

FYI -- since you are using the set pin, the debounce circuitry you currently have is not necessary (though it doesn't hurt)

Ken
To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/hMj4HCfvdaIJ.

kspn

unread,
Sep 5, 2012, 1:13:24 AM9/5/12
to connected-commu...@googlegroups.com
Hi Ken,

Thanks for that, it will simplify things quite a bit :)

I need all the help I can get being a 95% software guy.

I will let you know how I go

Karel

Ken Ihara

unread,
Sep 5, 2012, 2:00:05 AM9/5/12
to connected-commu...@googlegroups.com
Karel,

I just had a thought for your second problem.

Car stereos often have two 12V inputs.  The switched (red) cable and the constant (yellow) cable.  The constant 12V is there to keep memory settings and power the clock, etc.

Perhaps you could run your RPi off the constant 12V, and then monitor the switched 12V line so the RPi goes into a controlled shut-down when you turn off the key.

Ken
To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/JHzbiX_WAUoJ.

kspn

unread,
Sep 5, 2012, 2:10:16 AM9/5/12
to connected-commu...@googlegroups.com
Hi Ken,

Unfortunately that would leave the RasPi in a state of 'have power but not on' and the lack of a power switch on the Pi would mean I would need to build one (which could then be accidentally pressed while driving).

Also I am currently using a 'USB' adapter to give the 5v power to the RasPi, and i would need to wire that into the pi as well.

Thanks for the idea but it looks like the more complex solution  (so that the RasPi works like an iPod plugged into my radio) is the (current) way to go. I will however delay that until I get the 'latching' circuit working (one problem at a time)

Karel

kspn

unread,
Sep 5, 2012, 3:11:32 AM9/5/12
to connected-commu...@googlegroups.com
I think that the SmartSim application that they are highlighting will probably also help me with this as well :)

http://www.raspberrypi.org/archives/1917

We shall see :)

Karel

Stuart Young

unread,
Sep 5, 2012, 8:46:58 PM9/5/12
to connected-commu...@googlegroups.com
On 5 September 2012 16:10, kspn <ksp...@gmail.com> wrote:
Hi Ken,

Unfortunately that would leave the RasPi in a state of 'have power but not on' and the lack of a power switch on the Pi would mean I would need to build one (which could then be accidentally pressed while driving).

They've added a reset switch to the new version of the board which could be used to reboot the Pi, but the issue then is if someone disconnects and reconnects the battery, the unit will reboot (and if it happens multiple times, lose power while on and the FS is mounted, possibly leading to corruption.

BTW: Details of the new revision boards are at http://www.raspberrypi.org/archives/1929

There's a few changes that I am sure could be retrofitted to older boards that make a bit of sense, such as changing the fuses on the USB connector, changing/removing the HDMI protection diode, etc.

--
Stuart Young (aka Cefiar)

David Lyon

unread,
Sep 4, 2012, 3:08:44 AM9/4/12
to connected-commu...@googlegroups.com


On Tue, Sep 4, 2012 at 3:37 PM, kspn <ksp...@gmail.com> wrote:
Hi All,
2) The second circuit that I need some assistance with is a power circuit, as I am using the RasPi in my car I need some kind of 'trigger' curcuit that is able to (a) turn the RasPi on (apply power) using a battery to supply power (so switching the battery source on) then once the car is turned off flag (via GPIO 3v3) to the RasPi that a shutdown is required so that the system can be gracefully halted.

Cars have 'circuits' for power. One is 'Accessory' power which is only on when the engine is on. The other is battery or permenant power.

If you find the permenant power wire, it will go to your radio, use that.

David Lyon

unread,
Sep 4, 2012, 8:46:44 PM9/4/12
to connected-commu...@googlegroups.com
For fun, you could also consider:

Joystick:

 - http://www.dealextreme.com/p/arduino-ps2-joystick-game-controller-module-black-red-138517?item=122

Buttons with LCD (serial interface):

 - http://www.dealextreme.com/p/8x-digital-tube-8x-key-8x-double-color-led-module-81873?item=178

(haven't tested these - but they look interesting)

David Lyon

unread,
Sep 4, 2012, 7:37:49 PM9/4/12
to connected-commu...@googlegroups.com
A different option is to connect the switches in parallel to a shift register.

What you are looking to do is to output a single serial byte when
a key is pressed. That's far easier to catch programmaticly.

Connect the circuit to the Rasberry-Pi serial in pin - RXD

 - http://www.arduino.cc/en/Tutorial/ShiftIn

Here is a supplier with the part:

 - http://au.element14.com/texas-instruments/cd4021be/ic-4000-cmos-4021-dip16-18v/dp/2256617

David Lyon

unread,
Sep 5, 2012, 9:14:06 PM9/5/12
to connected-commu...@googlegroups.com
I found a nice article and library for reading a GPIO pin:

 - http://www.open.com.au/mikem/bcm2835/event_8c-example.html

the whole article is here:

 - http://www.open.com.au/mikem/bcm2835/index.html

kspn

unread,
Sep 5, 2012, 9:31:06 PM9/5/12
to connected-commu...@googlegroups.com
Hi David,

I did consider that, but unfortunately as described above (note I have Revision 1 without a reset switch) I would have no way of turning the device back on.

My basic scenario for this is:
1) Turn car on
2) Enable power from a battery pack (Which I have)
3) RasPi turns on
4) RasPi sets a signal to 'high' to keep power form the Battery Pack 'On' (don't know how to do this bit)
5) Car Turns Off
6) RasPi detects that car is no longer sending Power to the battery pack (don't know how to do this bit)
7) RasPi Shuts Down, stopping the 'high' maintenance signal
8) Power from Battery pack is turned off after a small delay (don't know how to do this bit)
9) Entire setup now has no power, GoTo 1

This scenario is designed in such a way that the Car is turning the RasPi on/off depending on if it is running with the limitation of the on/off being Power On/Power Off

I will probably come along to the CCHS meeting on Saturday morning, which may help with some of the explanation of what I am trying to achieve with this.

As far as the switches go, I am looking for Simple, the simpler the better, at the moment my solution is 'too' simple, and I am having to do some high speed loops to read the GPIO pins and get the status of the buttons (I have 4), which is not ideal.
I am going to investigate the option for setting up a flip-flop so that I only have to check the button whenever I update the screen (once per second) as that seems to be the next simplest solution, it also means that I can use the same code for signal checking and power maintenance for the power issue that I am having.

Thanks
Karel

Stefan Lacombe

unread,
Sep 5, 2012, 9:36:24 PM9/5/12
to connected-commu...@googlegroups.com

Not sure if this helps, but there is normally a permanent 12v and an ignition switched 12v supply the the radio in a car.  The RasPi could be permanently on but in a sleep mode (if it has such a thing) and made to wake on the switched 12v signal. That's how the radio retains it's memory when the ignition if off.

Stef

On 06/09/2012 11:31 AM, "kspn" <ksp...@gmail.com> wrote:

Hi David,

I did consider that, but unfortunately as described above (note I have Revision 1 without a reset switch) I would have no way of turning the device back on.

My basic scenario for this is:
1) Turn car on
2) Enable power from a battery pack (Which I have)
3) RasPi turns on
4) RasPi sets a signal to 'high' to keep power form the Battery Pack 'On' (don't know how to do this bit)
5) Car Turns Off
6) RasPi detects that car is no longer sending Power to the battery pack (don't know how to do this bit)
7) RasPi Shuts Down, stopping the 'high' maintenance signal
8) Power from Battery pack is turned off after a small delay (don't know how to do this bit)
9) Entire setup now has no power, GoTo 1

This scenario is designed in such a way that the Car is turning the RasPi on/off depending on if it is running with the limitation of the on/off being Power On/Power Off

I will probably come along to the CCHS meeting on Saturday morning, which may help with some of the explanation of what I am trying to achieve with this.

As far as the switches go, I am looking for Simple, the simpler the better, at the moment my solution is 'too' simple, and I am having to do some high speed loops to read the GPIO pins and get the status of the buttons (I have 4), which is not ideal.
I am going to investigate the option for setting up a flip-flop so that I only have to check the button whenever I update the screen (once per second) as that seems to be the next simplest solution, it also means that I can use the same code for signal checking and power maintenance for the power issue that I am having.

Thanks
Karel

On Tuesday, September 4, 2012 5:08:44 PM UTC+10, David Lyon wrote:


>
>
>
> On Tue, Sep 4, 2012 at 3:37 PM, kspn <ksp...@gmail.com> wrote:
>>
>> Hi All,

>> 2) The seco...

To view this discussion on the web, visit https://groups.google.com/d/msg/connected-community-hackerspace/-/uL9MbK8dmbQJ.

David Lyon

unread,
Sep 5, 2012, 9:37:07 PM9/5/12
to connected-commu...@googlegroups.com
Oh, good explanation, that makes sense.

Well, one thing you may want to try is to connect the
Rasberry-Pi to permenant power.

Then connect the accessory-power (12v) to a voltage-divider
(2-resistors) and connect the voltage-divider to a GPIO pin
configured as an input.

You can read that GPIO input to tell when accessory power
is on and off, and when the pin goes low, shut down the raspberry-pi
in it's own sweet time. (sudo shutdown 0 -h whatever).

Not sure you need extra batteries as you can use the one in the
car already.


kspn

unread,
Sep 5, 2012, 9:49:55 PM9/5/12
to connected-commu...@googlegroups.com
Hi Stef, David,

I suppose that my issue comes down to a single question that I have not yet spotted an answer to. How do I turn the RasPi back on after shutting it down without unplugging the power. If I can work that out then yes Permanent power becomes viable :)
(As a side note I like the battery because it provides the 5v USB power I need @ 1A)

Karel

kspn

unread,
Sep 5, 2012, 9:54:11 PM9/5/12
to connected-commu...@googlegroups.com
Hi Stef, David,

Here is a Forum power (RasPi) that describes the isssue :)

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=9089&p=107169&hilit=turn+on+unplug+power#p115844

"The Pi does not, it needs to be halted AND then shut down by just pulling the power out of the mains of the Pi."

Karel

David Lyon

unread,
Sep 5, 2012, 9:54:25 PM9/5/12
to connected-commu...@googlegroups.com


On Thu, Sep 6, 2012 at 11:49 AM, kspn <ksp...@gmail.com> wrote:
Hi Stef, David,

I suppose that my issue comes down to a single question that I have not yet spotted an answer to. How do I turn the RasPi back on after shutting it down without unplugging the power. If I can work that out then yes Permanent power becomes viable :)
(As a side note I like the battery because it provides the 5v USB power I need @ 1A)

big switch ?

 - http://www.thingiverse.com/thing:26805

(laugh - but - these big switches are really handy. You can
 vary the style to suite your own taste)

Karel Young

unread,
Sep 14, 2012, 8:33:16 AM9/14/12
to connected-commu...@googlegroups.com
Ok, I now have 2 CD4013BE Chips, and am starting to create the circuit for the Flip Flop Switch.

What do I connect where?

S1 - Switch input
Q1 - To GPIO Pin
R1 - From GPIO Pin

Where does 3v3 go in (VDD I think)
Earth (VSS?)

So for my circuit I have the attached file, is it somewhat correct?

Note, Ignore the S/R/Q values (only digrammer I could find) I have marked Pin 7 & 14 and used the same layout as the CD4013 chip

So
  • To GPIO = Pin 1
  • From GPIO = Pin 4
  • Switch Input - Pin 6
  • Earth Pin 7
  • Power (3v3) Pin 14

.... Help?
Karel


--
You received this message because you are subscribed to the Google Groups "Connected Community HackerSpace" group.
To post to this group, send an email to connected-commu...@googlegroups.com.
To unsubscribe from this group, send email to connected-community-h...@googlegroups.com.
Simple Diagram 1.png

kspn

unread,
Sep 14, 2012, 8:58:05 AM9/14/12
to connected-commu...@googlegroups.com
As an addendum to that, what value resister should I use on the Switch to Ground part of the circuit?
Reply all
Reply to author
Forward
0 new messages