The one obvious point that you are missing is that the two GPIO's normally used for I2C already have (1.8K) pull-up resistors to 3V3, all other GPIO's need pullups.Seeing as how it works in all of these cases, am I missing something obvious - should I be using a resistor or not?
You can enable the internal pull-ups with the gpio program if you have wiringPi installed:mendhak wrote:Thanks for the replies everyone. While going with the last one (simple, no resistors), I noticed that having three buttons just wouldn't work. The third button would keep receiving 'phantom' highs/lows which the code was picking up, so it was as though the button was being pressed all by itself. With two, it would work just fine.
In the end, I went back with the adafruit circuit (first example), using the 3.3V rail, buttons, and 10K resistors.
Code: Select all
3v3 | O 1k8 (on-board) | +---o GPIO3 | O 560R | / | -+- GND
a low so close to the theoretical maximum is asking for problems. if the 1.8K resistor and the 560 ohm both have their 5% tolerance in the wrong direction you could have a 10% different voltage as a result.My calculation gives 0.78V (560*3.3/[1800+560]) at the GPIO pin with the button pressed -- and that is exactly what my voltmeter says. This should be a "proper low" (the maximum low voltage is specified at 0.8V, see http://www.mosaic-industries.com/embedd ... -circuitry). Apart from that: I do read a stable low when the button is pressed, and a stable high otherwise.
Not completely 100% true, as the 1K8 resistor is simply a resistor outside the SoC. It's an an-board pull-up not a built in pull-up, but yes, you would need to cut a track to insert the resistor, probably not a good idea. But I think that even with this particular GPIO pin, where inserting the protection resistor "isn't possible" I would try use a 10% smaller resistor than 560E to ensure the low would be something like 0.6V, as 0.78V is way too close to the "grey zone", even a very small noise (20 mV) could already cause troubles. And yes, using such a lowered resistor would offer a more limited output short protection, but its much better than nothing. I would use 470E.Since I use GPIO3 with the on-board pull-up I cannot place the additional resistor where you suggest. Hence my solution.
Why not work out the lowest that is "safe" for you and use that rather than seemingly pick values at random.Mosmas wrote:Thanks, I'll take 470R.
It's always a good idea to have a current limiting resistor. If you set an input pin to output or vice versa bad things can happen, a resistor will protect you. The pins can only source or sink 16mA so limiting the current to that level (with at least 220 ohms) makes sense.FlashT wrote:Do I have to use resistor when using button only to change GPIO state? 3.3V PIN -> GPIO? I guess nothing bad could happen? Or am I wrong?
Just to add a bit more here... The Pi pins have the ability to source or sink a lot more than 16mA. I measured 35mA at one point in time and have also caused them to pull so much current it pulled the 3.3v supply low enough to reboot the Pi - which had the beneficial effect of resetting the pin to input mode to help prevent further damage. (I'd not like to test this on a new Pi with the SMPS 3.3v supply though)DougieLawson wrote:It's always a good idea to have a current limiting resistor. If you set an input pin to output or vice versa bad things can happen, a resistor will protect you. The pins can only source or sink 16mA so limiting the current to that level (with at least 220 ohms) makes sense.FlashT wrote:Do I have to use resistor when using button only to change GPIO state? 3.3V PIN -> GPIO? I guess nothing bad could happen? Or am I wrong?