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.