Skip to content

Instantly share code, notes, and snippets.

@davidraedev
Created October 5, 2015 17:00
Show Gist options
  • Save davidraedev/a47b52f3465542e7409b to your computer and use it in GitHub Desktop.
Save davidraedev/a47b52f3465542e7409b to your computer and use it in GitHub Desktop.
RPi Python Quickstart for TheKnobleJosh
# a pretty good overview here
# http://openmicros.org/index.php/articles/94-ciseco-product-documentation/raspberry-pi/217-getting-started-with-raspberry-pi-gpio-and-python
# quick python overview
# indentation is important, things like loops MUST be indented and the first part ends with a colon
# for a in b:
# do something
# arrays are called lists. [ a,b,c,d,e ]
# arrays with custom keys are called dictionaries. { a: 1, b: 2, c: 3 }
# concatting text is done with plus signs. "Why" + " Hello " + "There!"
# print() takes only strings, if you have anything else, call str() on it. print( "This is line number: " + str( 14 ) )
# to import a library, you can import part or all of it.
# import time
# time.sleep(5) OR
# import time.sleep as sleep
# sleep(5)
# Python comes in two versions. 2 and 3
# you might as well use version 3, which is called by "python3"
# but you might occasionally run in to tutorials or libraries written in version 2 "python"
# import the GPIO library
import RPi.GPIO as GPIO
import time
# set the pin number scheme ( BCM = Broadcom chip, BOARD = the pins )
GPIO.setmode( GPIO.BCM )
# Print "Hello Josh!"
print( "Hello Josh!" )
# set up the pins to use
pins = [ 11,12 ]
GPIO.setup( pins, GPIO.OUT )
# set a pin ( or list of pins ) to on/off ( takes 0 / GPIO.LOW / False or 1 / GPIO.HIGH / True )
while True:
GPIO.output( [ 11,12 ], 1 )
time.sleep( 0.8 )
GPIO.output( [ 11,12 ], 0 )
time.sleep( 0.8 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment