Skip to content

Instantly share code, notes, and snippets.

@omiq
Created April 5, 2018 19:52
Show Gist options
  • Save omiq/3b5409df4268be1210721bf5c9bf5422 to your computer and use it in GitHub Desktop.
Save omiq/3b5409df4268be1210721bf5c9bf5422 to your computer and use it in GitHub Desktop.
Basic Pi GPIO example
import RPi.GPIO as GPIO
import time
# Pi has (confusingly) two numbering schemes for pins
# usually you would choose based on what is printed on
# your dongles/pinout prints
GPIO.setmode(GPIO.BCM)
# H-Bridge pins
motor_pin_A1 = 7
motor_pin_A2 = 8
motor_pin_B1 = 9
motor_pin_B2 = 10
# Set all the pins as output
GPIO.setup(motor_pin_A1, GPIO.OUT)
GPIO.setup(motor_pin_A2, GPIO.OUT)
GPIO.setup(motor_pin_B1, GPIO.OUT)
GPIO.setup(motor_pin_B2, GPIO.OUT)
# Fire up the pins!
GPIO.output(motor_pin_A1, True)
GPIO.output(motor_pin_A2, False)
GPIO.output(motor_pin_B1, True)
GPIO.output(motor_pin_B2, False)
# Wait a second
time.sleep(1)
# Stop all the pins
GPIO.output(motor_pin_A1, False)
GPIO.output(motor_pin_A2, False)
GPIO.output(motor_pin_B1, False)
GPIO.output(motor_pin_B2, False)
# Clean up
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment