Example #1
0
    def api_softpwm(self, pin, command, option, req_method, req_args):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        # Figure out our command
        if command == "start" and req_method == 'GET':
            # Get the arguments
            duty_cycle = req_args.get('duty_cycle', 25.0)
            frequency = req_args.get('frequency', 35.0)
            polarity = req_args.get('polarity', 0)
            # Start the SoftPWM
            SPWM.start(pin, duty_cycle, frequency, polarity)
            resp[
                "message"] = "Setting {0} to duty cycle: {1}, frequency: {2}, and polarity {3}".format(
                    pin, duty_cycle, frequency, polarity)
        elif command == "stop" and req_method == 'GET':
            SPWM.stop(pin)
            resp["message"] = "Stopping {0}".format(pin)
        elif command == "cleanup" and req_method == 'GET':
            SPWM.cleanup(pin)
            resp["message"] = "Cleaning up {0}".format(pin)
        elif command == "duty_cycle" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_duty_cycle(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        elif command == "frequency" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_frequency(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        return jsonify(resp)
Example #2
0
        print(f)
        time.sleep(.1)

    # Hold at high 50%
    print("Holding high at 50% duty")
    SPWM.set_duty_cycle("XIO-P7", 50)
    SPWM.set_frequency("XIO-P7", 5000)

    time.sleep(3)

    # Hold at high 100%
    print("Holding high at 100% duty")
    SPWM.set_duty_cycle("XIO-P7", 100)
    SPWM.set_frequency("XIO-P7", 5000)

    time.sleep(3)

    # Try higher frequency
    print("Holding high at 10000Hz")
    SPWM.set_frequency("XIO-P7", 10000)

    time.sleep(3)

except:
    print("An error hath occurred.")

# Cleanup afterwards
SPWM.stop("XIO-P7")
SPWM.cleanup()
GPIO.cleanup()
Example #3
0
    SPWM.cleanup()

    # ISSUE #16 VERIFICATION
    try:
        print(
            "VERIFYING FIX FOR ISSUE #16, GPIO CONFIGURED THAT SPWM WANTS TO USE"
        )
        GPIO.setup(SPWMGPIO, GPIO.OUT)
        SPWM.start(SPWMGPIO, 50, 1)
    except Exception as e:
        print("EXCEPTION: {}".format(e))
        print("GPIO CLEANUP")
        GPIO.cleanup()

    # SETUP SOFTPWM
    print("STARTING SOFTPWM TEST")
    SPWM.start(SPWMGPIO, 50, 1)
    SPWM.set_frequency(SPWMGPIO, 2)

    # SETUP SOFTPWM RECEIVER
    rcvr = SPWMReceiver(GPIO, RECEIVERGPIO, COUNT, SLEEPTIME)
    rcvr.start()

    time.sleep(COUNT * SLEEPTIME + 1)

    # CLEANUP
    print("CLEANUP")
    SPWM.stop(SPWMGPIO)
    SPWM.cleanup()
    GPIO.cleanup()
Example #4
0
    time.sleep(1)

    # SETUP PWM
    try:
        print("PWM START")
        #PWM.toggle_debug()
        PWM.start(PWMGPIO, 50, 45, 1)

        # UNCOMMENT FOR CRASH
        print("PWM SET FREQUENCY")
        PWM.set_frequency(PWMGPIO, 10)

        # UNCOMMENT FOR CRASH
        print("PWM SET DUTY CYCLE")
        PWM.set_duty_cycle(PWMGPIO, 25)

        #time.sleep(COUNT*SLEEPTIME + 1)
        raw_input("PRESS ENTER WHEN DONE")

    except:
        raise
    finally:
        # CLEANUP
        print("CLEANUP")
        PWM.stop(PWMGPIO)
        PWM.cleanup()
        #OM.unload("PWM0")
        #GPIO.cleanup()


Example #5
0
def cleanup():
	motorStop()
	PWM.stop(pin_pwm)
	GPIO.cleanup(pin_forward)
	GPIO.cleanup(pin_back)
	PWM.cleanup()