MagPi29.pdf

(14214 KB) Pobierz
ISSUE 29 - DEC 2014
Get printed copies
at themagpi.com
A Magazine for Raspberry Pi Users
Scratch
Spacecraft
Temperature Sensors
External Storage
Project Curacao
BASIC Robotics
Traffic Light
Python GUI
A+ Review
Using Git
OpenCV
Raspberry Pi is a trademark of The Raspberry Pi Foundation.
This magazine was created using a Raspberry Pi computer.
http://www.themagpi.com
29
Welcome to Issue 29 of the MagPi, packed with the usual mixture of hardware projects and
programming articles, providing lots of avenues for invention during December.
With the Christmas holidays drawing near, what could be better than some new Raspberry Pi hardware.
For all those looking forward to building a high altitude capsule or autonomous submarine, the Model A+
provides many great features for a very low power budget. Dougie Lawson presents a whistle-stop tour
of the A+, comparing it to other Raspberry Pi Models.
On the subject of robots, computer vision can provide an image cognition solution within many
autonomous robotics projects. Derek Campbell sketches out more features of OpenCV (open source
computer vision) image recognition software.
The Raspberry Pi is ideally suited as the hub of a sensor array or control unit, since it can be used to
propagate information via a web server or other remote protocol. In this Issue, John Shovic's presents
his final article in the Project Curacao remote monitoring series, David Bannon demonstrates how to
build and read a simple array of digital temperature sensors, and Brian Grawburg introduces his traffic
light extension board.
When developing software or projects, it is important to retain unique files that are part of the build. In
this Issue, Alec Clews continues his series on software repositories and using Git, and William Bell
discusses the basics of adding external storage to the Raspberry Pi.
Computer programming enables the Raspberry Pi to be used within many different applications. This
month, Jon Silvera discusses how to drive a robotic arm with FUZE BASIC, William Bell presents a
simple space arcade game in Scratch and Paul Sutton
introduces Python graphical user interfaces (GUIs).
The MagPi will be taking a short break over Christmas
and the first Issue of 201 5 will be published at the start of
February.
Merry Christmas and best wishes for 201 5.
Chief Editor of The MagPi
The MagPi Team
Ash Stone
- Chief Editor / Administration
Ian McAlpine
- Layout / Testing / Proof Reading
W.H. Bell
- Issue Editor / Administration / Layout
Bryan Butler
- Page Design / Graphics
Matt Judge
- Website
Nick Hitch
- Administration
Colin Deady
- Layout / Proof Reading
Aaron Shaw
- Administration
Dougie Lawson
- Testing
Nick Liversidge
- Layout / Proof Reading
Martin Wolstencroft
- Proof Reading
David Bannon
- Layout / Proof Reading
Shelton Caruthers
- Proof Reading
Rita Smith
- Proof Reading
Claire Price
- Proof Reading
2
Contents
4
TRAFFIC
a
LIGHT
Simulating bi-directional traffic light
8
PROJECT CURACAO
Part 6: Upgrades on the Beach
A+
1 4
NEW MODEL
latest Raspberry Pi hardware
Introducing the
OPENCV
1 8
INTRODUCING
Vision on the Raspberry Pi
Part 2: Computer
DIGITAL TEMPERATURE SENSOR
22
Logging temperature with 1 -wire sensor
BASIC
26
FUZE
Using FUZE BASIC to control a robot arm
Part 5:
31
EXTERNAL STORAGE
tables and rsync
Part 1 : File systems, partition
36
VERSION CONTROL
Git - Part 3
Version control basics using
PATCH: GOING BALLISTIC
40
SCRATCH
land on Mars
Learning to
43
THIS MONTH'S EVENTS
Ireland, Glasgow, Saarbrücken
Manchester, Lagos, Northern
PIT: MAGIC 8
44
PYTHON
GUI with Python's
BALL
Creating a
Tkinter
http://www.themagpi.com
3
Simulating a bi-directional
traffic light
SKILL LEVEL : BEGINNER
The Imagination Station Science Museum in
North Carolina (USA) offers several Raspberry
Pi and Python classes and camps. This article
is a shortened version of a project given to the
students after they've completed about 20 hours
a preliminary exposure to the Pi and Python. A
previous project introduced the use of an 8 port
I/O expander (MCP23008) and provided
sufficient background in binary and
hexadecimal numbering to enable them to
complete this project on their own. New to this
project was the CD74AC02 Quadruple 2-input
NOR gate IC and the use of two MCP2301 7
chips (1 6 I/O ports each).
Brian Grawburg
Guest Writer
then both reds are on for a short time
simultaneously until the cycle starts over.
Most intersections with a separate left-turn lane
don't usually activate the left-turn lights if there
are no cars in the lanes. For this project
momentary push-buttons simulate a car in the
lane to activate both left-turn lanes.
The MCP2301 7s could be fitted to a
breadboard and then wired back to the Pi's
GPIO pins with jumpers, however I decided to
use a pre-fabricated Protect Your Pi board from
MyPiShop.com to make the connections much
easier. In addition, the board can be reused for
a variety of projects.
Overview of the Project
A typical traffic signal at a major intersection in
the U.S. has a red-yellow-green light and often a
left-turn signal, also with red-yellow-green
lights/arrows. Although many intersections are
asymmetrical as regards turning lanes and
timing, for this project I limited the number to
two symmetrical directions – North
(representing
north-south)
and
East
(representing east-west).
Like a real traffic signal, the Python code turns
on the red for one direction while the green and
then yellow are on for the opposite direction;
4
The project uses 1 2 LEDs and 1 2 resistors; I
made PCBs for the students to use because I
felt it was much easier to work with a PCB than
a breadboard. The CD74AC02 and the
pushbuttons, however, are on a breadboard.
About the CD7AC Chip
project was trying to incorporate the left-turn
option into the Python code. No doubt there
was a way to do it but I couldn't figure it out (I
saw one possible way, but it required a lot of
code). Here's where being part of a user group
can really make a difference. I'm active in the
Triangle
Embedded
Devices
group
(www.triembed.org) and posted a series of
emails to the group; got a great answer that I'm
using here.
One of the more f
rustrating aspects of this
with the normal cycle run the left turn cycle.”
Back in 201 0/201 1 I took a year-long course at
a local community college on programming
PLCs (Programmable Logic Controllers). One of
the basic functions is latching an output,
meaning that when it is set high it would remain
high until specifically set low by the program.
That's what I was trying to do within the Python
code.
The CD74AC02 contains four independent 2-
input NOR gates as diagrammed below (NOR
is an abbreviation for NOT OR, two options in
logic construction). I needed to make a latching
Set-Reset flip flop: a logic circuit that has two
inputs and one output. Latch circuits can be
either active-high or active-low.
Active-high circuit:
Both inputs are normally
tied to ground (LOW) by a pull-down resistor
and the latch is triggered by a momentary HIGH
signal on either of the inputs.
The “problem”: As the lights were cycling
through I wanted to push a button to simulate a
car pulling into the left turn-only lane which then
activates something to tell the program “there's
a car that wants to turn so when you're finished
HIGH, and the latch is triggered by a
momentary LOW signal on either input.
In an active-high latch when the SET input goes
HIGH, the output also goes HIGH. When the set
input returns to LOW, however, the output
remains HIGH. The output of the active-high
latch stays HIGH until the RESET input goes
HIGH. Then, the output returns to LOW and will
Active-low circuit:
Both inputs are normally
5
Zgłoś jeśli naruszono regulamin