91

Dependencies:   ADXL362 ATParser MPL3115A2 TSL2561 mbed

Fork of Lab9-1 by CPS-Lab*

Committer:
fanbsun
Date:
Fri Apr 06 20:22:02 2018 +0000
Revision:
5:4a5b8c114486
Parent:
4:eb81ef9e1621
Child:
6:074cf15af4a2
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fanbsun 0:9a45e4f07b10 1 #include "mbed.h"
fanbsun 0:9a45e4f07b10 2 #include "MPL3115A2.h"
fanbsun 0:9a45e4f07b10 3 #include <string>
fanbsun 0:9a45e4f07b10 4 #include <math.h>
jackclar 4:eb81ef9e1621 5 #include <ATParser.h>
jackclar 4:eb81ef9e1621 6 #include "BufferedSerial.h"
fanbsun 5:4a5b8c114486 7
jackclar 4:eb81ef9e1621 8 //Serial pc(SERIAL_TX, SERIAL_RX);
fanbsun 0:9a45e4f07b10 9 DigitalOut myled(LED1);
jackclar 2:c322c1331eaa 10 DigitalOut powerpin(PA_8); // GPIO pin
jackclar 4:eb81ef9e1621 11 BufferedSerial pc(SERIAL_TX, SERIAL_RX);
jackclar 4:eb81ef9e1621 12 BufferedSerial device(PA_9, PA_10);
fanbsun 5:4a5b8c114486 13
fanbsun 0:9a45e4f07b10 14 // Selects SDA as I2C1_SDA on pin PB_7
fanbsun 0:9a45e4f07b10 15 // Selects SCL on I2C1_SCL on pin PB_6
fanbsun 0:9a45e4f07b10 16 // The I2C address of the pressure sensor is fixed at 0x60.
fanbsun 0:9a45e4f07b10 17 MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
fanbsun 5:4a5b8c114486 18
fanbsun 0:9a45e4f07b10 19 int main() {
jackclar 2:c322c1331eaa 20 uint8_t id;
fanbsun 0:9a45e4f07b10 21 double p, t;
fanbsun 0:9a45e4f07b10 22 myled = 0;
fanbsun 0:9a45e4f07b10 23 powerpin = 0;
jackclar 4:eb81ef9e1621 24 ATParser at = ATParser(device, "\r\n", 256, 2000, false);
fanbsun 5:4a5b8c114486 25 char buffer[30];
jackclar 4:eb81ef9e1621 26 pc.baud(115200);
jackclar 4:eb81ef9e1621 27 device.baud(115200);
fanbsun 5:4a5b8c114486 28
fanbsun 5:4a5b8c114486 29 pc.printf("Hello");
jackclar 4:eb81ef9e1621 30
fanbsun 5:4a5b8c114486 31 at.send("AT+NI=1,MTCDT-19400691\n\r");
fanbsun 5:4a5b8c114486 32 wait(1);
fanbsun 5:4a5b8c114486 33 printf("Hello");
fanbsun 5:4a5b8c114486 34 at.send("AT+NK=1,MTCDT-19400691\n\r");
fanbsun 5:4a5b8c114486 35 wait(1);
fanbsun 5:4a5b8c114486 36 at.send("AT+FSB=1\n\r");
fanbsun 5:4a5b8c114486 37 wait(1);
fanbsun 5:4a5b8c114486 38 at.send("AT+JOIN\n\r");
jackclar 4:eb81ef9e1621 39
jackclar 2:c322c1331eaa 40 while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
jackclar 2:c322c1331eaa 41 {
jackclar 2:c322c1331eaa 42 wait(1);
jackclar 2:c322c1331eaa 43 }
fanbsun 0:9a45e4f07b10 44
fanbsun 0:9a45e4f07b10 45 while(1)
fanbsun 0:9a45e4f07b10 46 {
fanbsun 5:4a5b8c114486 47 wait(3600);
fanbsun 5:4a5b8c114486 48 p=pressure_sensor.getPressure();
fanbsun 5:4a5b8c114486 49 t=pressure_sensor.getTemperature();
fanbsun 5:4a5b8c114486 50 sprintf(buffer, "AT+SEND=%.1f,%.1f", p, t);
fanbsun 5:4a5b8c114486 51 buffer[18] = '\0';
fanbsun 5:4a5b8c114486 52 pc.printf(buffer);
fanbsun 5:4a5b8c114486 53 at.send(buffer);
fanbsun 0:9a45e4f07b10 54 }
jackclar 2:c322c1331eaa 55 }