This is a simple GPIO traffic light demo on the Raspberry Pi. The software is written in C and Python.
Using the Starter Kit-A or Starter Kit-C wire up the breadboard as shown. Note, the cathode of the LED is the short lead which connects to ground.
Demo Software in C
Now download the software by:
For old rev 1 board
wget http://skpang.co.uk/dl/traffic_light.tar
Unpack the tar file and change into directory by:
tar xf traffic_light.tar
cd traffic_light
For new Rev 2 board
wget http://skpang.co.uk/dl/traffic_light_rev_2.tar
Unpack the tar file and change into directory by:
tar xf traffic_light_rev_2.tar
cd traffic_light_rev_2
Compile the software by:
make all
Start the example by:
sudo ./traffic_light
To stop the program running press CTL-C
The main program is traffic_light.c to edit this program use:
sudo nano traffic_light.c
You can try and change the value of the delay. Press CTL-X Y to save and exit.
To re-compile the program:
make all
Now you can run it again.
Demo Software in Python
If you have not installed Python and GPIO module, do the following:
sudo apt-get install python python-dev python-pip sudo easy_install -U distribute sudo pip install rpi.gpio
Download the python software by:
For old rev 1 board
wget http://skpang.co.uk/dl/traffic_light.py
Make it executable by:
chmod +x traffic_light.py
To run the program:
sudo ./traffic_light.py
For new rev 2 board
wget http://skpang.co.uk/dl/traffic_light_rev_2.py
Make it executable by:
chmod +x traffic_light_rev_2.py
To run the program:
sudo ./traffic_light_rev_2.py
Press CTL-C to stop
Parts List
gcc -o traffic_light gb_common.o traffic_light.o
/usr/bin/ld: error: gb_common.o uses VFP register arguments, traffic_light does not
/usr/bin/ld: failed to merge target specific data of file gb_common.o
collect2: ld returned 1 exit status
make: *** [traffic_light] Fehler 1
Have successfully loade and run the Demo Software in C but now want to use the Python version so I can make adjustments to the program (one programming language is more than enough).
Seems GPIO something not loaded so ran this ok
“sudo apt-get install python python-dev python-pip”
But this
“sudo easy_install -U distribute”
caused a “do not know Easy_install command”
And this
“sudo pip install rpi.gpio”
also came up with an error.
My board is B rev 1 and running Debian.
Can someone please help a newbie.
before ‘make all’ try ‘make clean’
Using a Raspberry Pi Revision 2 board, to get the North Side yellow LED to light I had to change 21 to 27 in the line #define YEL_NORTH (1<<21) in traffic_light.c, as the GPIO number for pin 13 has changed from GPIO21 to GPIO27. Presently my East Side LEDs are not lighting at all, though that may well turn out to be for some mundane reason unconnected with any GPIO number changes.
Were you ever able to get your East lights working? Mine aren’t working either.
Needed to connect positive on left and right side of board. Duh.
The links to files appear to be offline, any chance of bringing them back?
The blue text are not links. You need to type them in on your Pi.
same issue as craig..
when type
wget http://skpang.co.uk/dl/traffic_light_rev_2.py
get error
pi@raspberrypi ~ $ wget http://skpang.co.uk/dl/traffic_light_rev_2.py
bash: wget http://skpang.co.uk/dl/traffic_light_rev_2.py: No such file or directory
Instead of typing the text, use cut and paste.
That is exactly what i did
Make sure your Pi is connected to the internet and at the prompt cut and paste this line:
wget http://skpang.co.uk/dl/traffic_light_rev_2.py
You should get this reply:
wget http://skpang.co.uk/dl/traffic_light_rev_2.py
–2012-12-10 19:25:29– http://skpang.co.uk/dl/traffic_light_rev_2.py
Resolving skpang.co.uk (skpang.co.uk)… 77.235.53.95
Connecting to skpang.co.uk (skpang.co.uk)|77.235.53.95|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1395 (1.4K) [text/plain]
Saving to: `traffic_light_rev_2.py.3′
100%[======================================>] 1,395 –.-K/s in 0s
2012-12-10 19:25:29 (3.87 MB/s) – `traffic_light_rev_2.py.3′ saved [1395/1395]
Thank you
the line you entered allows me to copy and paste fine, however if i type or cut and paste from the web page i get errors. even on the chmod +x traffic_light_rev_2.py
so sorry for being completly useless, but this is my very first go.. Great customer service by the way.
Please email me a screen shot ( or take a photo of your screen) of the error. Email : sales@skpang.co.uk
I’m having issues with the yellow north.
I wasn’t sure which board I had so i checked with “cat /proc/cpuinfo” and got back 000f which is the 512mb version 2 I believe.
I ran the rev2 python code and it wouldn’t work and got stuck at line 23:
GPIO.setup(27, GPIO.OUT)
I ran the rev1 code and it worked except for the yellow north.
I’ve tried to get GPIO pin 21/27(now not sure what to call it!) independently but I can’t.
I’m now starting to think that this pin is fried.
I had the same problem with the yellow north i don’t know why the problem is there but i used this diagram (http://www.raspberrypi-spy.co.uk/wp-content/uploads/2012/09/Raspberry-Pi-GPIO-Layout-Revision-1-e1347664808358.png) and chose another three ports and updated the code both pyphon and c versions and it worked perfectly
The only other thing i noticed was that the c version had the CPU stuck at 100% whilst the pyphon version barely registered as expected.
Sorry to repeat this message but think I replied in the wrong place.
Have successfully loaded and run the Demo Software in C but now want to use the Python version so I can make adjustments to the program (one programming language is more than enough).
Seems GPIO something not loaded so ran this ok
“sudo apt-get install python python-dev python-pip”
But this
“sudo easy_install -U distribute”
caused a “do not know Easy_install command”
And this
“sudo pip install rpi.gpio”
also came up with an error.
My board is B rev 1 and running Debian.
Can someone please help a newbie.
You should try doing “sudo apt-get update” first, then follow the instructions again from the beginning
Dear Sir,
I had problems with the yellow north led not working on “traffic_light_rev_2″ written in c. The #define YEL_NORTH (1<<21) had been changed to (1<<27) but two more changes are required:-
// LEDs test GPIO mapping:
"GPIO21 = LED" must be changed to "GPIO27 = LED"
and in
void setup_gpio(void)
"INP_GPIO(21); OUT_GPIO(21)" must be changed to
"INP GPIO(27); OUT_GPIO(27)
Then the Yellow North led operates correctly.
Best Regards
Bill Cook
Have run Python version successfully using instructions direct from Linix prompt (using wheezy).
Have then opened User interface (startx)and then file manager. Opened file from here and tried to run but message as follows:
“RPi.GPIO. SetupException: No access to /dev/men. Try running as root!”
Again using file manager there does not seem to be a /dev/men folder.
Very new to this stuff and trying very hard to understand the basics. Do not want to just do everything by blindly following instructions.
Regards
It would be nice if the Python sample code ran GPIO.cleanup() on exit (e.g. by catching the KeyboardInterrupt exception) – otherwise when you hit Ctrl-C to stop you invariably have some LEDs stuck on.
Also the code doesn’t use GPIO.setwarnings(False) which may be confusing for beginners if they attempt to re-run the sample.
how are you supposed to connect the east side yellow led?