Test firmware for the Supermote hardware.
Dependencies: K30_I2C libxDot-mbed5
Fork of K30_I2C_Program by
Diff: main.cpp
- Revision:
- 2:680fc2690d10
- Parent:
- 0:85741f91edf0
- Child:
- 3:2ab969b31f6b
--- a/main.cpp Fri Aug 17 07:25:00 2018 +0000 +++ b/main.cpp Fri Sep 07 02:54:05 2018 +0000 @@ -1,74 +1,164 @@ #include "mbed.h" #include "mDot.h" #include "ChannelPlans.h" -#include "K30_I2C.h" + +//#define TEST_HPM // particle +//#define TEST_MICS_VZ_89TE // voc +#define TEST_SPEC_3SP_CO // CO +#define TEST_K30 // CO2 sensor + +#ifdef TEST_HPM + #include "hpm.h" +#endif + +#ifdef TEST_MICS_VZ_89TE + #include "mics_vz_89te.h" +#endif + +#ifdef TEST_SPEC_3SP_CO + #include "spec_3sp_co.h" +#endif + +#ifdef TEST_K30 + #include "K30_I2C.h" +#endif mDot* dot = NULL; +Serial pc (USBTX, USBRX); // xDot USB interface +Serial device (UART_TX, UART_RX); // xDot UART to sensors +bool need5v = false; -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); +#ifdef TEST_HPM + HPM hpm = HPM::HPM(&device, &pc); + long int PM25; + long int PM10; +#endif + +#ifdef TEST_MICS_VZ_89TE + MICS_VZ_89TE sensor_voc = MICS_VZ_89TE::MICS_VZ_89TE(I2C_SDA, I2C_SCL, 0x70<<1); + int co2_fromVOC = 0; + int voc = 0; +#endif + +#ifdef TEST_SPEC_3SP_CO + SPEC_3SP_CO sensor_co = SPEC_3SP_CO::SPEC_3SP_CO(I2C_SDA, I2C_SCL, ADS1x1x_I2C_ADDRESS_ADDR_TO_VCC<<1, 3.29); + int co = 0; +#endif + +#ifdef TEST_K30 + K30_I2C k30(I2C_SDA, I2C_SCL, 0x68<<1); // xDot dev board + int co2 = 0; +#endif -DigitalOut blueLED (GPIO0); -DigitalOut orangeLED (GPIO1); -DigitalOut enable_5V (GPIO3); +DigitalOut blueLED (GPIO0); +DigitalOut orangeLED (GPIO1); +DigitalOut enable_5V (GPIO3); +DigitalOut enable_voc (UART_RTS); +DigitalOut enable_co (SPI_SCK); + +bool b_response; + +void turnOn5v(void) +{ + pc.printf("Turning on 5v rail..."); + enable_5V = true; + wait(1); + pc.printf("done\r\n"); +} + +void turnOffv(void) +{ + pc.printf("Turning off 5v rail..."); + enable_5V = false; + wait(1); + pc.printf("done\r\n"); +} 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; + + // Initialising + blueLED = true; + orangeLED = false; + + //lora::ChannelPlan * plan = new lora::ChannelPlan_AS923(); + //dot = mDot::getInstance(plan); + //dot->setAdr(true); + + pc.baud(57600); // start debug port + pc.printf("************************\r\n"); + pc.printf(" HARDWARE TEST FIRMWARE\r\n"); + pc.printf("************************\r\n\r\n"); + + +#ifdef TEST_HPM + turnOn5v(); + b_response = hpm.init(); +#endif + +#ifdef TEST_MICS_VZ_89TE + pc.printf("Enabling MICS_VZ_89TE..."); + enable_voc = true; + wait(1); + pc.printf("done\r\n"); - blueLED = orangeLED = true; - dot->setAdr(true); - dot->sleep(3,dot->RTC_ALARM,false); -// k30.scan(); // Careful; has potential to cause breakage of system + sensor_voc.getVersion(); +#endif + +#ifdef TEST_SPEC_3SP_CO + pc.printf("Enabling SPEC_3SP_CO..."); + enable_co = true; + wait(1); + pc.printf("done\r\n"); + + sensor_co.init(); +#endif + +#ifdef TEST_K30 + turnOn5v(); +#endif - 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); + while(1) + { +#ifdef TEST_HPM + b_response = hpm.read_measurement(PM25, PM10); + if (b_response) + { + pc.printf ("PM2.5 = %d ug/m3, PM10 = %d ug/m3\r\n", PM25, PM10); + } + else + { + pc.printf("Read measurement status is %d\r\n", b_response); + } +#endif - 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; - } +#ifdef TEST_MICS_VZ_89TE + char status = sensor_voc.readSensor(co2_fromVOC, voc); + pc.printf ("MICS_VZ_89TE: CO2=%d ppm, VOC%d ppb (status=%02x)\r\n", co2_fromVOC, voc, status); +#endif + +#ifdef TEST_SPEC_3SP_CO + sensor_co.start_conversion(); + // wait 7.8ms + wait(0.01); + + float co_ppm = sensor_co.read(); + pc.printf ("SPEC_3SP_CO: CO=%.2fppm\r\n", co_ppm); +#endif + +#ifdef TEST_K30 + int rc_check; + rc_check = k30.readCO2(co2); + if (rc_check) + pc.printf("K30 CO2:%d ppm\r\n",co2); + else + pc.printf("Failed to read CO2 sensor\r\n"); +#endif + + wait (1); + blueLED = !blueLED; + pc.printf ("\r\n"); } } \ No newline at end of file