Пример #1
0
def gpio_setup():
    """
    Setup GPIO_PIN as PWM input and start fan
    """

    try:
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(GPIO_PIN, GPIO.OUT)
        fan = GPIO.PWM(GPIO_PIN, PWM_FREQ)
        return fan
    except IndexError:
        print('\n Error: Pin "{0}" does not exist.\n')
        sys.exit(2)
    else:
        print('\n Error: Could not setup GPIO pin "{0}".\n'.format(GPIO_PIN))
        sys.exit(4)
    def __init__(self):
        #        rospy.init_node("spinny")
        self.command_topic = '/motor_speed'
        self.sub = rospy.Subscriber(self.command_topic, Int32,
                                    self.speed_callback)

        print("Setting up GPIO pins")
        #    rospy.on_shutdown(self.shut)

        self.pwm_pin = 16
        self.power_pin = 18

        GPIO.setwarnings(True)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.pwm_pin, GPIO.OUT)
        GPIO.setup(self.power_pin, GPIO.OUT, initial=GPIO.HIGH)

        print("Starting PWM output")
        self.p = GPIO.PWM(self.pwm_pin, 50)
        self.p.start(0)
Пример #3
0
GPIO.setwarnings(True)
GPIO.setmode(GPIO.ROCK)
GPIO.setup(var_gpio_out, GPIO.OUT, initial=GPIO.HIGH)       # Set up GPIO as an output, with an initial state of HIGH
GPIO.setup(var_gpio_in, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # Set up GPIO as an input, pullup enabled

# Test Output
print("")
print("Testing GPIO Input/Output:")

var_gpio_state = GPIO.input(var_gpio_out)                   # Return state of GPIO
print("Output State : " + str(var_gpio_state))              # Print results
sleep(1)
GPIO.output(var_gpio_out, GPIO.LOW)                         # Set GPIO to LOW

# Test PWM Output
p=GPIO.PWM(var_gpio_out, 60)                                # Create PWM object/instance

print("")
print("Testing PWM Output - DutyCycle - High Precision:")
print("60Hz at 50% duty cycle for 1 second")
p.start(50)
sleep(1)
print("60Hz at 25% duty cycle for 1 second")
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)
Пример #4
0
#!/usr/bin/env python                                                                                   

import R64.GPIO as GPIO
from time import sleep
import rospy
from std_msgs.msg import Int32

pwm_pin=16
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")
Пример #5
0
import R64.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT, initial=GPIO.HIGH)

p = GPIO.PWM(16, 50)
p.start(0)
sleep(5)
p.ChangeDutyCycle(20)
sleep(5)
p.ChangeDutyCycle(40)
sleep(5)
p.ChangeDutyCycle(60)
sleep(5)
p.ChangeDutyCycle(80)
sleep(5)
p.ChangeDutyCycle(98)
sleep(5)
p.stop()
GPIO.cleanup()