Element 14 Raspberry Pi User Manual page 28

Table of Contents

Advertisement

The first just sets the pins to the right
mode and makes sure they're turned off:
pins="7 8 25 24 23 18 15 14"
for x in $pins
do
gpio -g mode $x out
gpio -g write $x 0
done
The second grabs the IP address from
, converts it to binary, then pads
ifconfig
it out with leading zeros, if necessary.
ipaddress=`ifconfig eth0 | grep
'inet ' | awk '{print $2}' | cut
-f4 -d'.'`
binary=`echo
"ibase=10;obase=2;$ipaddress" | bc`
paddedBinary=`printf %08d $binary`
The next part uses
cut
part we want from this binary string
and outputs it to the appropriate pin.
Gertboards and Arduinos
Connecting directly to your Pi's GPIO pins can
provide you with basic input and output control,
but there are limitations. There are two additional
items that you can obtain to help you interact
more precisely with the world around you.
The Gertboard is a fairly complete expansion
pack for connecting between your Pi and
the real world, including a micro controller,
and a range of input and output options.
Meanwhile, the Arduino is a micro controller that
can connect to your Pi (or any other computer)
via the USB port. Typically, it comes assembled,
but kit forms are also available. In its raw form,
it has fewer features than the Gertboard (which
includes an Arduino microcontroller), but it can
be expanded with a huge range of shields.
28
Raspberry Pi User Guide.indd 28
bit=1
for x in $pins
do
-b$bit`
done
And, finally, we tell the script to sleep for
five minutes, then turn the LEDs off.
sleep 5m
for x in $pins
do
done
That's it! Save this into a file called
showIP.sh
chmod a+x showIP.sh
to extract the
and type
your IP. To get this run automatically on
boot, you just need to add the line:
/home/pi/showIP.sh &
to
rc.local
section for details on how to do this.
out=`echo $paddedBinary | cut
gpio -g write $x $out
bit=$((bit+1))
gpio -g write $x 0
, make it executable with:
to display
sudo ./showIP.sh
. See the 'Camera controller'
Figure 3. The simple circuit in all its glory.
08/07/2014 14:44

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Element 14 Raspberry Pi

Table of Contents