We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Christoph W. • 8 years ago

Thanks for this noce tutorial.

I just had to little issues.

1. Since RPi.GIOP version > 0.5.1a you need to include (channel) in the callback definition.

like: def my_callback(channel):

2. My "T-Cobbler" (has another name) has separate 3V and 5V Pins on the sides.
So you need to be carefull wehen you follow the schematic 1:1.

Danger Will Robinson • 3 years ago

I worked through the tutroial and all was well until the final section detecting a button push. I'm running R-Pi 3 with python 3.7 and RPI.GPIO 0.70 It seems that the statement "GPIO.add_event_callback(4, my_callback);" is being ignored. I added the channel argument to def of my_callback as suggested above but still not joy. Here is my code. Can you see anything wrong ?

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW)
GPIO.add_event_detect(4, GPIO.BOTH)

def my_callback(channel):
print ("Run callback");
GPIO.output(25, GPIO.input(4));

GPIO.add_event_callback(4, my_callback);

My set up is configured with a NO button. Pin 4 sits at 0v until button is pressed and Pin 4 goes to 3.3v. However, nothing happens at pin 25. I've done a number of tests and found that PIO.output(25, GPIO.HIGH) works and the LED turns on. I add a print statement to my_callback(channel) and have concluded that my_callback is never invoked. Something seems to be wrong with GPIO.add_event_callback(4, my_callback);

Thanks in advance.

Brad W • 6 years ago

I realize this is a bit old but I was just running through it to get setup using my RPi 2. My breakout is at Vilros that is slightly different than the Adafruit in that it has two tabs that connect to the left 3.3v and right 5v rails on my breadboard. Otherwise the 3.3v side is identical. I'm able to print GPIO 4 as reading zero. And when I get to step 5 I'm able to define my_callback and call it from the terminal manually. But when I push the button my_callback isn't getting called. Is there something I'm missing?https://uploads.disquscdn.c...

Sameer Bahadur • 6 years ago

maybe a bit too late - but your pull-up resistor on switch is not in the correct position to connect to the switch pin. resistor pin should be in row 28 not row 27.

chanzui • 9 years ago

Hi,
let's assume that we have only the button and the default state is pressed.

Is it better to set the internal pull-up/down resistor of the input pin to up or down?
Does this setting has an impact on power consumption of the Raspberry?

Guest • 9 years ago

I'm a newbie and maybe this is a stupid question, but why the resistor R2 is attached to ground and not to GPIO25 ( before / after the led )?

Leonardo Cruz Costa • 9 years ago

O resistor, no caso do artigo, pode ser colocado tanto antes quanto depois do LED. O que ele faz é limitar a corrente/tensão desse circuito (entre o pino 25 e o terra), independente de estar antes ou depois.

Steve • 9 years ago

I am a newbi as well, but the resister is to control the amount of current from the GPIO pin. Using a form of the equation E-IR, (Voltage = Current * Resistance), I = E / R, for the the 3.3v pin voltage,I = .01A or 10mA. This only allows 10mA to flow thru the pin

Resistors can also be used to Pull-up or Pull-down the GPIO pin, making sure it is either Hi or Lo

Jonathan Wiesel • 10 years ago

Thanks, helped me a lot. What software are you using to make the wiring diagrams with the raspberry cobbler breakout and all?

T Cassar • 7 years ago

That looks like what I use, Fritzing - Its free and really good!

Alex Grutter • 8 years ago

it almost looks like its from Autodesk's 123D Circuits