Home page 1

Raspberry Pi

A simple start

Hope this helps someone

I wanted to understand programming the raspberry Pi using Python to control the RPIO outputs.

I did not want to buy extra boards or download other peoples written programmes.

************

My main intitial problem was understanding that the GPIO library is not installed in IDLE 3

and that you cannot just work in python and expect the GPIO control pin bit to work - you have to use sudo to run a programme.

Open up IDLE .........Not IDLE 3
Under File - New Window
Write your programme in the new window
e.g.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD) ...... sets to pin number - for GPIO number change BOARD to BCM
GPIO.setup(11, GPIO.OUT) .....Note I connected my light/resistor to pin 11 or GPIO 17
GPIO.output(11,True) .......Turns light on
time.sleep(2) ..........wait a couple of seconds
GPIO.output(11,False) ..........Turns light off

Save the file as an example lights1

To run it click on the start button - bottom left
click on run and type
sudo python lights1.py ..... for lights1 put your saved name
IF you save it in a folder e.g. Python
then type
sudo python Python/lights1.py

I butchered a printer cable - which fits on the GPIO pins of the Pi and soldered on some pins at the other end - these fit into a standard breadboard

I bought some led's and resistors as well as wires to use as jump wires with the breadboard.

first setup

yellow wire from Pin 6 or Ground to one end of the resistor

white lead from pin 11 or GPIO 17 to long leg on the LED

Short leg of LED to resistor.

Raspberry Pi breadboard

Raspberry PI

***********

I then wanted to enter a number so that I could tell it how long to put the light on.

from Tkinter import *
root = Tk()
root.withdraw()
import tkSimpleDialog
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
print (number)

this little programme pops up a box asking for a number - which is then put into the variable number

also prints it out just to check

************

Now substitute number instead of the 2 and it asks for a number - you input it - and then it lights the light for that length of time.

Open up IDLE .........Not IDLE 3
Under File - New Window
Write your programme in the new window
e.g.
import RPi.GPIO as GPIO
import time

from Tkinter import *
root = Tk()
root.withdraw()
import tkSimpleDialog
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
print (number)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11,True)
time.sleep(number)
GPIO.output(11,False)

My programme is named lights1 and is in a folder called Python

so to run it Save the file

To run it click on the start button - bottom left
click on run and type
sudo python Python/lights1.py

************

Any comments to

brian @ ftfarm.co.uk

remove spaces either side of @ - left to stop robots getting my email.