One of the few things that separates the Pi from other SBC (Single Board Computer) is the ability to use the GPIO (General Purpose Input/Output) pins which can be set as HIGH or LOW to control any external devices. All you need is a female to male jumper wire to get started. Here I have used a HDD IDE connector to get the job done.
Software Implementation:-
The fastest way to get started is to use python which comes pre-installed with all images. Download theRPi.GPIO library and copy the gz tar ball to the RPi wheezy raspbian. Open the terminal and navigate to the extracted folder containing the RPi.GPIO library. Then type: $ sudo python setup.py install to install the module. Imp: As the OS is multitasking and not Real-time unlike Arduino there may be jitters depending on CPU priority.
Based on the library I have written a simple code to turn ON and turn OFF the LED after a delay of 1 sec (1000ms) each.The LED blinks 50 times.
- import RPi.GPIO as GPIO
- import time
- # blinking function
- def blink(pin):
- GPIO.output(pin,GPIO.HIGH)
- time.sleep(1)
- GPIO.output(pin,GPIO.LOW)
- time.sleep(1)
- return
- # to use Raspberry Pi board pin numbers
- GPIO.setmode(GPIO.BOARD)
- # set up GPIO output channel
- GPIO.setup(11, GPIO.OUT)
- # blink GPIO17 50 times
- for i in range(0,50):
- blink(11)
- GPIO.cleanup()
0 comments:
Posting Komentar