Exemple #1
0
def main():
    """
    Run temperature check every 3 seconds untill stopped by user
    """

    try:
        logging.info('Started fan service...')
        setup(PIN)
        while True:
            temp = get_temp()
            check_temp(temp, MIN_TEMP, MAX_TEMP)
            sleep(2)
    except KeyboardInterrupt:
        logging.info('Stopped fan service...')
    finally:
        fan_switch(GPIO.LOW)
        GPIO.cleanup(PIN)
Exemple #2
0
def main():
    """
    Run temperature control service
    """

    try:
        old_temp, old_speed = 0, 0
        fan = gpio_setup()
        fan.start(MIN_SPEED)
        logging.info('Started temperature control service...')
        while True:
            temp, speed = temp_ctrl(fan, old_temp, old_speed)
            old_temp, old_speed = temp, speed
            sleep(INTERVAL)
    except KeyboardInterrupt:
        fan.stop()
        logging.info('Stopped temperature control service.')
    else:
        fan.stop()
        logging.error('Unexpected error occurred, please check script.')
    finally:
        GPIO.cleanup(GPIO_PIN)
Exemple #3
0
p.ChangeDutyCycle(25)
sleep(1)
print("60Hz at 10% duty cycle for 1 second")
p.ChangeDutyCycle(10)
sleep(1)
print("60Hz at  1% duty cycle for 1 second")
p.ChangeDutyCycle(1)
sleep(1)
p.stop()

print("")
print("Testing PWM Output - Frequency - Low Precision:")
print("60Hz at 50% duty cycle for 1 second")
p.start(50, pwm_precision=GPIO.LOW)
sleep(1)
print("30Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(30)
sleep(1)
print("20Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(20)
sleep(1)
print("10Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(10)
sleep(1)
p.stop()

GPIO.cleanup([var_gpio_in, var_gpio_out])                   # Perform cleanup on specified GPIOs

print("")
print("Test Complete")
Exemple #4
0
power_pin=18
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pwm_pin, GPIO.OUT)
GPIO.setup(power_pin, GPIO.OUT, initial=GPIO.HIGH)

print("Starting PWM output")
p=GPIO.PWM(pwm_pin,50)
p.start(0)


def speed_callback(msg):
    num = msg.data
    p.ChangeDutyCycle(num)
    print("Changing Duty Cycle")
    print(num)



if __name__ == "__main__":
    rospy.init_node("spinny")

    print("Setting up GPIO pins")
    
    sub = rospy.Subscriber('/motor_speed', Int32, speed_callback)

    rospy.spin()

    p.stop()
    GPIO.cleanup()
print("")
print("Testing GPIO Input/Output:")

# Set Variables
var_gpio_out1 = 16
var_gpio_in1 = 18

# GPIO Setup
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BOARD)

# Test Output
GPIO.setup(var_gpio_out1, GPIO.OUT, initial=GPIO.HIGH
           )  # Set up GPIO as an output, with an initial state of HIGH
var_gpio_state = GPIO.input(var_gpio_out1)  # Return state of GPIO
print("Output State : " + str(var_gpio_state))  # Print results
sleep(0.5)
GPIO.output(var_gpio_out1, GPIO.LOW)  # Set GPIO to LOW
GPIO.cleanup(var_gpio_out1)  # Cleanup GPIO

# Test Input
GPIO.setup(var_gpio_in1, GPIO.IN,
           pull_up_down=GPIO.PUD_UP)  # Set up GPIO as an input, pullup enabled
var_gpio_state = GPIO.input(var_gpio_in1)  # Return state of GPIO
print("Input State  : " + str(var_gpio_state))  # Print results
GPIO.cleanup(var_gpio_in1)  # Cleanup GPIO

print("")
print("Test Complete")