I have a raspberry pi using pigpio to control two servos with two buttons. Right now I have to hold the button to make the servo move. I want the buttons to toggle the servos between the two positions, but my attempts fail.
I'm on mobile so i put a picture of my code, sorry I couldn't paste it.
Code Picture
Note: the commented code is from when i was using gpiozero to control the servos, but it caused jittering so I switched to pigpio. The comments are there just in case I have to switch back for whatever reason.
To toggle between positions you need to know when the positions are reached.
Do you have limit switches?
Can you measure the increase in current when the motor reaches the limit?
Can you send the motor to a position by setting an angle?
Related
I'm fairly new to the Raspberry Pi and trying to wrap my head around the code I need to use the 8 bit shift register to control a set of relays I have managed to hook up.
The tutorial was one of the many 8-bit shift tutorials for blinking LED.
I can't wrap my head around how to alter the code to get the system to treat either a set of individual variables (relay1, relay2, etc) or relay[0,0,0,0,0,0,0,0] as a set of toggle type switches.
So that when a relay is triggered-only that relay is altered (on to off and vice versa) and the other ones don't cycle.
while True: # execute loop forever
for y in range(8): # loop for counting up 8 times
IO.output(data,1) # pull up the data pin for every bit.
time.sleep(clock_cycle) # wait for 100ms
IO.output(clock, 1) # pull CLOCK pin high
time.sleep(clock_cycle)
IO.output(clock,0) # pull CLOCK pin down, to send a rising edge
IO.output(data,0) # clear the DATA pin
IO.output(shift,1) # pull the SHIFT pin high to put the 8 bit data out parallel
time.sleep(clock_cycle)
IO.output(shift,0) # pull down the SHIFT pin
Can someone show me what I'm pretty sure is a simple piece of code for setting individual outputs to on or off?
SHORT VERSION:
I'm attempting to detect when my microphone is being captured by a program like Discord, preferably in Python, but I can't figure out how to do it. Any suggestions?
LONG VERSION:
I'm trying to write a program that will turn on an "On Air" light whenever my microphone is being used. Typically this would either be for Discord or Twitch. This is something Windows already monitors as well (Windows 10) because it displays a microphone icon down in the notifications tray and tells you what programs are using your microphone. Basically, whenever that icon notification is up, I want my light to be turned on.
The light is currently being run by sending serial commands through Python to an Arduino Nano, but I can only manually tell it to turn on or off.
I can't find a way to access windows privacy monitoring status or make any headway on just checking if a microphone is in use with Python. Any suggestions?
You can lock if the MicrophonIcon is displayed. Presice write an Pythonscript that locks if Pixel at the Position of the MicrophoneIcon having the Color off the MicrophonIcon. qt can do this. It has a python binding.
Get the Position of the MicrophonIcon( you can hover over it with the mouse and use a program to look the position up)
Get some Pixel Colors off the aria with qt
write a loop that checks if the Pixel Colors at the moment are equal to messured ones.
Con: if the Position off the Microphon changes(Screensize, other options that push it, not visable( fullscreen)) It will not work.
If you checke the yello lines in 2 loops it should define the Microphone icon nearly failsafe if the position isnt changing
I'm working on a project for work which is essentially a remote monitor that looks at the status of drawbridges. I have a GUI set up that i designed with PyQtDesigner with 8 buttons that are currently coloured red and want them to go green when drawbridges come down. I'm using the GPIO on a raspberry pi to get a signal from the drawbridges but cant get the buttons to change to green.
self.pushButton_7.setStyleSheet("background-color: red")
that's how the buttons are coloured initially but unsure how to change them to green with an input from the raspberry pi, any pointers will be super helpful!
(totally new to pi's and python!)
I'm changing some inputs to a device with relays, and I'm expecting at some point to break the firmware. The question is, when will this happen?
So, to determine if the firmware breaks, I'm monitoring some LEDs that normally blink during normal operation. I know that they will lock up in whatever state they're currently in when the firmware breaks. So, my bright idea was to simple feed that signal back into a Raspberry Pi and watch the that GPIO for a change-state. If I see the state change, then go ahead and flip the relays...Then look at the LEDs and make sure they're still blinking...rinse, repeat.
However, I would normally check this with an interrupt or something in C, but I'm writing this in Python...
What's the Python way for handling this? I know that if I don't see any blinking for 2 seconds or so, the test is over, but I'm not sure how to do this without invoking something like sleep...to which, I wouldn't be able to watch for pin changes.
From the gpio module, create a threaded callback function that fires every time a rising (or falling, etc...) edge is detected.
Then using signal within this function call signal.alarm() to reset an alarm whenever the pin changes.
Finally use signal.signal() to register a function for what should happen when the alarm is not reset in time (ie, firmware has broken)
this won't work if you're using windows unfortunately... you would need to implement your own alarm system with threading if you are
Ok so i'm working on controlling an rc car with the keyboard directional keys, using Python and a Raspberry pi, I was just wondering if i need to use PyGame, or something similar, or if Python has a built in key listener, i was hoping to progress onto using an xbox controller, but would like to get it working from the key board first
You could use Pygame to read joysticks, but you'd eventually need GPIO to flow current to the motors. As such, I'd probably use GPIO for button input as well. See the video here for more.