Вы находитесь на странице: 1из 11

Simple Sensor Network

This pioject can seive as a mouel loi almost any sensoi netwoik you`u like to Luilu.
You will cieate a set ol inexpensive tempeiatuie sensois that aie mesh-netwoikeu to-
gethei to stieam theii uata to a Lase station iauio. This Lase station will Le connecteu
to a computei wheie the ieal-time tempeiatuie uata will Le visualizeu on the scieen.
In the next chaptei we will uiscuss making the sensoi noues veiy powei-ellicient so
that they can Le iun ellectively liom Latteiies. Foi now, these noues can Le poweieu
liom wall outlets so we can concentiate on the Lusiness ol Luiluing oui liist complete
wiieless sensoi netwoik.
The example pioject in Figuie 5-3 shows two sensoi noues anu a Lase
station. That`s thiee iauios in total. Il you have only two iauios, you can
Luilu it with a single sensoi noue anu the Lase station. You can also
cieate many moie sensoi noues. Il youi netwoik has moie than 10
noues, iememLei to extenu the Piocessing coue to change the uisplay
size anu limits so that it can show all the uata.
Iigurc 5-3. Sinp|c scnsor nctwor|
Parts
Two solueiless LieauLoaius (AF 6+, DK +3S-10+5-ND, SFE PRT-09567)
Hookup wiie oi jumpei wiie kit (AF 153, DK 923351-ND, SFE PRT-0012+)
142 | Chapter 5:API and a Sensor Network
Two 9-volt oi 5-volt powei supplies (9-volt Latteiies also woik well loi shoit-teim
use) (AF 63, oi S0 with 9 V Latteiy, RS 273-355, SFE TOL-0S269 oi TOL-0029S)
Two 3.3 V voltage iegulatois (TO-220 package) (DK +97-1+91-5-ND, SFE
COM-00526)
Two DC powei jacks (2.1 mm ID, 5.5 mm OD) (DK CP-02+A-ND, RS 27+-1577,
SFE PRT-00119)
Two 100K ohm iesistois (DK P100KBACT-ND, RS 271-13+7, SFE has an assoiteu
iesistoi kit: COM-0925S)
Two 200K ohm iesistois (DK P200KBACT-ND, oi use two 100K iesistois in seiies
loi each Loaiu)
Two 300 ohm iesistois (DK P300BACT-ND, RS 271-012)
Two 10 F electiolytic capacitois (DK P966-ND, RS 272-1025, SFE COM-00523)
Two 1 F electiolytic capacitois (DK P993-ND, RS 272-1+3+)
Two LM335 tempeiatuie sensois (in TO-92 packaging) (DK +97-2977-5-ND, SFE
SEN-09+3S)
One XBee iauio (Seiies 2/ZB liimwaie) conliguieu as a ZigBee Cooiuinatoi API
moue (Digi: XB2+-Z7VIT-00+, DK 602-109S-ND)
Two XBee iauios (Seiies 2/ZB liimwaie) conliguieu as a ZigBee Routei AT moue
(Digi: XB2+-Z7VIT-00+, DK 602-109S-ND)
Two XBee Lieakout Loaius with male heaueis anu 2 mm lemale heaueis installeu
(AF 126 (auu SFE PRT-00116), SFE BOB-0S276, PRT-0S272, anu PRT-00116)
XBee USB seiial auaptei (XBee Exploiei, Digi Evaluation Loaiu, oi similai) (AF
2+7, SFE VRL-0S6S7)
USB caLle loi XBee auaptei (AF 260, SFE CAB-0059S)
Viie stiippeis (AF 1+7, DK PAL70057-ND, SFE TOL-0S696)
Prepare Your Coordinator Radio
1. Follow the instiuctions unuei Reauing Cuiient Fiimwaie anu Conliguia-
tion on page 35 in Chaptei 2 to conliguie one ol youi iauios as a ZigBee Cooiui-
natoi API. Note that youi FRRUGLQDWRU iauio PXVW use the API liimwaie loi this
pioject to woik Lecause I/O uata is only ueliveieu in API moue. Be suie to select
the API veision loi youi cooiuinatoi!
Vhen you change liom AT to API moue using X-CTU, you may
get an eiioi message that the iauio is no longei communicating.
Go Lack to the PC Settings taL anu check the EnaLle API Lox to
enaLle communications with youi iauio. Vhen you latei change
API moue to 2, go Lack to that taL anu choose Use escape chai-
acteis (ATAP = 2).
Simple Sensor Network | 143
2. Once a iauio has Leen set to API moue it can RQO\ Le conliguieu in X-CTU. You
will not Le aLle to make aujustments to this iauio`s conliguiation in CoolTeim.
Use X-CTU to conliguie the cooiuinatoi with a PAN ID (Letween 0x0 anu
0xFFFFFFFFFFFFFFFF) that you`ve selecteu, then click Viite. Viite uown this
PAN ID so you can piogiam youi ioutei iauio with the same one. Eveiy iauio in
youi netwoik must use the same PAN ID so that they can communicate with each
othei (theie`s no neeu to set the DH anu DL in this case, Lecause the cooiuinatoi
will only Le ieceiving uata, not senuing it):
Pan ID:
_____________________________
3. The soltwaie liLiaiies that we aie using in Piocessing UHTXLUH that the Lase station
XBee Le in API Moue 2 (API Opeiation with escapeu chaiacteis). Use X-CTU to
set AP (API EnaLle) to 2, anu Viite the conliguiation to youi iauio.
Be suie that you set the cooiuinatoi`s API to moue 2, otheiwise the
pioject will not woik!
Prepare Your Router Radios
1. Follow the instiuctions unuei Reauing Cuiient Fiimwaie anu Conliguia-
tion on page 35 in Chaptei 2 to conliguie each ol youi sensoi noue iauios as a
ZigBee Routei AT. Youi URXWHU iauios will use the $7 liimwaie so that you can
easily conliguie them using a seiial teiminal. Be suie you select the AT veision loi
youi iouteis!
Vhen you change liom an API iauio to an AT iauio, you may get
an eiioi message that the iauio is no longei communicating. Il so,
go Lack to the PC Settings taL anu XQcheck the EnaLle API Moue
Lox.
2. LaLel the cooiuinatoi iauio with a C so that you know which one it is latei on.
Each ioutei iauio can Le laLeleu with an R.
Prepare the Sensor Boards
Ve`ll Legin Ly conliguiing the ioutei XBees. Ve`ll use the CoolTeim teiminal piogiam
anu an XBee Exploiei USB auaptei again to set up youi iauios. Foi each ol youi sensoi
noue iauios:
1. Select a ioutei XBee you`ve laLeleu with an R anu place it into the XBee Exploiei.
2. Plug the XBee Exploiei into youi computei.
144 | Chapter 5:API and a Sensor Network
3. Run the CoolTeim piogiam anu piess the Options Lutton to conliguie it.
+. Select the appiopiiate seiial poit, anu check the Local Echo Lox so you can see
youi commanus as you type them.
5. Click on the Connect Lutton to connect to the seiial poit.
6. Type +++ to go into commanu moue. You shoulu ieceive an OK ieply liom the
iauio.
7. Select the VDPH PAN ID you enteieu loi youi liist iauio aLove.
S. Type ATID lolloweu Ly the PAN ID you selecteu anu piess Entei on the keyLoaiu.
You shoulu ieceive OK again as a ieply.
9. Eveiy ZigBee cooiuinatoi always has 0 as its 16-Lit netwoik auuiess. In lact, that`s
the uelault uestination auuiess loi any newly conliguieu XBee iauio. To use 16-Lit
auuiessing, the high pait ol youi iauio`s GHVWLQDWLRQ auuiess will Le zeio. Type
ATDH 0 anu piess Entei on the keyLoaiu. You shoulu ieceive an OK iesponse.
10. Entei ATDL lolloweu Ly the ORZ pait ol youi iauio`s GHVWLQDWLRQ auuiess, in this case
also a zeio Lecause that`s the lixeu auuiess loi the cooiuinatoi. Type ATDL 0 anu
piess Entei. You shoulu ieceive an OK iesponse.
11. Entei ATJV1 to ensuie that youi ioutei attempts to iejoin the cooiuinatoi on staitup.
12. Entei ATD02 to put pin 0 in analog moue.
13. Entei ATIR3E8 to set the sample iate to 1,000 milliseconus (hex 3ES).
1+. Save youi new settings as the iauio`s uelault Ly typing ATWR anu piessing Entei.
It`s not a Lau iuea to iecheck youi conliguiations altei you entei them.
Foi example, to iecheck that you enteieu the uestination auuiess coi-
iectly, liom commanu moue type ATDL anu piess Entei to see the cuiient
setting.
Connect voltage regulator circuit and power jack to breadboard
1. Viie up a LieauLoaiu with a 3.3-volt voltage iegulatoi (LD1117V33) as shown in
Figuie 5-+. The iegulatoi has thiee legstypically, giounu, output, anu input
when vieweu liom the liont (wheie the wiiting is). Sometimes these legs aie in a
uilleient oiuei, so linu anu check the uata sheet il you`ie not suie! Input is wheie
a high voltage, loi example 5 oi 9 volts, is applieu to the iegulatoi. Output is wheie
you will get the iegulateu 3.3 volts. Giounu is the common giounu loi youi entiie
ciicuit, incluuing input, output, anu all the othei components. Biing giounu out
to Loth Llue giounu iails that iun along the siues ol youi LieauLoaiu. Biing 3.3-
volt output powei to Loth ol the ieu powei iails.
Simple Sensor Network | 145
Iigurc 5-1. \o|tagc rcgu|ator circuit on brcadboard
2. Soluei a ieu wiie (aLout 10 cm) to the shoit centei pin ol youi powei jack, anu
soluei a similai Llack wiie to the longei outei pin, as shown in Figuie 5-5. Don`t
allow the two connections to touch each othei since that will cieate a shoit ciicuit
when you powei up!
3. Attach the ieu wiie liom the powei jack, using the LieauLoaiu to connect it to the
input pin ol the voltage iegulatoi. Attach the Llack giounu wiie to the giounu pin
ol the voltage iegulatoi in the same way.
+. Hook up the output pin ol the voltage iegulatoi to one ol the powei iails ol the
LieauLoaiu using a ieu wiie. Hook up the giounu pin to one ol the giounu iails
on the LieauLoaiu.
5. Use the two capacitois to uecouple the powei supply in the lollowing way: attach
the shoit giounu leau ol the 10 F capacitoi (also maikeu with a stiipe on the
capacitoi`s giounu siue) to giounu neai the voltage iegulatoi. Attach the othei
positive leau ol the 10 F capacitoi to the voltage iegulatoi`s input pin. This will
iemove some lowei-lieguency noise coming liom the wall powei supply. Also at-
tach the shoit giounu leau ol the 1 F capacitoi to giounu, anu the othei positive
leau to the 3.3 V output pin. This will iemove some highei-lieguency noise coming
out ol the voltage iegulatoi. Decoupling will pievent noisy powei liom ieaching
youi iauio anu inteileiing with its signal.
146 | Chapter 5:API and a Sensor Network
6. Hook up powei anu giounu acioss the LieauLoaiu so that the iails on Loth siues
aie live.
It`s a ieally goou iuea to check the voltage levels using a multimetei altei
you liist wiie up the LieauLoaiu loi powei. Make suie that youi powei
iails have 3.3 volts on Loth siues wheie you expect it. You uon`t want
to senu 9 volts to youi iauio anu cook it!
Router XBee connection to power
1. Vith a routcr XBee mounteu on its Lieakout Loaiu, position the Lieakout Loaiu
in the centei ol youi othei LieauLoaiu so that the two iows ol male heauei pins
aie inseiteu on opposite siues ol the centei tiough.
2. Use ieu hookup wiie to connect pin 1 (VCC) ol the XBee to 3.3-volt iegulateu
powei.
3. Use Llack hookup wiie to connect pin 10 (GND) ol the XBee to giounu.
Iigurc 5-5. Powcr jac| with wiring so|dcrcd in p|acc
Simple Sensor Network | 147
Temperature input
This pioject uses the LM335 piecision analog tempeiatuie sensoi. This sensoi has a
lineai output ol -10 mV pei uegiee Kelvin. It has an aujustment pin loi caliLiation,
Lut this can Le salely ignoieu unless you minu one oi two uegiees ol eiioi at ioom
tempeiatuie. You can get the entiie uata sheet loi the LM335 at http://www.nationa|
.con/ds/LM/LM135.pdj:
1. The LM335 tempeiatuie sensoi has thiee leaus. Vhen the sensoi`s llat siue is lacing
you, the leaus liom lelt to iight aie aujustment, positive, anu negative. Inseit the
LM335 so that each leau is in its own iow on the LieauLoaiu.
2. Use a Llack wiie to connect the iightmost, negative leau to one ol the giounu iails.
3. Inseit the 300 ohm iesistoi so that it`s connecteu to powei on one enu anu to the
positive centei pin ol the LM335 on the othei. You can use jumpei wiies to make
the connection il that`s moie convenient in youi LieauLoaiu layout.
+. Inseit a 200K ohm iesistoi so that it`s connecteu to the positive centei pin on one
enu anu to an empty LieauLoaiu iow on the othei.
5. Use a jumpei wiie to connect Letween the unattacheu enu ol the 200K ohm iesistoi
to XBee uigital input 0 (physical pin 20).
6. Inseit a 100K ohm iesistoi so that one enu connects to XBee uigital input 0 (anu
the 200K iesistoi). The othei enu ol the 100K ohm iesistoi goes to giounu. Again,
use jumpei wiies as neeueu to complete these electiical connections.
Second sensor board
Cieate the seconu sensoi Loaiu in the same way as the liist. You can make as many
sensoi Loaius as you like. The system will woik with as lew as 1 oi as many as 10
without any aujustment to the soltwaie. Figuie 5-6 shows the LieauLoaiu layout loi
oui simple sensoi netwoik, anu Figuie 5-7 shows the schematic.
Prepare the Base Station
Connect to computer
Youi Lase station iauio is simply an XBee seiial auaptei connecteu to youi computei:
1. Select the cooiuinatoi XBee you`ve laLeleu with a C anu place it into the XBee
Exploiei.
2. Plug the XBee Exploiei into youi computei.
148 | Chapter 5:API and a Sensor Network
Iigurc 5-. Sinp|c scnsor nctwor| LM335 brcadboard |ayout
Iigurc 5-7. Sinp|c scnsor nctwor| LM335 schcnatic
Simple Sensor Network | 149
Program the Base Station
The simple sensoi netwoik Lase station uses the lollowing Piocessing piogiam. Down-
loau the ZIP lile ol all the liLiaiies anu iesouices liom this Look`s weLsite. Insiue the
Piocessing sketch loluei loi the Simple Sensoi Netwoik piogiam aie two suLuiiectoiies
calleu codc anu data (see Figuie 5-11). The codc loluei contains the |og1j.jar anu
xbcc-api-0.5.5.jar liLiaiy liles. These contain all the coue loi communication with the
Iigurc 5-10. Thc Proccssing |DE with contro| buttons at thc top, tcxt arca in thc nidd|c, and spacc
jor ncssagcs and conso|c output at thc botton
152 | Chapter 5:API and a Sensor Network
XBee in API moue. The data loluei holus the |og1j.propcrtics lile, ieguiieu Ly
|og1j.jar. It also has a lont lile loi a sans seiil 10-point lont useu loi scieen uisplay.
Iigurc 5-11. Dircctory structurc jor thc Proccssing s|ctch progran Sinp|c Scnsor Nctwor|, inc|uding
a|| rcquircd |ibrarics, conjig ji|cs, a jont ji|c, and thc Proccssing .pdc s|ctch itsc|j
You nust ieplace the COM poit listeu in this coue with youi actual
COM poit. Look loi it in the coue aiounu line 20. Poit names aie listeu
in the console in Piocessing, as youi piogiam staits up.
Once you have loaueu the liles anu uiiectoiies onto youi computei anu openeu the
Sinp|c_Scnsor_Nctwor|.pdc lile in Piocessing, piess the Run Lutton (laLeleu with a
tiiangle) to launch the uisplay coue. It will open in a new winuow anu show a thei-
mometei loi each sensoi noue uetecteu, as shown in Figuie 5-12.
Iigurc 5-12. Sinp|c Scnsor Nctwor| tcnpcraturc disp|ay scrccn in Proccssing
Simple Sensor Network | 153
Simple Sensor Network display code in Processing
Heie`s the souice coue loi the Piocessing sketch. The comment shown in Lolu aLout
the seiial poit highlights an essential change. Othei commenteu instiuctions aie only
impoitant il you uiun`t uownloau the souice liom the weLsite listeu in the Pielace:
/*
* Draws a set of thermometers for incoming XBee Sensor data
* by Rob Faludi http://faludi.com
*/
// used for communication via xbee api
import processing.serial.*;
// xbee api libraries available at http://code.google.com/p/xbee-api/
// Download the zip file, extract it, and copy the xbee-api jar file
// and the log4j.jar file (located in the lib folder) inside a "code"
// folder under this Processing sketch's folder (save this sketch, then
// click the Sketch menu and choose Show Sketch Folder).
import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse;
String version = "1.01";
// *** REPLACE WITH THE SERIAL PORT (COM PORT) FOR YOUR LOCAL XBEE ***
String mySerialPort = "/dev/tty.usbserial-A1000iMG";
// create and initialize a new xbee object
XBee xbee = new XBee();
// make an array list of thermometer objects for display
ArrayList thermometers = new ArrayList();
// create a font for display
PFont font;
void setup() {
size(800, 600); // screen size
smooth(); // anti-aliasing for graphic display
// You'll need to generate a font before you can run this sketch.
// Click the Tools menu and choose Create Font. Click Sans Serif,
// choose a size of 10, and click OK.
font = loadFont("SansSerif-10.vlw");
textFont(font); // use the font for text
// The log4j.properties file is required by the xbee api library, and
// needs to be in your data folder. You can find this file in the xbee
// api library you downloaded earlier
PropertyConfigurator.configure(dataPath("")+"log4j.properties");
// Print a list in case the selected one doesn't work out
println("Available serial ports:");
154 | Chapter 5:API and a Sensor Network

Вам также может понравиться