Hardware Reference
In-Depth Information
We need to set the mode in which the GPIO pins are being used. There
are two modes, namely the board's GPIO mode and the BCM GPIO
mode (more information available on http://sourceforge.net/p/
raspberry-gpio-python/wiki/ ) . The former refers to the pin numbers
on the Raspberry Pi board while the latter refers to the pin number found
on the Broadcom chipset. In this example, we will adopt the BCM chipset's
pin description.
We will set the pin 25 to be an output pin and set it to false so that the
Christmas tree lights are switched off at the start of the program:
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, False)
In the preceding routine, we are switching off the lights and turning them
back on with a three-second interval:
while 1:
GPIO.output(25,True)
sleep(3)
GPIO.output(25,False)
sleep(3)
3.
When the pin 25 is set to high, the device is turned on, and it is turned off when the
pin is set to low with a three-second interval.
Connecting multiple appliances to the Raspberry Pi
Let's consider a scenario where we have to control muliple appliances using the Raspberry Pi.
It is possible to connect a maximum of 15 devices to the GPIO interface of the Raspberry Pi.
(There are 17 GPIO pins on the Raspberry Pi Model B, but two of those pins, namely GPIO14
and 15, are set to be UART in the default state. This can be changed after startup. It is also
possible to connect a GPIO expander to connect more devices to Raspberry Pi.)
In the case of appliances that need to be connected to the 110V AC mains, it is recommended
that you use muliple power switch tails to adhere to safety pracices.
In the case of decoraive lights that operate using a batery (for example, a two-feet Christmas
tree) or appliances that operate at low voltage levels of 12V DC, a simple transistor circuit and
a relay can be used to connect the devices. A sample circuit is shown in the figure that follows:
 
Search WWH ::




Custom Search