I have a raspberry pi and I was wondering if there was a way to interrupt a program using a GPIO pin? For example, the pi begins printing a long story but if i click a button and close the switch it will pause and turn on a led. I did some research but i could only find stuff for python 2 while I am using 3. Thank you any help is greatly appreciated. :D
The RPi.GPIO library supports Python 3, so you can start by using that.
Assuming that your RPi board is one that uses GPIO 3, here is an example:
import RPi
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.output(3, RPi.GPIO.LOW)
Related
I've been trying to control a mg995 Servo by changing the duty Cycle with the RPi.GPIO library, but the Servo ended up shaking a lot. I've been reading a lot of Threads about this issue and I know, that using the RPi.GPIO library is causing the issue.
I then tried to use the pigpio library but it's unfortunately not available for the RP4.
I know that buying a specific hardware could help out but I want to try it with software first.
Is there another way to controll a Servo without the shaking? I want to run the Servo through python code btw
If the driving is not done at a too high PWM frequency then you can create a solution by using SYSFS driver, if you need high frequency the problem is maybe hardware and not software to control at the oscilloscope. If you are able and want to do without any lib then you can write directly the gpio registers of the SOC through memory-map with mmap
As I tested before, software PWM is unstable and the servos can shake a lot, hardward PWM is quite acurrate, but the pi has only 2 hardware PWM channels.
The best way may be add an external PWM module (PCA9685 for example).
I am writing a GUI for my Raspberry pi, but I'd like to work on the code on PC, then drop it into the pi, just cos the tools are better and I mostly have remote access to the pi etc etc. My problem is that the GUI does some calls to change IO pins on the Pi, using the RPi.GPIO library, which doesn't exist on PC. Of course I can comment out the lines of pi-specific code, but that's really messy especially if I start going back and forth. My idea is to set up a dummy/mirror library for the PC, then the code picks the dummy library on PC and the real library on the pi. Seems simple, but I'm getting really bogged down creating my own library. So, to my question, in summary - what is the easiest way to create a quick library using PyCharm that my code would pick up...
Here is some quick code for context...
import RPi.GPIO as GPIO # this is the library I want to mirror
# sets pin numbering on pi, does completely nothing in
# the dummy I want to call in on on PC
GPIO.setmode(GPIO.BOARD)
GPIO.output(self.reset_pin, 1) # also does stuff on pi, nothing on PC
There is the fake-rpi package on pypi:
So, does this simulate everything on a Raspberry Pi? No! Right now it simulates what I use and need. Over time, more will be added. You are also welcome to submit pull requests for things I haven't added yet.
But it looks like it simulates GPIO pins
Python: I'm writing a system that needs the program to wait until an input from the GPIO board on a raspberry comes through then loop until the input stops? Any ideas on the best way to do this?
The best way , imho, is to use the event_detected() function of the RPI.GPIO module.
Take a look at http://raspi.tv/2014/rpi-gpio-update-and-detecting-both-rising-and-falling-edges
The example program detects rising and falling edges on GPIO 25
Sorry I am a beginner to both Raspberry Pi and python. I am write a simple python program to use the pulse width modulator, Here is the code.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12,GPIO.OUT)
pwm=GPIO.PWM(12,50)
pwm.start(0)
while True:
for i in range(50):
pwm.ChangeDutyCycle(i)
time.sleep(0.05)
for i in range(50,0,-1):
pwm.ChangeDutyCycle(i)
time.sleep(0.05)
I connected the led between 12 and ground with the suitable resistor. But when I execute, I don't get any error but it wont work.
The code seems to work fine on my Rpi-3. So we cannot help you if we can't see the circuit design. I can make a guess that you probably used the normal numbering to connect the led, but used the BCM numbering in your program. So either change it to board numbering by GPIO.setmode(GPIO.BOARD) or refer the below chart for correct numbers.
I got the problem. I need to use the proper numbering. The reason for having two types of numbering is,
The GPIO.BOARD option specifies that you are referring to the pins by the number of the pin the the plug - i.e the numbers printed on the board (e.g. P1).
The GPIO.BCM option means that you are referring to the pins by the "Broadcom SOC channel" number.
I hope this helps anyone.
I am new to coding and I am trying to control ESCs through a PS3 controller which will be coded on the Raspberry Pi B+. I think this can be done, but i have read in a lot of places that I need to use an additional board? Is this the case?
I have found some code which i was going to manipulate..
http://www.raspians.com/Knowledgebase/ps3-dualshock-controller-inst...
http://mechnable.com/content/raspberry-pi-controlling-4-servos-via-...
Please advise me on if I need another board?
My project: is to create a system which can VTOL. So I wanted to control the ESCs with an input from the PS3 controller.