Test firmware for the Supermote hardware.

Dependencies:   K30_I2C libxDot-mbed5

Fork of K30_I2C_Program by Hux Connect

Committer:
david_hux
Date:
Fri Jun 29 00:41:34 2018 +0000
Revision:
0:85741f91edf0
Child:
2:680fc2690d10
Sample code to integrate with K30_I2C library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
david_hux 0:85741f91edf0 1 #include "mbed.h"
david_hux 0:85741f91edf0 2 #include "mDot.h"
david_hux 0:85741f91edf0 3 #include "ChannelPlans.h"
david_hux 0:85741f91edf0 4 #include "K30_I2C.h"
david_hux 0:85741f91edf0 5
david_hux 0:85741f91edf0 6
david_hux 0:85741f91edf0 7 mDot* dot = NULL;
david_hux 0:85741f91edf0 8
david_hux 0:85741f91edf0 9 Serial pc(USBTX,USBRX); // xDot dev board
david_hux 0:85741f91edf0 10 //Serial pc(PA_2, PA_3); // Murata dev board
david_hux 0:85741f91edf0 11 K30_I2C k30(I2C_SDA, I2C_SCL, 0x68<<1); // xDot dev board
david_hux 0:85741f91edf0 12 //K30_I2C k30(PB_9, PB_8, 0x68<<1); // Muarata dev board
david_hux 0:85741f91edf0 13 //AnalogIn HCHO(PB_14);
david_hux 0:85741f91edf0 14
david_hux 0:85741f91edf0 15 DigitalOut blueLED (GPIO0);
david_hux 0:85741f91edf0 16 DigitalOut orangeLED (GPIO1);
david_hux 0:85741f91edf0 17 DigitalOut enable_5V (GPIO3);
david_hux 0:85741f91edf0 18
david_hux 0:85741f91edf0 19 int main (){
david_hux 0:85741f91edf0 20 lora::ChannelPlan * plan = new lora::ChannelPlan_AS923();
david_hux 0:85741f91edf0 21 dot = mDot::getInstance(plan);
david_hux 0:85741f91edf0 22
david_hux 0:85741f91edf0 23 pc.baud(115200);
david_hux 0:85741f91edf0 24 pc.printf("**************************\r\n");
david_hux 0:85741f91edf0 25 pc.printf("\tCO2 Sensor\r\n");
david_hux 0:85741f91edf0 26 pc.printf("**************************\r\n");
david_hux 0:85741f91edf0 27
david_hux 0:85741f91edf0 28 enable_5V = true;
david_hux 0:85741f91edf0 29
david_hux 0:85741f91edf0 30 blueLED = orangeLED = true;
david_hux 0:85741f91edf0 31 dot->setAdr(true);
david_hux 0:85741f91edf0 32 dot->sleep(3,dot->RTC_ALARM,false);
david_hux 0:85741f91edf0 33 // k30.scan(); // Careful; has potential to cause breakage of system
david_hux 0:85741f91edf0 34
david_hux 0:85741f91edf0 35 int co2;
david_hux 0:85741f91edf0 36 int rc_check;
david_hux 0:85741f91edf0 37 int counter = 0;
david_hux 0:85741f91edf0 38 bool counterFail = false;
david_hux 0:85741f91edf0 39
david_hux 0:85741f91edf0 40 orangeLED = blueLED = false;
david_hux 0:85741f91edf0 41
david_hux 0:85741f91edf0 42 while(1){
david_hux 0:85741f91edf0 43 dot->sleep(2,dot->RTC_ALARM,false);
david_hux 0:85741f91edf0 44 blueLED = orangeLED = !orangeLED;
david_hux 0:85741f91edf0 45 // k30.scan();
david_hux 0:85741f91edf0 46 // wait(7.0f);
david_hux 0:85741f91edf0 47 // pc.printf("**********************\r\n");
david_hux 0:85741f91edf0 48 // pc.printf("Reading CH2O sensor ...... \r\n");
david_hux 0:85741f91edf0 49 // ch2o_ppm = HCHO.read()*3.125*3.6 - 1.25;
david_hux 0:85741f91edf0 50 // pc.printf("Formaldehyde Level: %.3f ppm\r\n\n", ch2o_ppm);
david_hux 0:85741f91edf0 51
david_hux 0:85741f91edf0 52 pc.printf("Reading K30 sensor ...... \r\n");
david_hux 0:85741f91edf0 53 rc_check = k30.readCO2(co2);
david_hux 0:85741f91edf0 54
david_hux 0:85741f91edf0 55 // pc.printf("%d \r\n", rc_check);
david_hux 0:85741f91edf0 56
david_hux 0:85741f91edf0 57 if (rc_check&&co2){
david_hux 0:85741f91edf0 58 pc.printf("Successful reading\r\nCO2:\t%d ppm\r\n",co2);
david_hux 0:85741f91edf0 59 if(!co2){
david_hux 0:85741f91edf0 60 counterFail = true;
david_hux 0:85741f91edf0 61 }
david_hux 0:85741f91edf0 62 if(!counterFail) {
david_hux 0:85741f91edf0 63 counter++;
david_hux 0:85741f91edf0 64 pc.printf("Success Count: %d\r\n", counter);
david_hux 0:85741f91edf0 65 }
david_hux 0:85741f91edf0 66 else pc.printf("Failure at: %d\r\n", counter);
david_hux 0:85741f91edf0 67 }
david_hux 0:85741f91edf0 68 else{
david_hux 0:85741f91edf0 69 pc.printf("Failure to read sensor \r\n");
david_hux 0:85741f91edf0 70 pc.printf("Last count: %d\r\n", counter);
david_hux 0:85741f91edf0 71 counterFail = true;
david_hux 0:85741f91edf0 72 }
david_hux 0:85741f91edf0 73 }
david_hux 0:85741f91edf0 74 }