NeonHorizon / lipopi

Guide to setting up LiPo batteries on the Raspberry Pi
GNU General Public License v3.0
416 stars 62 forks source link

Why is wire to GND needed? #50

Closed slavapak closed 4 years ago

slavapak commented 5 years ago

Dear Daniel,

IIUC when RPi0 shuts down, GPIO14 should go low and that should turn Powerboost off. Then why is wire to GND still needed?

Thank you!

Kind Regards, Slava.

RChadwick7 commented 5 years ago

I'll assume you're more of a software person. Forgive me if I got your question wrong. GPIO14 will go low RELATIVE to ground. I'm not familiar with any magic that would allow knowing if a pin is low (0 Volts, connected to ground) or high (+5 Volts or +3.3 Volts) without access to a ground. Unlike a water hose, where water will go in one end and come out the other, Electricity needs to work in a loop. If you ever look at any battery, you will see two connections. At least one will be marked, and you can figure out what the other one is (Either + or -). Hope this helps.

slavapak commented 5 years ago

RChadwick7 thanks! That makes sense.

Do you mind if I ask you several more questions? :)

I'm thinking of implementing the basic lipopi but with a SPDT switch instead of a button. Daniel suggested a nice solution here. 1) Is it safe to have GPIO18 connected to Bat when Pi is off? 2) Also does it drain any additional current? 3) If yes, would adding a 100K resistor between Bat and switch less the drained current? 4) In general, is it OK/safe to have Bat constantly connected to GPIO14 when Pi is on? 5) Is it safe to have GPIO14, 18, Bat, En and Gnd connected momentarily? I assume that might happen during switch slider slide.

Thanks a lot!

Cheers, Slava.

RChadwick7 commented 5 years ago

I just want to back up for a second. The GPIO pins won't necessarily be connected directly to +V or Ground. If you program a GPIO pin to be high, it will switch on a switch between the pin and +V, and if you program it low, it will turn on a switch that connects it to Ground. So, what happens if you connect two GPIO pins together, and set one to be high, and one to be low? In some situations, you might get smoke! Since digital electronics is not about high power, but about information, you may often see a resistor between inputs and outputs. This ensures that no matter how the pins are set you won't get a direct short between +V and Ground. A resistor between 1K and 10K is usually good to let the voltage low/high information be passed, but not be a big deal if it's connected between +V and Gnd. I could be wrong, but I think the Pi has these resistors already internally. Regardless, it wouldn't hurt to put a 1K resistor on outputs.

In general, it's a bad idea to power random pins of a chip when it's powered down. However, if the Pi's power is the same as what you attach to GPIO18, that's fine. Again, if you want to be safe, put a 10K resistor between +V and GPIO18.

Since we're dealing with information instead of power here, very little current is required for an input to detect a high. If your code accidentally made GPIO18 and output, and set it low, you would have a higher current drain with a 1K resistor. Under normal operation, I doubt you could measure a difference. As for GPIO14, I would use a pull up resistor, 1K to 10K. Again, as long as it's configured as input, everything should be OK. In the Engineering world, it's common to permanently pull up a pin. If the pin could never be configured as an output, and a 1K resistor is not desirable for whatever reason (Cost, laziness, etc), the pin can usually be connected directly. Again, the warning about not powering pins on an unpowered chip. If you use the same power supply for everything, no worries.

As for connecting everything together momentarily? Sounds scary, but putting resistors on GPIO 14 and 18 should hopefully protect them. As for the +V from the battery and ground shorting, that's a really bad idea. Depending on what you want to do, I would either use an SPST (Or just one side of an SPDT) to switch the +Battery voltage (No need to switch Gnd), or leave the battery permanently connected, and use the SPST instead of the pushbutton switch. The PowerBoost will draw current this way, but it's SO small you likely will never notice it.

Hopefully some of this makes sense. I made some assumptions that might be wrong. If you have more questions, it might help to know more about your application.

NeonHorizon commented 5 years ago

When the Pi is off or the pins are set as inputs the GPIO's should be very high impedance (IE little to no current will flow) but as mentioned having 1k resistors inline isn't a bad idea under most situations.

With reference to pulling up and down pins the Pi has software programmable pull up and down resistors which are about 50k so its usually unnecessary to have external ones. The only odd ones out are the I2C pins which I think have internal 1.8k pullups.

slavapak commented 5 years ago

Thanks for such a through explanation!

Basically, all I want to do is to add safe on/off to my RPi0. I like the idea to copy lipopi, but with a sliding switch instead of a button. And hence are all my questions :) I.e. for button GPIO14 is connected to Bat only when button is pressed, but for sliding switch it will be connected all the time when RPi0 is on. And in the solution suggested by Daniel in that other thread GPIO18 remains constantly connected to Bat when RPi0 is off. Now, if I understand you correctly, all of it is safe and does not cost much current.

Thank you!

Cheers, Slava.

slavapak commented 5 years ago

Reviving this thread.

I just realized that when using sliding switch instead of a button, and put it between Bat and 100 KOhm resistor, connection to Bat might be redundant.

Here how I assume it would work:

Unfortunately I do not know a lot about electric circuits, and I'm afraid to burn my RPi0. Can you please confirm that it is safe to remove link to Bat?

Thank you!

Cheers, Slava.

NeonHorizon commented 5 years ago

Can you do a circuit diagram so I can see?

slavapak commented 5 years ago

Sure!

Here it is: sliding-switch

NeonHorizon commented 5 years ago

Hey that's really clever! You are taking advantage of the tri-state output on the GPIO (hi, low, high impedance). I think it should work but I don't know for sure give it a go and let us know :)

NeonHorizon commented 5 years ago

By the way now I understand a bit better I think I can answer your original question. You were asking why the ground wire is needed, I'm guessing you mean the wire with the 100k resistor rather than the actual ground? The reason that is needed is because when the Pi is powered off GPIO14 is high impedance (almost open circuit) so the 100k is used as a pulldown resistor.

slavapak commented 5 years ago

I see. Thank you!