PWM stops after short time - Raspberry Pi Forums
hi guys,
reason can't pwm function... have no idea why it's switch on correctly after 'sleep' on it's automatically shuts off. can't seem find in code suggesting pwm.stop() command...
i'm trying in 'up' statement setting count '1' , thereby disabling next time if class activate pwm signal again due continuous pressing of button. count stored in __init__ statement make sure kept when class exited.
i've added print 'pause' statement check if possibly count reset 0 else statement. see no print of statement guess problem should not here.
can me solve problem? or there possibly better solution model this?
thanx in advance!
code:
reason can't pwm function... have no idea why it's switch on correctly after 'sleep' on it's automatically shuts off. can't seem find in code suggesting pwm.stop() command...
i'm trying in 'up' statement setting count '1' , thereby disabling next time if class activate pwm signal again due continuous pressing of button. count stored in __init__ statement make sure kept when class exited.
i've added print 'pause' statement check if possibly count reset 0 else statement. see no print of statement guess problem should not here.
can me solve problem? or there possibly better solution model this?
thanx in advance!
code:
code: select all
import cwiid, time #wii module, time module import rpi.gpio gpio #the gpio module class states: def __init__(self): #first disable ports when creating class gpio.output(4,false) #ena gpio.output(27,false) #in1 (forward) gpio.output(22,false) #in2 (backward) gpio.output(23,false) #in3 (forward) gpio.output(24,false) #in4 (backward) gpio.output(5,false) #enb self.count = 0 def press(self,state): #now following controlling motors if state == 'up' , self.count != 1: gpio.output(4,true) #ena gpio.output(27,false) #in1 gpio.output(22,true) #in2 gpio.output(23,false) #in3 gpio.output(24,true) #in4 gpio.output(5,true) #enb time.sleep(.5) p2=gpio.pwm(22,50) p3=gpio.pwm(24,50) print 'pwm activated' time.sleep(.5) p2.start(75) p3.start(75) print 'pwm started' self.count = 1 else: #do following when no buttons pressed: try: p1.stop() except unboundlocalerror: print 'unbound error 1' try: p2.stop() except unboundlocalerror: print 'unbound error 2' try: p3.stop() except unboundlocalerror: print 'unbound error 3' try: p4.stop() except unboundlocalerror: print 'unbound error 4' print 'pause' gpio.output(4,false) #ena gpio.output(27,false) #in1 gpio.output(22,false) #in2 gpio.output(23,false) #in3 gpio.output(24,false) #in4 gpio.output(5,false) #enb self.count = 0 print 'class exited' def main(): print 'initializing...' time.sleep(1) #create instances use on board , set output print 'mapping gpio ports...' gpio.setwarnings(false) #disable warnings gpio.setmode(gpio.bcm) #use bcm board layout (gpio numbering) gpio.setup(4,gpio.out) #engine on gpio.setup(5,gpio.out) #engine b on gpio.setup(27,gpio.out) #in1 (forward engine a) gpio.setup(22,gpio.out) #in2 (backward engine a) gpio.setup(23,gpio.out) #in3 (forward engine b) gpio.setup(24,gpio.out) #in4 (backward engine b) time.sleep(2) #create connection wii mote wiimote=cwiid.wiimote() #connects wii print 'connected' #now make sure wii remote reports pressed buttons wiimote.rpt_mode = cwiid.rpt_btn #create class button=states() while wiimote.state['buttons'] != 128: if wiimote.state['buttons'] == 512: button.press('up') else: button.press('pause') print 'closing ports' gpio.output(4,false) #ena gpio.output(27,false) #in1 gpio.output(22,false) #in2 gpio.output(23,false) #in3 gpio.output(24,false) #in4 gpio.output(5,false) #enb gpio.cleanup() main()
i didn't if using frequent pwm starts , stops stop doing so. try setting dutycycle 0 rather doing stop/start.
raspberrypi
Comments
Post a Comment