Test firmware for the Supermote hardware.
Dependencies: K30_I2C libxDot-mbed5
Fork of K30_I2C_Program by
main.cpp
- Committer:
- david_hux
- Date:
- 2018-06-29
- Revision:
- 0:85741f91edf0
- Child:
- 2:680fc2690d10
File content as of revision 0:85741f91edf0:
#include "mbed.h" #include "mDot.h" #include "ChannelPlans.h" #include "K30_I2C.h" mDot* dot = NULL; Serial pc(USBTX,USBRX); // xDot dev board //Serial pc(PA_2, PA_3); // Murata dev board K30_I2C k30(I2C_SDA, I2C_SCL, 0x68<<1); // xDot dev board //K30_I2C k30(PB_9, PB_8, 0x68<<1); // Muarata dev board //AnalogIn HCHO(PB_14); DigitalOut blueLED (GPIO0); DigitalOut orangeLED (GPIO1); DigitalOut enable_5V (GPIO3); int main (){ lora::ChannelPlan * plan = new lora::ChannelPlan_AS923(); dot = mDot::getInstance(plan); pc.baud(115200); pc.printf("**************************\r\n"); pc.printf("\tCO2 Sensor\r\n"); pc.printf("**************************\r\n"); enable_5V = true; blueLED = orangeLED = true; dot->setAdr(true); dot->sleep(3,dot->RTC_ALARM,false); // k30.scan(); // Careful; has potential to cause breakage of system int co2; int rc_check; int counter = 0; bool counterFail = false; orangeLED = blueLED = false; while(1){ dot->sleep(2,dot->RTC_ALARM,false); blueLED = orangeLED = !orangeLED; // k30.scan(); // wait(7.0f); // pc.printf("**********************\r\n"); // pc.printf("Reading CH2O sensor ...... \r\n"); // ch2o_ppm = HCHO.read()*3.125*3.6 - 1.25; // pc.printf("Formaldehyde Level: %.3f ppm\r\n\n", ch2o_ppm); pc.printf("Reading K30 sensor ...... \r\n"); rc_check = k30.readCO2(co2); // pc.printf("%d \r\n", rc_check); if (rc_check&&co2){ pc.printf("Successful reading\r\nCO2:\t%d ppm\r\n",co2); if(!co2){ counterFail = true; } if(!counterFail) { counter++; pc.printf("Success Count: %d\r\n", counter); } else pc.printf("Failure at: %d\r\n", counter); } else{ pc.printf("Failure to read sensor \r\n"); pc.printf("Last count: %d\r\n", counter); counterFail = true; } } }