CPS-Lab* / Mbed 2 deprecated Lab92

Dependencies:   ADXL362 ATParser MPL3115A2 TSL2561 mbed

Fork of Lab91 by Fanbo Sun

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MPL3115A2.h"
00003 #include <string.h>
00004 #include <math.h>
00005 #include <ATParser.h>
00006 #include "BufferedSerial.h"
00007 #include "TSL2561.h"
00008 
00009  
00010 //Serial pc(SERIAL_TX, SERIAL_RX);
00011 DigitalOut myled(LED1);
00012 DigitalOut powerpin(PA_8); // GPIO pin
00013 BufferedSerial pc(SERIAL_TX, SERIAL_RX);
00014 BufferedSerial device(PA_9, PA_10);
00015  
00016 // Selects SDA as I2C1_SDA on pin PB_7
00017 // Selects SCL on I2C1_SCL on pin PB_6
00018 // The I2C address of the pressure sensor is fixed at 0x60. 
00019 MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
00020 TSL2561 lightsensor(PB_4,PA_7);
00021 
00022  
00023 int main() {
00024     uint8_t id;
00025     double p, t, l;
00026     myled = 0;
00027     powerpin = 0;
00028     char s[6];
00029     ATParser at = ATParser(device, "\r\n", 256, 2000, false);
00030     char buffer[200];
00031     char buffer1[30];
00032     pc.baud(115200);
00033     device.baud(115200);
00034     
00035     pc.printf("Hello");
00036     
00037     at.send("AT+NI=1,MTCDT-19400691\n\r") && at.recv("OK");
00038     at.send("AT+NK=1,MTCDT-19400691\n\r") && at.recv("OK");
00039     at.send("AT+FSB=1\n\r") && at.recv("OK");
00040     at.send("AT+JOIN\n\r") && at.recv("OK");
00041     at.send("AT+TXDR=7\n\r") && at.recv("OK");
00042     
00043     
00044     
00045     while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
00046     {
00047         wait(1);
00048     }
00049     
00050     strcpy(buffer, "AT+SEND=");
00051        
00052     while(1) 
00053     {
00054         for(int i = 0; i< 24; i++)
00055         {     
00056             l=lightsensor.lux(); 
00057             sprintf(s, "%.1f", l);
00058             strcat(buffer, s);
00059             strcat(buffer, ",");
00060             pc.printf(buffer);
00061             pc.printf("\n\r");
00062             wait(5);
00063         }
00064         
00065             
00066         
00067          
00068      //   p=pressure_sensor.getPressure();
00069      //   t=pressure_sensor.getTemperature();
00070        // sprintf(buffer1, "AT+SEND=a\n\r");
00071      //   sprintf(buffer, "AT+SEND=%.1f,%.1f\n\r", p, t);
00072     //    pc.printf(buffer);
00073         at.send(buffer) && at.recv("OK"); 
00074      //   at.send(buffer1) && at.recv("OK"); 
00075         wait(10);
00076     }
00077 }