2015年3月6日星期五

Week 5 (6th Mar 2015)

Week 5.1 (6th Mar 2015)
This is the fifth week of our group project. Our progresses are listed below:
First of all, the circuit was built out by connecting the temperature and pressure sensor to the FRDM-KL46Z through conducting wires. The pins of MPL 115A2 are ensured to be connected to corresponding pins on FRDM-KL46Z correctly. The microprocessors FRDM-KL46Z and LPC1768 are separately connected to two computers through USB wires.


After that, we continue with programming work. The basic flowchart of outdoor and indoor code is shown below:
Outdoor


Indoor


The outdoor part of code we utilize is an example code offered on http://developer.mbed.org/users/joeh/code/mpl115a2_example/ 
We change several specific pin names to make sure that this code suits FRDM-KL46Z successfully. 

The detailed indoor part of code we write is:

#include "mbed.h"
//#include "C12832.h"

Serial device(p9, p10);
Serial pc(USBTX, USBRX);
//C12832 lcd(p5, p7, p6, p8, p11);

int get_message(char  array[]);
int decode_message(char array[]);
float convertdata(char array[]);
int test(void);
float ws=0, wd=0, rg=0, tp=0, ps=0;

int main()
{
    int length;;
   
    int ok;
    char n[100];
   
    for(;;)
    {
    length = get_message(n);
    ok = decode_message(n);
                 
    //lcd.locate(0,4);
    pc.printf("wind speed is: %5.1f\n\r", ws);
    //lcd.locate(0,16);
    pc.printf("wind direction is: %5.1f\n\r", wd);
    //lcd.cls();
    //lcd.locate(0,4);
    pc.printf("rain guage is: %5.1f\n\r", rg);
    //lcd.locate(0,16);
    pc.printf("temperature is: %5.1f\n\r", tp);
    //lcd.cls();
    //lcd.locate(0,4);
    pc.printf("pressure is: %5.1f\n\r", ps);
    //lcd.cls();
    }                          
   
}
           
int get_message(char  array[])
{
bool gotheader = false;
bool gotend = false;
char read;
int  i;

// testing
//    printf("In get message\n\r");
    do
    {
        //printf("Waiting\n\r");
        if (device.readable())
        {
            //printf("Device Readable\n\r");
            read=device.getc();
            if(read == '@') gotheader = true;
            //pc.putc(read);            
        }
    }    while(gotheader == false);

//    printf("Got Header\n\r");

    i = 0;
    do
    {
        if (device.readable())
        {
            read=device.getc();
            array[i] = read;  
            i = i + 1;
            if (read == '\n') gotend = true;            
        }
    }    while(gotend == false);
   
//    printf("Got end\n\r");
//    printf("%c %c %c %c %c %c\n\r", array[0], array[1],array[2],array[3],array[4],array[5]);
   
    return (i);
}

int decode_message(char array[])
{
    if ((array[0] == 'W') && (array[1] == 'S'))
    {
        ws = convertdata(array);
    }
    if ((array[0] == 'W') && (array[1] == 'D'))
    {
        wd = convertdata(array);
    }
    if ((array[0] == 'R') && (array[1] == 'G'))
    {
        rg = convertdata(array);
    }
    if ((array[0] == 'T') && (array[1] == 'P'))
    {
        tp = convertdata(array);
    }
    if ((array[0] == 'P') && (array[1] == 'S'))
    {
        ps = convertdata(array);
    }    
}

float convertdata(char array[])
{
float value;
int R;

    R = sscanf(&array[2], "%f", &value);
 //   printf("Value read is %f  \n\r", value);
    return value;
}


/*
int test(void)
{
    int read;
    int gotheader = false;
    pc.printf("Started\n\r");
    pc.printf("In get message\n\r");
    do
    {
       //pc.printf("Waiting\n\r");
        if (device.readable())
        {
            pc.printf("Device Readable\n\r");
            read=device.getc();
            pc.putc(read);            
        }
    }    while(gotheader == false);

}
*/

To test the function of those codes, simulated data for wind speed, wind direction and rainfall are artificially generated out which are incremented automatically. In terms of the data for temperature and pressure, they are sent from the sensor MLP 115A2. All of those data are displayed through PuTTY which are shown as below:




Having completed this, it shows that the data of temperature and pressure can be detected by sensor MLP 115A2, passed from FRDM-KL46Z to LPC1768 wirelessly and then displayed on the screen successfully. 
What remains to do is mainly processing the signal sensed by the outside wind and rain sensor and replacing the artificially generated data. 














2015年3月1日星期日

Week 4 (27th Feb 2015)

Week 4 (27th Feb 2015)
This is the forth week of the wireless weather station project.
The main progress of the lab day was divided into two parts. One was on detecting the signal types of the wind direction and wind speed and the other was programming.

  • Detect signal types

To achieve this task, the outside sensor from WH1081 is taken apart as photo shown below:

According to the photo, the above one is wind speed sensor whose inside chip is as:

There are 8 switches connected with 8 resistors in the circuits whose resistor values are measured and specified by group members. The representing circuit is shown in figure below:

In terms of the signal type that wind speed sensor sends, it has been clarified that every 120 degrees the outside jacket rotates, it would generate a digital pulse signal. It means that every time the sensor makes a round, three digital pulses will be sent.

Seen from the first photo, the sensor below is the one for wind direction whose inside chip is like:

It has been found out that there is a magnet in the shell.  Due to the magnetic connection between the shell and chip, the direction sensor has the ability to sense changes of wind direction and then generates analog signals.

  • Programming

One of the group member focused on writing the code, especially the signal receiving function. The present code is shown as below: