Short python program to change voltages in rpi gpio pins.

First I installed python:

sudo apt-get install python-pip

and then a library for gpio:

sudo pip install rpi.gpio

Once that was done, the following python script sets a high and low voltage to physical pin 11. Note: the physical pin 11 corresponds to GPIO 17.  The physical pin 6 corresponds to Ground.  For additional details and diagrams refer to: http://elinux.org/RPi_Low-level_peripherals.

import RPi.GPIO as GPIO
import time
for i in range(5):
   print ‘——————‘
   print ‘now in repetition:’,i
   GPIO.setmode(GPIO.BOARD)
   GPIO.setup(11,GPIO.OUT)
   print ‘ON…’
   GPIO.output(11,GPIO.HIGH)
   time.sleep(5)
   GPIO.output(11,GPIO.LOW)
   print ‘OFF…’
   time.sleep(5)

To run the program above, I created a script prendeApaga.py and ran it as shown below:

sudo python prendeApaga.py

Note: additional information for the rpi unit:

linux distribution: ID=debian

user: pi

password: raspberry

 available from: MCM electronics: http://www.mcmelectronics.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: