Sunday, February 24, 2013

Raspberry PI-Example #1 GPIO Control with Python

Raspberry PI-Example #1 GPIO Control with Python

First you must either buy a GPIO enhancement device or make one.  I choose to make one, by simply remove the header off one end of a GPIO cable I bought for my unit.  Once removed I then soldered all 26 point to a circuit board.  I then soldered a solderless header to the circuir board and solder each pin point for connectivity.  I tehn made some stand offs out of bolts and attached the harness to the board so that the soldered joint wouldn't weaken.  Once done you then can connect each pin to a solderless bread board via jumper wire.

Next I located the pins and the pin out diagram and proceeded label and verify the documentation. Here is an example of what I figured out and tested.

Then I got my breadboard and followed the GND pin with a jumper wire to a GND point on the bread board, I used Pin #6. Next I place a 330 ohm resistor in series to the GND.  Then I connected the GND pin of an LED to the resisitor.  Next I then connected a jumper wire from pin 12 (GPIO 18) to the positive terminal of the LED on the bread board.  Using the resistor will control the current to the LED to approx 10mA. keep in mind no Pin connection of the GPIO should exceed 50mA or you may damage your Raspberry PI.
Next step is to write our code using Python through the application of "IDLE 3".  

Once code is written you must save it as a file.  Once saved the program can only be run successfully as a ROOT user.  I then open up the terminal window and login as a ROOT USER.
 Next type SU and then enter the password and then you shall be a root user.
Once I am in terminal mode as a ROOT USER, I then execute my save program,
by entering"python a.py" as "a.py" is the filename I gave my code.

Once that is complete your LED should light up.  Now to turn it off, just change your code statement to a "False" from "True" and then follow these procedures again.

Thank You for you interest
Paul Fowler


No comments:

Post a Comment