Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1268

Python • Re: stop loop with button press--raspberry pi and gpio

$
0
0
sorry for a late reply, i had gotten all the parts in the mail finally and pulled everything apart to cut wires to length, solder boards and connectors, all that fun jazz. just got it back together and running again this afternoon.
The code configures the GPIO as an output. You need an input.
By the way, the code could not run, because of SyntaxErrors.

Code:

GPIO.setup(18, GPIO.OUT)GPIO.output(18, 0) #BUTTON BLUEGPIO.setup(18, , pull_up_down=GPIO.PUD_DOWN) # invalid syntax, two commas
Instead, use GPIO.IN.

You can also configure more than one GPIO, if you put the integers into a list or tuple and us this instead of a single int.

Code:

GPIO.setup([12, 13, 14, 15], GPIO.OUT)
my actual code did have the gpio.in command in it, when i copied and pasted it set it up as a hyperlink, and when i went to remove it a window popped up asking if i wanted to delete all the hyperlinks. i clicked yes and didnt think much about it, but now im guessing it deleted the text too and not just the hyperlink. lol

i wasnt sure what pins are high or low by default, and didnt know if it is in the wrong state when the button is pressed (feed from 3.3v) the input wouldnt be read. so i was making sure the pin was low so it could read a high signal when button is pressed... correct me if im wrong, but i think that is was is needed.

good to know about being able to configure more than a single pin, that will make the script way more better to navigate... spose i ought to get a python code editor and stop using notepad lmao.

I suggest considering shifting your loyalty from RPi.GPIO to the alternative gpiozero Python library. (This is the gpio library currently mentioned by Raspberry Pi in their own documentation: Use GPIO from Python - https://www.raspberrypi.com/documentati ... rom-python )

gpiozero comes supplied with routines that watch for changes in gpio state and let you take appropriate actions.

Examples -
https://gpiozero.readthedocs.io/en/stab ... tml#button
i saw the name gpiozero when doing some googling, tried using it and it seemed like i couldnt use both rpi.gpio and gpio zero. didnt realize it was the reccomended method from the pi guys themselves at the time, so i was just sticking when what i had played around with in the pass.

that being said, since it seems the usurp rpi.gpio ill probably convert over... looking over the documentations it looks way more user friendly for a newbie like me, but i couldnt find how to manually set a specific pin to high or low. thats a pretty basic thing so i only looked through the basic recipes list that would seem to include something like that and briefly looked over the input/output pages, so i could have easily missed it

Statistics: Posted by jfisher1991 — Thu Nov 21, 2024 4:19 am



Viewing all articles
Browse latest Browse all 1268

Trending Articles