• No results found

PIC Wireless Weather Station

N/A
N/A
Protected

Academic year: 2021

Share "PIC Wireless Weather Station"

Copied!
56
0
0

Loading.... (view fulltext now)

Full text

(1)

PIC Wireless Weather Station

PIC Wireless Weather Station

By:

By:

Eoghan O’Sullivan

Eoghan O’Sullivan

Department of Electronic Engineering,

Department of Electronic Engineering,

Cork Institute of Technology,

Cork Institute of Technology,

Bishopstown,

Bishopstown,

Cork.

Cork.

Supervisor:

Supervisor:

Dr. Oliver Gough

Dr. Oliver Gough

Date:

Date:

30/5/2009

30/5/2009

(2)
(3)

Abstract

Abstract

The main purpose of this project was to d

The main purpose of this project was to design and build a wireless weather station thatesign and build a wireless weather station that logged the humidity and temperature values on a remote PC. The PIC was the

logged the humidity and temperature values on a remote PC. The PIC was the

fundamental point in the project as it held the code that helped extract the information fundamental point in the project as it held the code that helped extract the information from the sensor and send it wirelessly using the Zigbee

(4)

Acknowledgement

Acknowledgement

Firstly I would like to thank my project supervisor Dr. Oliver Gough

Firstly I would like to thank my project supervisor Dr. Oliver Gough for his guidance andfor his guidance and assistance which were a great benefit to the

assistance which were a great benefit to the project overall.project overall. Most of the work carried out for the project was

Most of the work carried out for the project was done so in the done so in the senior lab and I would likesenior lab and I would like to thank the technicians in the

to thank the technicians in the lab for their assistance and providing me with anything lab for their assistance and providing me with anything II needed.

needed.

I would also like to thank m

I would also like to thank my classmates who were a great help to me y classmates who were a great help to me during the year andduring the year and offered their help when they could.

offered their help when they could.

Lastly I would like to thank my family and

Lastly I would like to thank my family and friends for their continued support throughoutfriends for their continued support throughout the year.

(5)

Table of Contents

Table of Contents

ABSTRACT II ABSTRACT II ACKNOWLEDGEMENT III ACKNOWLEDGEMENT III TABLE

TABLE OF OF CONTENTS CONTENTS IVIV

1: 1: INTRODUCTION INTRODUCTION 55 O OBJECTIVEBJECTIVE: : 55 2: 2: COMPONENTS COMPONENTS 77 APPENDIX

APPENDIX 1: 1: MINUTES MINUTES OF OF MEETINGS MEETINGS 2222 APPENDIX

APPENDIX 2: 2: PIC PIC CODE CODE 2727

APPENDIX

APPENDIX 3: 3: REQUIREMENT REQUIREMENT SPECIFICATION SPECIFICATION 4141 APPENDIX

(6)

1: Introduction

1: Introduction

The reason for choosing this project was out o

The reason for choosing this project was out of the other twenty projects that were shownf the other twenty projects that were shown to us at the beginning of the

to us at the beginning of the year, this project appealed to me. year, this project appealed to me. It is interesting to monitorIt is interesting to monitor the weather conditions outside and have the

the weather conditions outside and have the data sent to a PC data sent to a PC using wireless technologyusing wireless technology and graphing the data to see the changing conditions.

and graphing the data to see the changing conditions.

This device will be placed in an outdoor environment to monitor the weather conditions. This device will be placed in an outdoor environment to monitor the weather conditions. It will read in data from a sensor and the

It will read in data from a sensor and then send it wirelessly to a receiver which n send it wirelessly to a receiver which will thenwill then log the data into the PC. This process will happen once a min and give an accurate picture log the data into the PC. This process will happen once a min and give an accurate picture of the conditions outside. Below is a block

of the conditions outside. Below is a block diagram of the overall system.diagram of the overall system.

Fig 1.1 Fig 1.1

Objective:

Objective:

My initial objectives are as follows, My initial objectives are as follows,

Setup wireless link between PC and data loggerSetup wireless link between PC and data logger

TestTest

Interface the sensor to the TX moduleInterface the sensor to the TX module

Display results on PC using VB languageDisplay results on PC using VB language

The monitoring of temperature and humidity in indu

The monitoring of temperature and humidity in industry as it is very important to keepstry as it is very important to keep these under controlled as best as possible. Humidity is the

these under controlled as best as possible. Humidity is the concentration of water in theconcentration of water in the Radio Radio Transmitter Transmitter Receiver Receiver Display Display PIC PIC Microcontroller Microcontroller Temperature Sensor Temperature Sensor Humidity Sensor Humidity Sensor

(7)

air and the relative humidity is ratio that compares the amount of water vapour in the air compared to the amount of water vapour that would be present in the air at saturation. The relativity humidity is described in percentage, if there was 1 0 grams of water vapour in each kilogram of air and the saturation of the air was 50 grams of water vapour per kilogram then the relative humidity would then be 50/10 = 25%.

The device used to measure humidity is called a hydrometer, it works by measuring the moisture content in the air at a given time.

(8)

2: Components

Humidity & Temperature Sensor

Fig 2.1

This is the Sensirion SHT-75 humidity and temperature sensor. This sensor was the best fit for the job as it was small, easy to use and did both measurements. The humidity sensor is capacitive type which has a distinct advantage over it resistive type sensors which don’t work at relative humidity levels below 20% and they also can only be used in a non-condensing type environment. This sensor also comprises of a calibrated digital output which was a factor in choosing it as it avoided A/D conversion in the PIC. The sensor contains a 14bit analog to digital converter and a serial interface circuit on the same chip. This results in superior signal quality, a fast response time and in sensitivity to external disturbances. The 2-wire serial interface and internal voltage re gulation allows for easy and fast system integration. The small size and low power consumption makes this sensor the ideal choice.

Fig 2.2

This is how the sensor is wired up to the PIC, there are two wire on the sensor which each have a specific job.

Pin 1 – This is the serial clock input(SCK), this is used to synchronize

communication between the PIC and the sensor, since the interface consists of  fully static logic there is no minimum clock frequency, this was useful to the project because a bit could then be toggled in the PIC to generate a manual clock  pulse.

Pin 4 – This is the data line from the sensor to the PIC, it is bi-directional. DATA

is valid on the rising edge of the SCK pulse and after the falling edge of the SCK pulse the DATA may then be changed, DATA must remain stable while SCK is

(9)

high. To avoid signal contention the microcontroller must only drive DATA low. An external pull-up resistor (e.g. 10 k Ω) is required to pull the signal high.

The senor requires a voltage in the range of 2.4V to 5.5V, the VDD and GND are decoupled by a 100nF capacitor that is built into the sensor.

Communication with Sensor

Once the VDD voltage has been supplied to the sensor it needs 11ms to reach sleep state, no commands must be sent to the sensor before this time.

To initiate a transmission, a Transmission Start sequence has to be issued. It consists of a lowering of the DATA line while SCK is high, followed by a low pulse on SCK and raising DATA again while SCK is still high.

Fig 2.3

The subsequent command consists of three address bits (only ‘000’ is currently supported) and five command bits. The SHT71 indicates the proper reception of a command by pulling the DATA pin low (ACK bit) after the falling edge of the 8thSCK clock. The DATA line is released (and goes high) after the falling edge of the 9thSCK clock.

Measurement Sequence

After the transmission start sequence the next step is to tell the sensor what measurement is required, this is done by sending a code from the PIC to the sensor through the DATA line, if the relative humidity is required then the code ‘00000101’ is used, for temperature measurement the code ‘00000011’ is used. The PIC then has to wait while the

measurement is been taken and these times which takes approximately 11/55/210 ms for a 8/12/14bit measurement. To signal the completion of a measurement, the SHT-75 pulls data line low and enters Idle Mode. The controller must wait for this Data Ready signal

(10)

an acknowledgement pulse to the sensor after each byte of data that has been received, it does this by pulling the DATA line low. For this project CRC(check sum calculation) was not used as it was not necessary.

Fig 2.4

Fig 2.5

Reset Sequence

If it is the case that the connection is lost between the PIC and the sensor there is a reset sequence which in turn resets the serial interface, this is achieved by leaving the DATA line high and toggling the SCK nine times or more, this must be directly followed b y a transmission start sequence.

Fig 2.6

Piczee Rx & Tx

(11)

This is a PIC Microcontroller with 2,4GHz IEEE 802.15.4 transceiver and ZigBee stack. It’s range is 100meters and it has its own built in antenna. Like all PIC chips it operates between 2.1V and 3.6V. This next diagram is a list of the pin i/o on the chip and below that is the schematic diagram of the circuit.

(12)

Fig 2.8

ZigBee’s primary aim is to make low data rate, battery power communications feasible. Primarily it does this by using mesh networks of adjacent devic es rather than point-to-point communications over long distances. It does this by setting one of the chips as coordinator and the other as an end point, this allows one chip to control the other which makes the system more efficient. Below are the most common types of networks used.

Fig 2.9

(13)

For the transceivers to work correctly a protocol stack was needed. The application source code must include the header file, zAPL.h , to access the ZigBee protocol functions.

#include “zAPL.h”

A ZigBee protocol coordinator application will need to have one support variable to keep track of the current primitive being executed by the Stack.

 ZIGBEE_PRIMITIVE currentPrimitive;

A ZigBee protocol router or end device will also need to keep track of the current primitive; but in addition, it will need two other support variables to assist in network  discovery and joining.

 NETWORK_DESCRIPTOR * currentNetworkDescriptor;  ZIGBEE_PRIMITIVE currentPrimitive;

 NETWORK_DESCRIPTOR * NetworkDescriptor;

Next, the application must configure all pins required to interface with the transceiver. Before the Stack can be used, it must be initialized. Interrupts must then be enabled.

 ZigBeeInit();

 RCONbits.IPEN = 1;  INTCONbits.GIEH = 1;

Here is an example of the basic structure of the application.

while (1) { CLRWDT();  ZigBeeTasks( &currentPrimitive ); switch (currentPrimitive) {

 // Include cases for each required primitive.  // Be sure to update currentPrimitive!

default:

currentPrimitive = NO_PRIMITIVE; break;

 }  }

(14)

case APSDE_DATA_indication: {

 // Declare variables used by this primitive.

currentPrimitive = NO_PRIMITIVE; // This may change during processing.  frameHeader = APLGet();

switch (params.APSDE_DATA_indication.DstEndpoint) {

case EP_ZDO:

 // Handle all ZDO responses to requests we sent. break;

 // Include cases for all application endpoints.  }

 APLDiscard();  }

break;

The Microchip Stack for the ZigBee protocol allows one outgoing message in the application layer at a time. Messages are sent b y implementing the following:

Verify that the application layer is ready for a new outgoing message by

confirming that ZigBeeReady() is TRUE.

Lock the system with ZigBeeBlockTx() so subsequent calls to ZigBe eReady()

will return FALSE.

Load the message payload into the array TxBuffer, using TxData to index through

the array. When complete, TxData must point to the first location after the message.

Load the APSDE_DATA_request primitive parameters.

Set currentPrimitive to APSDE_DATA_request and call ZigBeeTasks().

Here is an example of how to send an outgoing message.

if (ZigBeeReady()) { if (bLightSwitchToggled) { bLightSwitchToggled = FALSE;  ZigBeeBlockTx();

TxBuffer[TxData++] = APL_FRAME_TYPE_KVP | 1; // KVP, 1 transaction TxBuffer[TxData++] = APLGetTransId();

(15)

TxBuffer[TxData++] = APL_FRAME_COMMAND_SET | (APL_FRAME_DATA_TYPE_UINT8<< 4);

TxBuffer[TxData++] = OnOffSRC_OnOff & 0xFF; // Attribute ID LSB

TxBuffer[TxData++] = (OnOffSRC_OnOff >> 8) & 0xFF; // Attribute ID MSB TxBuffer[TxData++] = LIGHT_TOGGLE;  params.APSDE_DATA_request.DstAddrMode = APS_ADDRESS_16_BIT;  params.APSDE_DATA_request.DstEndpoint = destinationEndpoint;  params.APSDE_DATA_request.DstAddress.ShortAddr = destinationAddress;  params.APSDE_DATA_request.ProfileId.Val = MY_PROFILE_ID;  params.APSDE_DATA_request.RadiusCounter = DEFAULT_RADIUS;  params.APSDE_DATA_request.DiscoverRoute =  ROUTE_DISCOVERY_ENABLE;  params.APSDE_DATA_request.TxOptions.Val = 0;  params.APSDE_DATA_request.SrcEndpoint = EP_SWITCH;  params.APSDE_DATA_request.ClusterId = OnOffSRC_CLUSTER; currentPrimitive = APSDE_DATA_request;  }  } PIC 16F877A

This is the microcontroller that was used in the project, this microcontroller can be programmed using MPLAB to carry out the tasks required.

(16)

Fig 2.11

Maxim 232

(17)

This is the Maxim 232 driver and receiver chip, this chip is used to send data from the PIC chip through an RS232 cable into the remote PC. The transmitter uses pins 12 and 13 to send data out through the RS232 port and this converts voltage into high and low

pulses for a computer to recognize. Pins 11 and 14 are used by the receiver part of the chip, this takes data coming from the RS232 cable and converts the high and low pulses into a voltage.

(18)

3: Procedure & Results

Firstly the Tx and Rx boards were built using vero board to mount on the components. The code was put together to read the data from the sensor using MPlab to write and debug the code.

To test the code first a simplier circuit was made, it consisted of the PICdem board with the sensor directly wired into the ports on the PIC.

Fig 3.1

An incircuit debugger was used to program the chip on the PICdem board which was the 16F877a. Once the chip was programmed then using an oscilloscope the results could be tracked to verify that the sensor was working correctly.

Fig 3.2

Unfortunitily the system didn’t work out as the Data line was not being pulled to ground. Due to this the information could not be extracted from the sensor correctly because the Data line needs to go low and not idle between 1 and 0. A reason for this error was due to a faulty sensor, the Data pin on the sensor had been broken off the sensor during set up, this may have caused a bad connection which lead to the Data line not going to 0. This

(19)

was a major setback, had the sensor worked perfectly it would have been possible to exact the data fom the sensor and take an accurate reading from it.

(20)

4: Problems

Many obstacles were encountered during the second semester which backlogged the project significantly. Firstly due to bad planning on my part I didn’t get my objectives completled on the time schedual that I had set out at the start of the project. Secondly the sensor failed to work correctly which hampered any chance of reading in data correctly from the sensor. Thirdly the Zigbee protocol was very difficult to understand at the beginning, it took up a large sum of time researching this area which I now have an understanding of, but due to the lack of time near the end of the semister this part of the project was never completed fully

(21)

5 : Conclusion

This project has been a great learning experience for me, altought I didn’t get the system working like I had hoped at the beginning of the year I still have gained a vast amount of  knowledge and a better insight into projects. They seem easy to look at but this project is a challenging task which requires you to put a lot of time, effort and pre-thought in. I underestimated the work involved and didn’t start on time but likeall humans we learn from our mistakes in a positive way. From this project I will take with me an

understanding of work involved in projects in the future and I hope this experience will stand to me again and again.

Also my skills using MPlab have increased; I started out at the beginning of the semester with very little knowledge of how to use it correctly but with help from my supervisor, classmates and John O’Sullivan I feel like I have learnt a huge amount about it.

(22)

6: References

www.howstuffworks.com www.google.com www.farnell.com www.microchip.com www.sensirion.com

(23)

Appendix 1: Minutes of Meetings

Wireless Weather Station

Minutes

Date 3/10/2008 Time 11:00am

location PF 46 

ATTENDEES Dr. Oliver Gough and Eoghan O’Sullivan

 genda topics

DISCUSSION Sensors CONCLUSIONS Research

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

What types are out there, how much they cost and how

they could be Eoghan

Report due for

Integrated into the project. Next

meeting

DISCUSSION PIC and Zigbee CONCLUSIONS Research

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Research Microchip website, look up protocol stack, in

circuit debugger Eoghan n\a

DISCUSSION Frame a project objective

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Outline the timescale on a Gantt chart Eoghan 7/11/2008

(24)

Wireless Weather Station

Minutes

Date

10/10/2008

Time 11:00am

location PF 46 

ATTENDEES Dr. Oliver Gough and Eoghan O’Sullivan

 genda topics

DISCUSSION Minutes of last meeting

CONCLUSIONS Need to do further research on sensors

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Narrowed down to a couple of sensors, pick the most

suitable Eoghan

Report due for

One for the project Next

meeting

DISCUSSION PIC and Zigbee CONCLUSIONS Research

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Find out how to communicate with the PIC Eoghan n\a

SIGNED Dr. Oliver Gough

Wireless Weather Station

(25)

Dr. Oliver Gough and Eoghan O’Sullivan

 genda topics

Minutes of last meeting Confirmed sensors

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Eoghan will order the Sensirion SHT-75 humidity and

temperature Eoghan

Need this for

sensor from ie.farnell.com February

2009 PICZee chip

Located one for the projected

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Oliver had two chips which I could use on the project n/a n\a Dr. Oliver Gough

Wireless Weather Station

Minutes

Date

(26)

 genda topics

DISCUSSION Minutes of last meeting CONCLUSIONS Sensor has arrived

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Talked more about integrating the sensor into the

project using the PIC n/a n/a

and how the and the need for software

DISCUSSION Project Plan

CONCLUSIONS Needs to be edited

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Changes to be made to the toll gates, milestones and

Gantt chart Eoghan 18/11/2008

SIGNED Dr. Oliver Gough

Wireless Weather Station

Minutes

Date

28/11/2008

Time 11:10am

location PF 46 

ATTENDEES Dr. Oliver Gough and Eoghan O’Sullivan

 genda topics

DISCUSSION Minutes of last meeting

CONCLUSIONS Download PIC 18f462 datasheet

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

(27)

functions of the 2009 PIC chip and how to send and receive data.

DISCUSSION Background research CONCLUSIONS n/a

ACTION ITEMS PERSON RESPONSIBLE DEADLINE

Send it to Olive to be reviewed Eoghan 28/11/2008

(28)

Appendix 2: PIC Code

list p=16f877A include <p16f877A.inc> DelayCount1 equ 0x20 DelayCount2 equ 0x21 Temp equ 0x22 Temp1 equ 0x23 Temp2 equ 0x24 Temp3 equ 0x25 Temp4 equ 0x26 Temp5 equ 0x27 Temp6 equ 0x28 Temp7 equ 0x29 Temp8 equ 0x30 Temp9 equ 0x31 org 0x00 goto start org 0x04 goto ISR org 0x10 start: clrf PORTB bsf STATUS,RP0 clrf TRISB bcf STATUS,RP0 clrf TXREG call TXsetup clrf Temp clrf Temp1 clrf Temp2 clrf Temp3 clrf Temp4 clrf Temp8 clrf Temp9

bsf PORTB,0 ;CLK high (start up, while data is high toggle bsf PORTB,1 ;DATA high (clk 9 or more times,reset) call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high

(29)

call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low ******9th time bsf PORTB,1 ;DATA high

call softdelay

bcf PORTB,1 ;DATA low, before clock change****** bsf PORTB,0 ;CLK high, now clock changes

call softdelay

bsf PORTB,0 ;CLK high ;transmission start bsf PORTB,1 ;DATA high

call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,1 ;DATA low, before clock change****** bsf PORTB,0 ;CLK high, now clock changes

call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low

(30)

call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low

bsf PORTB,1 ;DATA high humidity '000001..' call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low

bcf PORTB,1 ;DATA low humidity '0000010.' call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low

bsf PORTB,1 ;DATA high humidity '00000101' call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bsf STATUS,RP0 ;PORTB set for input movlw 0x02 ;******************* movwf TRISB ;******************* bcf STATUS,RP0 ;******************* bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay

bcf PORTB,0 ;CLK low \\\\changed here 4clock off////  call softdelay bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK low call softdelay

(31)

bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK low call softdelay

bcf PORTB,0 ;CLK low \\\\\\\\resume clock/////////  call softdelay movlw 0x08 movwf Temp3 clrw bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay

(32)

clrf TRISB ; FOR OUTPUT

bcf STATUS,RP0 ;***************** call softdelay

bcf PORTB,1 ;pull data line low for acknowledge bsf PORTB,0 ;CLK high*** acknowledge pulse (9th) call softdelay

bcf PORTB,0 ;CLK low

bsf STATUS,RP0 ;******************* movlw 0x02 ; SET PORTB

movwf TRISB ; FOR INPUT

bcf STATUS,RP0 ;******************* clrf Temp clrf Temp1 clrf Temp3 movlw 0x08 movwf Temp3 call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low

(33)

call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low clrf PORTB ;****************** bsf STATUS,RP0 ; SET PORTB clrf TRISB ; FOR OUTPUT

bcf STATUS,RP0 ;*****************

bcf PORTB,1 ;pull data line low for acknowledge call softdelay

bsf PORTB,0 ;CLK high*** acknowledge pulse (9th) call softdelay

bcf PORTB,0 ;CLK low

bsf STATUS,RP0 ;******************* movlw 0x02 ; SET PORTB

movwf TRISB ; FOR INPUT

bcf STATUS,RP0 ;******************* call softdelay movlw 0x48 movwf Temp8 movlw 0x6d movwf Temp9 call sendout1 ; call sendout

call sendout ;send last 8bits to TX

bsf PORTB,0 ;CLK high...check sum first pulse call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay

(34)

bsf PORTB,0 ;CLK high call softdelay

bcf PORTB,0 ;CLK low call softdelay

bsf PORTB,0 ;CLK high..end of check sum (8th pulse) call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low goto readtemp

Loop: btfss PORTB,0 ;store the first 8 bits

bcf STATUS,C ;*************************** movfw PORTB ;*************************** andlw 0x02 ;*************************** movwf Temp ;*************************** rrf Temp,0 ;*************************** andlw 0x0F ;*************************** iorwf Temp2,1 ;*************************** decf Temp3 ;*************************** btfss STATUS,Z ;*************************** rlf Temp2,1 ;*************************** return

Loop2: btfss PORTB,0 ;store the second 8 bits

bcf STATUS,C ;*************************** movfw PORTB ;*************************** andlw 0x02 ;*************************** movwf Temp ;*************************** rrf Temp,0 ;********************** andlw 0x01 ;*************************** iorwf Temp4,1 ;*************************** decf Temp3 ;*************************** btfss STATUS,Z ;*************************** rlf Temp4,1 ;************************* return softdelay: clrf DelayCount1 movlw 0xC0 movwf DelayCount2 Delayloop: decfsz DelayCount1,F

goto smalldelay goto exitdelay

smalldelay: decfsz DelayCount2,F goto smalldelay

goto Delayloop

exitdelay: Return

TXsetup: bsf STATUS,RP0

(35)

movwf SPBRG ;load value into SPBRG movlw b'10100100' ;async high baud rate movwf TXSTA ;transmit config register bcf STATUS,RP0

movlw b'10000000' ;Enable serial port open movwf RCSTA

return

sendout: bcf STATUS,RP0

movfw Temp2 ;move temp2 to w-reg movwf TXREG ;move w-reg to tx nop nop

bsf STATUS,RP0 ;switch to bank1 bsf TXSTA,TXEN ;enable transmission nop

bcf STATUS,RP0 ;switch to bank0 btfss PIR1,TXIF ;check tx empty goto $-1

nop

movfw Temp4 ;Same code again movwf TXREG ;only this time its for nop ;sending second byte

nop bsf STATUS,RP0 bsf TXSTA,TXEN nop bcf STATUS,RP0 btfss PIR1,TXIF goto $-1

movlw 'X' ; character sent out to make up 8 bits movwf TXREG

nop nop

movlw 'X' ; character sent out to make up 8 bits movwf TXREG

nop nop

movlw 'X' ; character sent out to make up 8 bits movwf TXREG

nop nop

movlw 'X' ; character sent out to make up 8 bits movwf TXREG

nop nop return

(36)

bsf STATUS,RP0 ;switch to bank1 bsf TXSTA,TXEN ;enable transmission nop

bcf STATUS,RP0 ;swictch to bank0 btfss PIR1,TXIF ;check tx empty goto $-1

nop

movfw Temp9 ;Same code again movwf TXREG ;only this time its for nop ;sending second byte

nop bsf STATUS,RP0 bsf TXSTA,TXEN nop bcf STATUS,RP0 btfss PIR1,TXIF goto $-1 return readtemp: clrf PORTB bsf STATUS,RP0 clrf TRISB bcf STATUS,RP0 clrf Temp clrf Temp1 clrf Temp2 clrf Temp3 clrf Temp4 clrf Temp8 clrf Temp9

bsf PORTB,0 ;CLK high ;transmission start

bsf PORTB,1 ;DATA high call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bsf PORTB,1 ;DATA high call softdelay

bcf PORTB,0 ;CLK low bsf PORTB,1 ;DATA high

(37)

call softdelay

bcf PORTB,1 ;DATA low, before clock change****** bsf PORTB,0 ;CLK high, now clock changes

call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low bcf PORTB,1 ;DATA low call softdelay

bsf PORTB,0 ;CLK high bcf PORTB,1 ;DATA low call softdelay

bcf PORTB,0 ;CLK low

bsf PORTB,1 ;DATA High Temperature command call softdelay

bsf PORTB,0 ;CLK high

bsf PORTB,1 ;DATA low temperature command bit high call softdelay

bcf PORTB,0 ;CLK low

bsf PORTB,1 ;DATA high temperature command line stays high call softdelay

bsf PORTB,0 ;CLK high

bsf PORTB,1 ;DATA high temprature line still high (final bit) call softdelay

bsf STATUS,RP0 ;PORTB set for input movlw 0x02 ;******************* movwf TRISB ;******************* bcf STATUS,RP0 ;******************* bcf PORTB,0 ;CLK low

(38)

call softdelay bcf PORTB,0 ;CLK lo call softdelay bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK lo call softdelay bcf PORTB,0 ;CLK low call softdelay bcf PORTB,0 ;CLK lo call softdelay

bcf PORTB,0 ;CLK low \\\\\\\\resume clock/////////  call softdelay

movlw 0x08 ;move 8 into w-reg

movwf Temp3 ;move w-reg to Temp3 to count number of bits saved clrw bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high

(39)

call Loop call softdelay

bcf PORTB,0 ;CLK low

clrf PORTB ;****************** bsf STATUS,RP0 ; SET PORTB clrf TRISB ; FOR OUTPUT

bcf STATUS,RP0 ;***************** call softdelay

bcf PORTB,1 ;pull data line low for acknowledge

bsf PORTB,0 ;CLK high********** acknowledge pulse (9th) call softdelay

bcf PORTB,0 ;CLK low

bsf STATUS,RP0 ;******************* movlw 0x02 ; SET PORTB

movwf TRISB ; FOR INPUT

bcf STATUS,RP0 ;******************* clrf Temp clrf Temp1 clrf Temp3 movlw 0x08 movwf Temp3 call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low

(40)

bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call Loop2 call softdelay bcf PORTB,0 ;CLK low clrf PORTB ;****************** bsf STATUS,RP0 ; SET PORTB clrf TRISB ; FOR OUTPUT

bcf STATUS,RP0 ;*****************

bcf PORTB,1 ;pull data line low for acknowledge call softdelay

bsf PORTB,0 ;CLK high********** acknowledge pulse (9th) call softdelay

bcf PORTB,0 ;CLK low

bsf STATUS,RP0 ;******************* movlw 0x02 ; SET PORTB

movwf TRISB ; FOR INPUT

bcf STATUS,RP0 ;******************* call softdelay movlw 0x54 movwf Temp8 movlw 0x70 movwf Temp9 call sendout1

call sendout ;send bits to TX

bsf PORTB,0 ;CLK high...check sum first pulse call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low

(41)

call softdelay

bsf PORTB,0 ;CLK high call softdelay

bcf PORTB,0 ;CLK low call softdelay

bsf PORTB,0 ;CLK high...end of check sum (8th pulse) call softdelay bcf PORTB,0 ;CLK low call softdelay bsf PORTB,0 ;CLK high call softdelay bcf PORTB,0 ;CLK low goto start ;Loop back to start

ISR: retfie ;Dummy interruptservice routine End

(42)

Appendix 3: Requirement Specification

Requirement Specification

Eoghan O’Sullivan Version 1.2 Status Reviewed Approved

(43)

Contents

STATUS ... 41

1. INTRODUCTION ... 44

1.1. WHAT IS THE AIM OF THE PRODUCT? ... 44

1.2. GOALS ... 44

1.3. USAGE... 45

1.4. BACKGROUND INFORMATION... 45

1.5. DEFINITION OF TERMS ... 45

2. OVERVIEW OF THE SYSTEM ... 45

... 45

2.1. PRODUCT COMPONENTS... 45

2.2. DESIGN PHILOSOPHY... 45

3. DELIVERY ... 46

(44)

Document history

Version Date Changes Sign Reviewed

(45)

Introduction

This project consists of the design of sensor system to record weather data and transmit this data back to a PC.

What is the aim of the product? 

To accurately measure the weather conditions and display the results on a

4 Original To transmit data from the PIC back to the PC. 2

Figure 1. A wireless weather station with a transmitter built in to transmit 

Req.No Original/  Changed

Description of requirement Priority

1 Original To record temperature, humidity and wind speed on to the PIC.

1 2 Original Write a formal report documenting the project to include

graphs and tables demonstrating the success of the project. 1 3 Original Make a project presentation and hopefully to demonstrate

a working prototype.

(46)

Usage 

This system could be used to measure the climatic conditions of a region, each sub-station would transmit back its data to a main hub and a better picture of the regions climate could be shown.

Background information 

Form research on the C.I.T server I found past reports on this project, I also researched in the internet and found other reports with useful information. www.web-ee.com/schematics/instumentations/wireless-weather-station/

Definition of terms 

www = World Wide Web

Overview of the system

Figure 2. An overview of the system.

Product components 

Ill be using sensors to measure the weather conditions and a PIC to read the data. I will be using the zigbee standard to transmit the data in packets.

I will use farnell to locate the sensors for the weather station and microchip to source my zigbee transmitter.

Design philosophy 

Air Speed Sensor Temperature Sensor Humidity Sensor Radio Transmitter Receiver Display PIC Microcontroller

(47)

Study some similar projects on this topic in order to understand my project more.

Delivery

  Date Assessment Criteria

Fri 10th October 

Submit first draft of Project Specification with Minutes of Meetings for comments and feedback.

Fri 17th October 

Submit final draft of Project Specification signed by supervisor.

Fri 24th October 

Submit first draft of project Plan with Minutes of  Meetings for comments and feedback.

Fri 7th  November 

Submit final draft of Project Plan signed by supervisor. Fri 21st

 November 

Submit Background Research/Information Chapter of  Project Report.

Fri 28th  November 

Prepare 10minute Project Presentation. Mon 1st – 

Wed 3rd December 

Present Project Presentation and receive feedback.

Mon 8th –  Thur 11th December 

Present Project Presentation with 5 minute Q&A session to Departmental Staff.

Fri 12th December 

Submit Written Report containing title page, table of  contents, Chapter 1 Introduction, Chapter 2 Background Research, Appendix 1 Minutes of Meetings, Appendix 2 Project Specification and Appendix 3 Project Plan. Fri 27th

February

I hope to have the software for the PIC completed and communicating with the Zigbee.

Fri 27th March

I hope to have the portfolio well under way and the  project almost complete.

Thur 29th April

Around this date I will be giving my presentation on my  project and have a question and answers session.

Fri 1st May

I will had in my project plan book and prototype up to be corrected and assessed

(48)

Documentation

The word processor I will use for this project is Microsoft Word. The templates for the documents are from the LIPS project model, created b y Christian

Krysander and Thomas Svensson.

(49)

Appendix 4: Project Plan

Project Plan

Eoghan O’Sullivan

Version 1.1

(50)

Contents

STATUS ... 48

DOCUMENT HISTORY ... 51

AN OVERVIEW OF THE SYSTEM ... 52

... 52

1.1. PURPOSE AND GOAL... 52

1.2. DELIVERABLES ... 52

2. DELIVERY ... 52

2.1. WHAT IS NOT INCLUDED ... 53

WORK BREAKDOWN STRUCTURE ... 53

THIS IS A LIST OF HOW LONG APPROXIMATELY IT WILL TAKE TO COMPLETE THE FOLLOWING TASKS. ... 53

2.2. BEFORE START... 53

2.3. DURING THE PROJECT... 53

2.4. AFTER THE PROJECT... 54

MEETING PLAN ... 54

RESOURCE PLAN ... 54

2.5. PERSONS... 54

2.6. COMPONENTS ANDEQUIPMENT... 54

2.7. WORK ROOMS... 54

2.8. ECONOMY... 54

MILESTONES AND TOLLGATES ... 54

2.9. MILESTONES... 54

2.10. TOLLGATES... 55

SCHEDULE ... 55

(51)
(52)

Document history

Versio

n

Date

Changes

sign

Reviewed

0.1 21stOctober 2008 First draft Eos 1.1 5thNovember 2008 Second draft Eos

(53)

An overview of the system

Purpose and goal 

This system has various sensors which measure the weather conditions, a microcontroller then sends them to a transmitter where data is sent via a wireless to a receiver and the data is

displayed on a display.

Deliverables 

Delivery

  Date Assessment Criteria

Fri 10th October 

Submit first draft of Project Specification with Minutes of  Meetings for comments and feedback.

Fri 17th October 

Submit final draft of Project Specification signed by supervisor.

Fri 24th October 

Submit first draft of project Plan with Minutes of  Meetings for comments and feedback.

Air Speed Sensor Temperature Sensor Humidity Sensor Radio Transmitter Receiver Display PIC Microcontroller

(54)

Fri 28th  November 

Prepare 10minute Project Presentation. Mon 1st – 

Wed 3rd December 

Present Project Presentation and receive feedback.

Mon 8th –  Thur 11th December 

Present Project Presentation with 5 minute Q&A session to Departmental Staff.

Fri 12th December 

Submit Written Report containing title page, table of  contents, Chapter 1 Introduction, Chapter 2 Background Research, Appendix 1 Minutes of Meetings, Appendix 2 Project Specification and Appendix 3 Project Plan. Fri 27th

February

I hope to have the software for the PIC completed and communicating with the Zigbee.

Fri 27th March

I hope to have the portfolio well under way and the  project almost complete.

Thur 29th April

Around this date I will be giving my presentation on my  project and have a question and answers session.

Fri 1st May

I will had in my project plan book and prototype up to be corrected and assessed

What is not included 

This system does not have the capabilities to transmit over long distances so it would not be the most practical weather station to be made.

Work Breakdown Structure

 This is a list of how long approximately it will take to complete the following tasks.

Before start 

No Activity Description Est. Time

1. Project Specification Write project specification 2 days

2. Project Plan Research project and produce project plan 2.3days 3. Backgroung Research and

Information Chapter 

Research what exaclty the project is about and an information chapter for the project book 

2 days 4. Order Components Order the sensors for the project 1 day

(55)

No Activity Description Est. Time 5. Get the sensors working To read in data onto the PIC 3 weeks 6. Set up transmitter Set up the Zigbee protocol to send data 2 weeks 7. Write software To take the variables and put them in a program

to and display the result on the screen

3 weeks 8. Test it as a whole unit and

tidy up the appearance

Make sure its working and to make a housing for  the board and transmitter 

2 weeks

After the project 

No Activity Description Est. Time

9. Final Report A detailed written report on the project 1 weeks 10. Final Presentation A 15minute presentation on the project where i

show a working prototype

2 weeks

Meeting plan

My supervisor Dr.Oliver Gough and I meet once a week in PF46. The time varies week to week due to status of the project.

Resource plan

Persons 

Dr. Oliver Gough and Eoghan O’Sullivan

Components and Equipment 

I will need to order sensors for the weather station, included in the li st are: Temperature sensor, Humidity sensor and a Wind speed sensor.

I also need to order a PIC board and a zigbee standard system to transmit my data. For the software I will be using MatLab to write up code for th e PIC.

Work rooms 

Most of the work I can do in the senior lab B176a, I can also do work at home as I have tools to assist me.

Economy 

I am hoping to source all the components for under 60eur. This is subject to change as I have not confirmed what exactly I need yet.

(56)

No Description Date

1. Requirement specification ready 24/10/2008

2. Project Plan ready 7/11/2008

3. Background Research/Information Chapter of Project Report ready. 21/11/2008

4. Order Components 11/11/2008

5. Sensors working 20/02/2009

6. Transmitter working 6/03/2009

7. Get software fully written and working 27/03/2009

8. Fully working and testing underway 10/04/2009

9. Final written report 17/04/2009

1 Final Presentation 30/04/2009

Tollgates 

No Description Date

1 Approval of project specification 24/10/2008

2 Approval of project plan 7/11/2008

3 Approval of Chapter one of project report 21/11/2008

4 Sensors working and reading on the PIC 20/02/2009

5 Sending data to a PC 27/03/2009

6 Working fully with software implemented 10/04/2009

7 Final Presentation 30/04/2009

Schedule

Risk analysis

Programming is my weakness, I hope to have the sensors connected to the PIC and reading the data with no flaws. If I get bogged down in programming I might lose time that I could use in doing something else to the project.

References

Outline

Related documents

All stationary perfect equilibria of the intertemporal game approach (as slight stochastic perturbations as in Nash (1953) tend to zero) the same division of surplus as the static

In this study, it is aimed to develop the Science Education Peer Comparison Scale (SEPCS) in order to measure the comparison of Science Education students'

By first analysing the image data in terms of the local image structures, such as lines or edges, and then controlling the filtering based on local information from the analysis

This data descriptor presents the database of hydrographic (i.e., temperature and salinity) profiles obtained by instrumented seals in the Southern Indian Ocean.. This database is

The results highlight that the relative importance of different sources of competitiveness differs across sectors and thus reconcile the differences in emphasis in relation to the

Quality: We measure quality (Q in our formal model) by observing the average number of citations received by a scientist for all the papers he or she published in a given

Konveksi satuan hanya melayani desain 1 bahan + sablon/bordir, tanpa ada kombinasi bahan &amp; warna, kecuali kombinasi warna yang dipakai bukan dari kain panjang untuk

Our end—of—period rates are the daily London close quotes (midpoints) from the Financial Times, which over this period were recorded at 5 PM London time. Our beginning—of—period