41
WIRELESS SENSOR NETWORKS Environmental Sensor Application of Rain Collector II with CrossBow Technology by Aurelio Quimado Hafalia Senior Project ELECTRICAL ENGINEERING DEPARTMENT

Sp Aurelio Hafalia

Embed Size (px)

DESCRIPTION

paper

Citation preview

WIRELESS SENSOR NETWORKS

PAGE

WIRELESS SENSOR NETWORKS

Environmental Sensor Application of Rain Collector II

with CrossBow Technology

by

Aurelio Quimado Hafalia

Senior Project

ELECTRICAL ENGINEERING DEPARTMENT

California Polytechnic State University

San Luis Obispo

2005

TABLE OF CONTENTS

Section

Page #

Abstracti

List of Figures ...ii

Acknowledgements .iii

I. Introduction.1

II. Background...3

III. Requirements..6

i. Learn how to use TinyOS....6

ii. Learn how to use TinyViz....7

iii. Test Equipment....8

iv. Program a CrossBow Mica2 to interface with the MIB510...8

v. Program a CrossBow Mica2 to interface with the MDA300CA.9

vi. Wire the CrossBow MDA300CA to interface

with the Rain Collector II...11

vii. Use XListen.nc to convert the transmitted data

to a txt. file. Then have Matlab retrieve the raw data

from the txt. file to display in a user-friendly graphical fashion..13

IV. Test and Results...14

V. Conclusions and Recommendations....17

Bibliography....18

Appendices.....19

A. Troubleshooting..20

B. TOSBase Output....21

C. XSensor Output..22

D. m-file of Rain Collector II...23

Abstract

This report goes into discussion of a particular application, a rainfall measuring device, with wireless devices developed by Crossbow Technology and students and faculty of the University of California Berkeley. The first several pages introduce the tasks of the Wireless Sensor Networks Group followed by a detailed report of the wireless equipment interfacing successfully with the rain gauge application. A step-by-step technical approach was taken to inform the reader of the uses of this wireless technology. To conclude the senior project, results were recorded from the application demonstration to verify the completeness of the senior project.

List of Figures

Figure #

Page #

1. Field-Application Overview.4

2. Crossbow MIB510....5

3. Crossbow Mica2 mote.5

4. Crossbow MDA300CA....5

5. Rain Collector II and MDA300CA Circuit12

6. Rain Collector II and MDA300CA Wiring Diagram...13

7. Data Collected from the Counter Channel.16

8. Graphical Representation of Output17

Acknowledgements

First and foremost, I would like to thank Dr. James Harris who is my senior project advisor, professor, and my guide to help me obtain my goal in becoming a Cal Poly graduate in the Electrical Engineering program. You have given me a senior project I can truly be proud of and hope to see the Wireless Sensor Networks Team thrive through its beginning stages here at Cal Poly. Thank you again for giving me this unique opportunity as I will apply my experiences in future group projects.

To the undergraduates, I thank you for our weekly collaboration in making this senior project a memorable one. Without each others knowledge, communication skills, and patience we would not be able to complete the definition of teamwork. This senior project was a success because of that important aspect.

To the graduates, I appreciate the countless hours you have put in the WSN team. Without having both of you to make the project come together, we would not have gotten this far. Thank you for your dedication.

The Wireless Sensor Network Team appreciates the support of Drs. Diana Franklin and John Seng for sharing their Crossbow hardware with us, and the Network Performance Research Laboratory (NetPRL) for purchasing the additional sensors that were used in the completion of this project.

I. Introduction

I am a member of a team of undergraduate and graduate EE / CPE students that developed the implementation of a wireless project entitled Wireless Sensor Network (WSN) at Cal Poly the WSN Team. A Crossbow Technology, Inc., system was selected as the technology to be used. CrossBow plays a big roll in sensory systems globally. This is the company that manufactures and provides information on how to use the TinyOS technology. The project began by learning how to use the newly developed wireless operating system, TinyOS, which was established by students and professors at the University of California, Berkeley. Through the manuals and tutorials found on the internet, we were able to execute programs and create computer simulations and demonstrations on the CrossBow hardware. The next phase was to develop and test our understanding of writing and modifying code by successfully uploading the program to the CrossBow hardware. Our goal is to introduce implementation of a potentially user-friendly WSN system such as the CrossBow Technology, Inc products with its environmental measuring devices to design an all-in-one application. It is our hope that this project is considered as an on-going project to be adopted by the school to show the benefits of this technology.As the WSN team continues to grow in the future, we plan to make a positive impact cost-effective, applicable, and efficient integration of the available technology in the market into one complete system. Within a year or two, the WSN Team hopes to implement CrossBow technology in Cal Polys green house and Swanson Ranch in Santa Cruz, CA.

This report provides detailed-procedural descriptions accompanied by figures to help the reader get a better understanding of what I have accomplished as my senior project. The report starts with a quick review of the technology being used and then transitions into the requirements of the project concluding with the results of a demonstration.

II. Background

Before I go into detail of the technical aspect of the WSN project, it is imperative that the reader understands the basic operation of each hardware device used. The devices used are Mica2, MDA300CA, and MIB510.

The WSN Team uses Crossbow Technologys wireless sensors. This platform enables powerful, wireless, and automated data collection and monitoring systems. The power behind this hardware is TinyOS. It is the operating system used specifically for wireless systems that provides low-level event and task management. It is an open-source operating system that allows the programmer, who is fluent in C, to customize the existing applications written.

The radio boards we utilize for our senior project is called Mica2 motes. These motes are battery-powered wireless devices that have the primary function to send and receive data. There is a built-in processor that runs TinyOS. Connection is based on a radio link. The number of motes that are in use varies directly with the magnitude of the wireless network.

The data acquisition card we interface with is the MDA300CA. It is an environmental data acquisition module that mates directly to the Mote. The MDA300CA has the capability to interface with external sensors. Several highlights of this particular sensor board are the facts that it can take both analog and digital inputs, it has a built-in counter, and have necessary excitation voltages to interface with external environmental sensors. This device has the potential to receive and transmit a number of external sensor data, all at one time.

The last piece of hardware we use is the MIB510. It is known as the mote interfacing board that provides the gateway for the data to flow from the mote to the PC. This particular board connects to a PC through a serial interface. The MIB510 allows us to upload programs to the motes to execute its capable functions.

Figure 1 is a diagram that gives an idea of how I applied this technology to the Rain Collector II application. Figures 2, 3, 4, show the Mica2, MDA300CA, and the MIB510.

Figure 1: Field-Application Overview

III: Requirements & Design

i. Learn how to use TinyOS

The reference used to understand this operating system was a TinyOS tutorial found on the internet (if needed, please refer to this website: http://www.tinyos.net/tinyos-1.x/doc/tutorial/ ). I was able to interpret the code based on the detailed explanations and examples given. A primary example was StdControl, the common interface that is used to initialize TinyOS components. Here is an example of that code.

StdControl.ncinterface StdControl {

command result_t init();

command result_t start();

command result_t stop();

}

The three commands that are defined are init (), start (), and stop (). They are called when a component is first initialized. These three commands are able to call multiple components and subcomponents. The only command that can be called multiple times is init (). It can not be called after the commands start () or stop (). Through the first several lessons I was able to decipher what was taking place in the TinyOS code as I applied specific programs to my application.

This was the foundation stage of my senior project. It was challenging for me because of my limited background in programming. As I referenced my C & Unix notes, my understanding of TinyOS code accelerated as I studied the code given in the tutorials. Spending time to reverse engineer a couple of programs along with the help of my teammates in the WSN Team allowed me to modify the code towards the final stages of my senior project.

ii. Learn how to use TinyViz

TinyViz is the TinyOS simulator. Without the use of the hardware, I was able to execute the necessary commands to simulate programs. This gave me an introduction on how to load applications and see what should happen if I was working with the TinyOS hardware. In one of my many power point presentations, I was able to demonstrate specific programs to show an understanding of this newly developed operating system which was part of the groundwork of my senior project. In theory, once I am able to execute the necessary commands to upload applications to the simulator, I should be able to follow the same procedure for the hardware.

Through this process of getting TinyViz to work, I initially ran into difficulty in regards to TinyOS installation. I had to search the internet for message boards on TinyOS to install the correct version to run the simulator. It turned out TinyOS was primarily designed to interface with Linux instead of Windows. But after making the needed changes on my computer to interface with the updated TinyOS software, I was able to execute a number of programs through TinyViz. The two main programs were the Blink.nc application and a Hello World morse-code application that was developed by one of the members of the WSN Team, Wesley Leung. Accomplishing the task of simulating programs, our next step was to apply our knowledge to the CrossBow hardware.

iii. Test Equipment

The following test equipment has been provided or funded by the NetPRL Group, Electrical Engineering and Computer Science Department of Cal Poly, SLO:

1. A Linux box or a Windows PC with Cygwin installed

2. TinyOS version 1.1.7

3. Crossbow MIB510CA Programming and Serial Interface Board

Figure 2

4. Crossbow Mica2 mote (2) Figure 3

5. Crossbow MDA300CA Environmental Monitor Sensor Board Figure 4

6. TOSBase (Provided by Crossbow)

7. XSensor (Provided by Crossbow

8. Xlisten Serial Line Listener (Modified from Crossbow sourcecode)

iv. Program a CrossBow Mica2 to interface with the MIB510.

Specification:

A Mica2 mote is needed to mate with the MIB510 to collect data wirelessly from a second mote that is connected to the MDA 300CA. The mote that is programmed and to be the gateway between the PC and the incoming data packets, needs to execute a program called TOSBase.nc TOSBase.nc receives the incoming data from the second mote.

Procedure:

After supplying power and making the serial-USB port connection from the MIB510 and the PC, connect a Mica2 mote to the MIB510 and install TOSBase. *IMPORTANT: Batteries for the Mica2 mote must be taken out while uploading programs. If failed to do so, the Mica2 mote will no longer be operational.* In general, the location of TOSBase is located in the following directories: cd/opt/tinyos-1.x/contrib./xbow/apps/TOSBase. After locating the correct directory that contains TOSBase, execute the command, make mica2 install.0 mib510.com1. The program should upload successfully with no indication of error. If an error occurs, please refer to Appendix A which lists some of the possible descriptions of what may have caused an error. If those possibilities have been eliminated, refer to Crossbows contact information on their website. Refer to Appendix B to see the output of a successful upload of TOSBase. Assuming a successful upload, detach the Mica2 mote and proceed with the next section.

v. Program a CrossBow Mica2 to interface with MDA 300CA

Specification:

The MDA300CA is equipped with drivers (SamplerC.nc). This application allows the activation of all the channels with the specified parameters. The SamplerC.nc also goes into sleep-mode when no sampling is in progress. This means longer battery life.

The MDA300CA is attached to a Mica2 mote in order to transmit data wirelessly to the mote that is connected to the MIB510. The program that will be used to transmit the data in raw form is the XSensor.nc. Essentially, this program takes the data collected from the MDA300CA and sends it back to the Mica2 mote connected to the MIB510 as long as both motes are within the wireless network.

Procedure:

First, attach the MDA300CA to the Mica2 mote. To upload XSensor.nc, the mote with the attached MDA300CA must also be attached to the MIB510. *IMPORTANT: Batteries for the Mica2 mote must be taken out while uploading programs. If failed to do so, the Mica2 mote will no longer be operational.* After making all the necessary connections, upload the program, XSensor.nc. Once in the XSensor directory, execute the following: "make mica2 install.1mib510.com1." After the successful upload, detach the mote from the MIB510, install the batteries, and activate the mote. The mote with TOSBase.nc uploaded with no batteries needs to be reconnected to the MIB510 to allow wireless transfer between both motes.

Successfully compiling the program, a prompt will be sent back to the user without any error messages. Refer to Appendix C to view a successful upload of XSensor.

vi. Wire the CrossBow MDA 300CA to interface with the Rain Collector II

Specification:

The functionality of the Rain Collector II is a normally-open switch. At the bottom of the dual bucket, there is a small cylindrical magnet. When the bucket tips on either side, the magnet passes the normally-open switch causing it to close. When the switch closes, it allows a current to continue through the circuit back to the counter producing a voltage spike. This voltage spike is detected by the MDA300CAs onboard Counter. The function of the Counter is to save the number of spikes it receives until a data packet is sent out to the PC. Once the data packet is transmitted, the Counter automatically resets back to zero waiting for the next voltage spike from the Rain Collector II. Figure 5 is a circuit diagram of the functionality of the Rain Collector II and MDA300CA.

Figure 5: Rain Collector II and MDA300CA Circuit

Procedure:

Make the proper connections between the Rain Collector II and MDA 300CA. Short the switch by tipping the bucket of the Rain Collector II. This will allow the Counter on the MDA 300CA to record the voltage spike. The channels that are utilized on the MDA300CA are Vcc, Gnd, and the Counter. Figure 6 shows a wiring diagram of the MDA300CA and the Rain Collector II.

Figure 6: Rain Collector II and MDA300CA Wiring Diagram

vii. Use XListen.nc to move the transmitted data to a txt. file. Then have Matlab retrieve the raw data from the txt. file to display in a user-friendly graphical fashion.

Specification:

XListen.nc is the program that displays the data that was collected from the TOSBase program. XListen interfaces with a txt. file. After getting the data, execute a Matlab program to display data in a user-friendly fashion by displaying a graph of rainfall (mm) per packet sent.

In order to convert the counts collected from the Counter port from the MDA 300CA to millimeters, a formula is needed to execute conversion. The conversion used in Matlab is the following:

[0.4 * (counts collected from Counter)] / 2

.4 = .4 mm / bucket-tip

2 = the Counter counts every 2 units. Divide by 2 is needed to get the correct number of tips.

Procedure:

After the raw data has been collected in the txt. file, write a Matlab code that will implement a conversion formula and display graphical results.

(Refer to Appendix D to view the m-file for Matlab.)

IV. Test and Results

Objective: Demo the application, Rain Collector II, with the Crossbow technology. Display accurate, meaningful, and real-time results in a graphical fashion.

Following the previous steps in Chapter III Sections iii vii, I was able to gather data in real-time that displayed accurate results. The programs I used to display the output are XListen, a text file, and Matlab. XListen allowed an open channel to gather the data packets that were sent out wirelessly from the Mica2 mote connected to the MDA300CA, and was provided by Jose Bacerra (ref. 6). The text file displayed two columns. The first column displayed the time in seconds when a packet was received. The second column showed the number of counts the Counter channel received. Matlab took the information from the text file and executed the conversions and graphical display. Refer to Appendix D for the m-file used in Matlab for the Rain Collector II.

The following is the collected data in the text file. Notice the four digits starting from the right are in hexadecimal. I implemented a Matlab function that converted the hexadecimal value to decimal to make the correct conversions to millimeters (see Figure 7).

Sec Cnts

0 0000

11 0000

33 0000

43 0000

54 0000

65 0000

76 0000

86 0002

97 0001

108 000a

129 0000

140 0007

151 0000

161 0000

172 0000

194 0000

204 0000

226 0002

237 0000

247 0000

258 0000

Using the data collected from the text file, Matlab performed the necessary operations to display the following output as shown in Figure 8.

Figure 8: Graphical Respresentation of Output

The test and results of the Rain Collector II application to Crossbow technology demonstrated the required goals with complete success.

V. Conclusions and Recommendations

Having the responsibility of establishing the WSN group at Cal Poly was an important task. We succeeded in understanding the TinyOS operating system, the syntax of the code, executing programs, and interfacing the Crossbow hardware with other commercial products to make a user-friendly system to collect environmental data. These successes were accomplished because of the groups communication, knowledge, and patience. Through these qualities, we were able to overcome all our obstacles to reach our goals. We hope you are able to continue where we left off based on our experiences with the Crossbow technology and keep the WSN Team striving for excellence.

To the future members of the WSN Team: Having a strong background in programming and a concentration in communications / electronics may get you started in obtaining the goals of the WSN group. But at the same time it is imperative that you are open-minded and humble to the other group members that may lack the knowledge you have. It is important that all members of the WSN Team be self-motivated to overcome obstacles together. With those points in mind, I can guarantee there will be success in your personal goals as well as the teams goals. It was with great privilege working with the 1st generation of the WSN Team.

Bibliography

1. TinyOS Tutorial

http://www.tinyos.net/tinyos-1.x/doc/tutorial/2. Crossbow Technology

http://www.xbow.com/3. CENS: Center for Embedded Networked Sensing

www.cens.ucla.edu4. Rain Collector II

http://www.davisnet.com/weather/products/weather_product.asp?pnum=78525. Rain Collector II Specification Sheet

http://www.davisnet.com/product_documents/weather/spec_sheets/rain_collector_std.pdf6. Jose Becerra, Cal Poly Wireless Sensor Network Demonstration Project; MS Thesis, EE Department, Cal Poly, San Luis Obispo, CA, September 2005

Appendices

Appendix A: Troubleshooting:1. Make sure power is supplied to the MIB510 to allow application transfer.

2. Mica2 mote mating with the MIB510 and Mica2 mote mating with MDA300CA:

- Make sure devices are physically connected properly.

- Pay close attention to the white bar connection and make sure it is lined up properly.

- Make sure the switch is on the ON mode for all devices.

3. Have an extra set of batteries. This will determine the maximum distance of the wireless sensor network established along with execution of the uploaded program.

Appendix B: TOSBase Output

Marble1@marble /opt/tinyos-1.x/contrib/xbow/apps/TOSBase

$ make mica2 install.0 mib510,com1

mkdir -p build/mica2

compiling TOSBase to a mica2 binary

ncc -o build/mica2/main.exe -Os -I%T/../contrib/xbow/tos/platform/mica2

-finlin

e-limit=100000 -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x81 -Wnesc-all

-target=mica2 -

fnesc-cfile=build/mica2/app.c -board=micasb

-DCC1K_DEFAULT_FREQ=RADIO_916BAND_CH

ANNEL_00 -DRADIO_XMIT_POWER=0xFF -DIDENT_PROGRAM_NAME="TOSBase"

-DIDENT_PROGRAM_

NAME_BYTES="84,79,83,66,97,115,101,0" -DIDENT_USER_HASH=0x0054ef2eL

-DIDENT_UNIX

_TIME=0x429d5f0dL TOSBase.nc -lm

G:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/RealMain.nc: In

function `main'

:

G:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/interfaces/StdControl.nc:63:

warning:

`result' might be used uninitialized in this function

compiled TOSBase to build/mica2/main.exe

11544 bytes in ROM

637 bytes in RAM

avr-objcopy --output-target=srec build/mica2/main.exe

build/mica2/main.srec

set-mote-id build/mica2/main.srec build/mica2/main.srec.out 0

installing mica2 binary using mib510

uisp -dprog=mib510 -dserial=com1 -dpart=ATmega128 --wr_fuse_e=ff

--erase --uplo

ad if=build/mica2/main.srec.out

Firmware Version: 2.1

Atmel AVR ATmega128 is found.

Uploading: flash

Fuse Extended Byte set to 0xff

Marble1@marble /opt/tinyos-1.x/contrib/xbow/apps/TOSBase

Appendix C: XSensor Output

Ball G@r /opt/tinyos-1.x/contrib/xbow/apps/XSensorMDA300

$ make mica2 intstall.1 mib510,com1

mkdir -p build/mica2

compiling XSensorMDA300 to a mica2 binary

ncc -o build/mica2/main.exe -Os -I../../tos/interfaces

-I../../tos/system -I../

../tos/lib -I../../tos/sensorboards/mda300 -I../../tos/platform/mica2

-finlin

e-limit=100000 -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x81 -Wnesc-all

-target=mica2 -

fnesc-cfile=build/mica2/app.c -board=mda300

-DCC1K_DEFAULT_FREQ=RADIO_916BAND_C

HANNEL_00 -DRADIO_XMIT_POWER=0xFF -DIDENT_PROGRAM_NAME="XSensorMD"

-DIDENT_PROGR

AM_NAME_BYTES="88,83,101,110,115,111,114,77,68,0"

-DIDENT_USER_HASH=0x306db657L

-DIDENT_UNIX_TIME=0x429e6688L XSensorMDA300.nc -lm

compiled XSensorMDA300 to build/mica2/main.exe

20834 bytes in ROM

1062 bytes in RAM

avr-objcopy --output-target=srec build/mica2/main.exe

build/mica2/main.srec

Ball G@r /opt/tinyos-1.x/contrib/xbow/apps/XSensorMDA300

$

Appendix D: m-file of Rain Collector II

%Rain Collector II Program

%THIS M-FILE OPENS A FILE THAT IS STORED IN THE 'current %work directory'

%CALLED CNTR1.txt (OR ANY GIVEN NAME WHEN XLISTEN IS RUN)

%THIS PROGRAM USES textread(), A FUNCTION THAT READS %NUMBERS AND CHARACTERS

%THE DATA SAVED TO "CNTR1.txt" CONTAINS NUMBERS AND/OR %CHARACTERS IN THE FIRST 2 columns

%THis only reads numbers starting from R,C (ROW,COLUMN)

% data=csvREAD('C:\tinyos\cygwin\opt\tinyos-%1.x\contrib\xbow\tools\src\xlisten\june2.csv',1,0)

[time,val] = textread('C:\tinyos\cygwin\opt\tinyos-1.x\contrib\xbow\tools\src\xlisten\CNTR1.txt', '%d %s')

%variable= data(row,column)

%once the data is stored in the data matrix in matlab the %indexing starts from

%Row=1,2,3.. & Column=1,2,3..

%x contains the time in seconds

%**********************************************************%BELOW THIS COMMENT BOX IS WHERE THE CONVERSION FORMULAS %NEED TO BE PLACED

%for example if the engineering units need to be divided by %a 1000 to get the voltage

%read from ADC in volts DO:5

%**********************************************************

%your_variable = ((0.03894*(y_voltage))-42.017);

Max=size(val);

%CONVERTS TO HEX TO DECIMAL

for n = 1:Max,

dec(n)=hex2dec(val(n))

end

cnt = (dec *0.2) / 2;%FORMULA TO CONVERT COUNTER %TO MILLIMETERS

%RAIN COLLECTOR TITLES FOR GRAPHICAL OUTPUT***************

plot(time,cnt)

grid

xlabel('Seconds ')

ylabel('Millimeters')

Title('RAINFALL IN MILLIMETERS VS. TIME')

%*********************************************************

%plots the time in x axis and engineering units in y axis

%plot(x_time,your_variable)

%grid

%xlabel('Title for x-axis')

%ylabel('Title for y-axis')

%Title('Title of graph')

%***********************************************

2

1

Figure 7:

Data Collected from Counter

7

6

( Figure 4. Crossbow MDA300CA

3

4

5

Figure 3. Crossbow Mica2 mote(

( Figure 2. Crossbow MIB510CA

8

9

10

11

12

13

14

15

16

18

19

20

21

22

23

24

25

17

i

ii

iii

PAGE