Hardware Reference
In-Depth Information
Engage thrusters
1.
In order to test the device, there are two opions to control the device the GPIO Pins
of the Raspberry Pi. This can be controlled either using the quick2wire GPIO library
or using the Raspi GPIO library.
The main difference between the quick2wire gpio library and the Raspi
GPIO library is that the former does not require that the Python script to
be run with root user privileges (to those who are not familiar with root
privileges, the Python script needs to be run using sudo ). In the case of
the Raspi GPIO library, it is possible to set the ownership of the pins to
avoid executing the script as root. This is left as some homework for you.
2. Once the installaion is complete, let's turn on/of the lights on the tree with a three
second interval. The code for it is given as follows:
# Import the rpi.gpio module.
import RPi.GPIO as GPIO
#Import delay module.
from time import sleep
#Set to BCM GPIO
GPIO.setmode(GPIO.BCM)
# BCM pin 25 is the output.
GPIO.setup(25, GPIO.OUT)
# Initialise Pin25 to low (false) so that the Christmas tree
lights are switched off.
GPIO.output(25, False)
while 1:
GPIO.output(25,False)
sleep(3)
GPIO.output(25,True)
sleep(3)
In the preceding example, we will get started by importing the raspi.gpio
module and the time module to introduce a delay between turning on/off
the lights:
import RPi.GPIO as GPIO
#Import delay module
from time import sleep
 
Search WWH ::




Custom Search