예제 #1
0
def setup(pin):
    """
    Setup GPIO pin
    """

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(pin, GPIO.OUT)
    GPIO.setwarnings(False)
예제 #2
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)
예제 #4
0
print("GPIO.BCM       " + str(GPIO.BCM))
print("GPIO.OUT       " + str(GPIO.OUT))
print("GPIO.IN        " + str(GPIO.IN))
print("GPIO.HIGH      " + str(GPIO.HIGH))
print("GPIO.LOW       " + str(GPIO.LOW))
print("GPIO.PUD_UP    " + str(GPIO.PUD_UP))
print("GPIO.PUD_DOWN  " + str(GPIO.PUD_DOWN))
print("GPIO.VERSION   " + str(GPIO.VERSION))
print("GPIO.RPI_INFO  " + str(GPIO.RPI_INFO))

# Set Variables
var_gpio_out = 82
var_gpio_in = 81

# GPIO Setup
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
예제 #5
0
MQTT_OFF = "OFF"
MQTT_TOGGLE = "TOGGLE"

# The RockPro version of the library seems to return strings not ints - is this
# intended behavior?
HIGH = "1"
LOW = "0"

#LED_PIN = 27
#BUTTON_PIN = 4
LED_PIN = 16
BUTTON_PIN = 13

GPIO.setmode(GPIO.BOARD)
GPIO.setrock('ROCKPRO64')
GPIO.setwarnings(False);

GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, GPIO.LOW)
led_state = False

time.sleep(1)

GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

class MyHandlerForHTTP(BaseHTTPRequestHandler):
    """
    Handler for HTTP messages
    """
    def do_GET(self):
        global led_state