1 year ago
#378321
Zavier Jacob
How do I get the GUI to recognize that my output is actually set up?
The output on GPIO 27 is connected to a dc motor. The code is to get the motor to start from a GUI using, tkinter button widget. When I run the program RC5 the motor works fine. When I run the GUI to start the motor it says the GPIO is not set to output.
After adding the GPIO section to the GUI it no longer produces the error that GPIO isn't set up. Now it won't recognize the pulse from the raspberry pi. I've tried defining it in the GUI but it puts out the same error.
The error code is what follows:
'''
Run
Traceback (most recent call last):
File "RGUI.py", line 242, in <module>
motor_run()
File "RGUI.py", line 207, in motor_run
running = R.loop()
File "/home/pi/Desktop/CODES/RC5.py", line 67, in loop
motor(value)
File "/home/pi/Desktop/CODES/RC5.py", line 56, in motor
p.ChangeDutyCycle(95)
NameError: name 'p' is not defined
'''
'''
#The following code is for motor_run below to connect the GPIO pins
GPIO17 = 17
GPIO22 = 22
GPIO27 = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO17, GPIO.OUT)
GPIO.setup(GPIO22, GPIO.OUT)
GPIO.setup(GPIO27, GPIO.OUT)
p = GPIO.PWM(17 , 1000) # create PWM and set Frequency to 1KHz
'''
#The following code is to run/stop the motor
#running = True
def motor_run():
running = R.loop()
def on_start():
motor_run = True
def on_stop():
motor_run = False
frame5 = LabelFrame(main_canvas, text="Run Program", padx=5, pady=5, font=("Times", 20))
frame5.grid(row=3, column=0)
main_canvas.create_window((0,630), window=frame5, height=150, width= 200, anchor="s")
Button_run=Button(frame5, text="run", command=on_start, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_run.grid(row="2", column="0")
Button_stop=Button(frame5, text="stop", command=on_stop, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_stop.grid(row="2", column="1")
#The following is from the code RC5
#set up GPIO pins
GPIO.setup(17 , GPIO.OUT) # connected to pwm
GPIO.setup(22 , GPIO.OUT) # connect to In2
GPIO.setup(27 , GPIO.OUT) # connected to In1
p = GPIO.PWM(17 , 1000) # creat PWM and set Frequence to 1KHz
p.start(0)
def motor(ADC):
value = ADC
if (chan0 > -16384): # turn clockwise
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
print("Run")
p.ChangeDutyCycle(95)
elif (chan0 < -16348):
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
print("Run Slow")
p.ChangeDutyCycle(75)
# function calls
on_stop()
on_start()
motor_run()
update_value()
update_bat_1()
update_bat_2()
update_gen1()
#main()
main.mainloop()
python
tkinter
button
output
pi
0 Answers
Your Answer