Test firmware for the Supermote hardware.

Dependencies:   K30_I2C libxDot-mbed5

Fork of K30_I2C_Program by Hux Connect

Committer:
bjenkins
Date:
Fri Sep 14 03:17:31 2018 +0000
Revision:
3:2ab969b31f6b
Parent:
2:680fc2690d10
Update PM code

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"
bjenkins 2:680fc2690d10 4
bjenkins 3:2ab969b31f6b 5 //#define TEST_HPM // PM2.5 / PM10
bjenkins 2:680fc2690d10 6 //#define TEST_MICS_VZ_89TE // voc
bjenkins 3:2ab969b31f6b 7 //#define TEST_SPEC_3SP_CO // CO
bjenkins 2:680fc2690d10 8 #define TEST_K30 // CO2 sensor
bjenkins 2:680fc2690d10 9
bjenkins 2:680fc2690d10 10 #ifdef TEST_HPM
bjenkins 2:680fc2690d10 11 #include "hpm.h"
bjenkins 2:680fc2690d10 12 #endif
bjenkins 2:680fc2690d10 13
bjenkins 2:680fc2690d10 14 #ifdef TEST_MICS_VZ_89TE
bjenkins 2:680fc2690d10 15 #include "mics_vz_89te.h"
bjenkins 2:680fc2690d10 16 #endif
bjenkins 2:680fc2690d10 17
bjenkins 2:680fc2690d10 18 #ifdef TEST_SPEC_3SP_CO
bjenkins 2:680fc2690d10 19 #include "spec_3sp_co.h"
bjenkins 2:680fc2690d10 20 #endif
bjenkins 2:680fc2690d10 21
bjenkins 2:680fc2690d10 22 #ifdef TEST_K30
bjenkins 2:680fc2690d10 23 #include "K30_I2C.h"
bjenkins 2:680fc2690d10 24 #endif
david_hux 0:85741f91edf0 25
david_hux 0:85741f91edf0 26
david_hux 0:85741f91edf0 27 mDot* dot = NULL;
bjenkins 2:680fc2690d10 28 Serial pc (USBTX, USBRX); // xDot USB interface
bjenkins 2:680fc2690d10 29 Serial device (UART_TX, UART_RX); // xDot UART to sensors
david_hux 0:85741f91edf0 30
bjenkins 2:680fc2690d10 31 #ifdef TEST_HPM
bjenkins 2:680fc2690d10 32 HPM hpm = HPM::HPM(&device, &pc);
bjenkins 2:680fc2690d10 33 long int PM25;
bjenkins 2:680fc2690d10 34 long int PM10;
bjenkins 2:680fc2690d10 35 #endif
bjenkins 2:680fc2690d10 36
bjenkins 2:680fc2690d10 37 #ifdef TEST_MICS_VZ_89TE
bjenkins 2:680fc2690d10 38 MICS_VZ_89TE sensor_voc = MICS_VZ_89TE::MICS_VZ_89TE(I2C_SDA, I2C_SCL, 0x70<<1);
bjenkins 2:680fc2690d10 39 int co2_fromVOC = 0;
bjenkins 2:680fc2690d10 40 int voc = 0;
bjenkins 2:680fc2690d10 41 #endif
bjenkins 2:680fc2690d10 42
bjenkins 2:680fc2690d10 43 #ifdef TEST_SPEC_3SP_CO
bjenkins 2:680fc2690d10 44 SPEC_3SP_CO sensor_co = SPEC_3SP_CO::SPEC_3SP_CO(I2C_SDA, I2C_SCL, ADS1x1x_I2C_ADDRESS_ADDR_TO_VCC<<1, 3.29);
bjenkins 2:680fc2690d10 45 int co = 0;
bjenkins 2:680fc2690d10 46 #endif
bjenkins 2:680fc2690d10 47
bjenkins 2:680fc2690d10 48 #ifdef TEST_K30
bjenkins 3:2ab969b31f6b 49 K30_I2C k30(I2C_SDA, I2C_SCL, 0x68<<1);
bjenkins 2:680fc2690d10 50 int co2 = 0;
bjenkins 2:680fc2690d10 51 #endif
david_hux 0:85741f91edf0 52
bjenkins 2:680fc2690d10 53 DigitalOut blueLED (GPIO0);
bjenkins 2:680fc2690d10 54 DigitalOut orangeLED (GPIO1);
bjenkins 2:680fc2690d10 55 DigitalOut enable_5V (GPIO3);
bjenkins 2:680fc2690d10 56 DigitalOut enable_voc (UART_RTS);
bjenkins 2:680fc2690d10 57 DigitalOut enable_co (SPI_SCK);
bjenkins 2:680fc2690d10 58
bjenkins 2:680fc2690d10 59 bool b_response;
bjenkins 2:680fc2690d10 60
bjenkins 2:680fc2690d10 61 void turnOn5v(void)
bjenkins 2:680fc2690d10 62 {
bjenkins 2:680fc2690d10 63 pc.printf("Turning on 5v rail...");
bjenkins 2:680fc2690d10 64 enable_5V = true;
bjenkins 2:680fc2690d10 65 wait(1);
bjenkins 2:680fc2690d10 66 pc.printf("done\r\n");
bjenkins 2:680fc2690d10 67 }
bjenkins 2:680fc2690d10 68
bjenkins 2:680fc2690d10 69 void turnOffv(void)
bjenkins 2:680fc2690d10 70 {
bjenkins 2:680fc2690d10 71 pc.printf("Turning off 5v rail...");
bjenkins 2:680fc2690d10 72 enable_5V = false;
bjenkins 2:680fc2690d10 73 wait(1);
bjenkins 2:680fc2690d10 74 pc.printf("done\r\n");
bjenkins 2:680fc2690d10 75 }
david_hux 0:85741f91edf0 76
bjenkins 3:2ab969b31f6b 77 int main ()
bjenkins 3:2ab969b31f6b 78 {
bjenkins 2:680fc2690d10 79 // Initialising
bjenkins 2:680fc2690d10 80 blueLED = true;
bjenkins 2:680fc2690d10 81 orangeLED = false;
bjenkins 2:680fc2690d10 82
bjenkins 2:680fc2690d10 83 pc.baud(57600); // start debug port
bjenkins 2:680fc2690d10 84 pc.printf("************************\r\n");
bjenkins 2:680fc2690d10 85 pc.printf(" HARDWARE TEST FIRMWARE\r\n");
bjenkins 2:680fc2690d10 86 pc.printf("************************\r\n\r\n");
bjenkins 2:680fc2690d10 87
bjenkins 2:680fc2690d10 88
bjenkins 2:680fc2690d10 89 #ifdef TEST_HPM
bjenkins 2:680fc2690d10 90 turnOn5v();
bjenkins 3:2ab969b31f6b 91 do {
bjenkins 3:2ab969b31f6b 92 b_response = hpm.init();
bjenkins 3:2ab969b31f6b 93 if (!b_response)
bjenkins 3:2ab969b31f6b 94 {
bjenkins 3:2ab969b31f6b 95 pc.printf("Initialisation of PM sensor failed\r\n");
bjenkins 3:2ab969b31f6b 96 wait(1.0);
bjenkins 3:2ab969b31f6b 97 }
bjenkins 3:2ab969b31f6b 98 } while (!b_response);
bjenkins 3:2ab969b31f6b 99 pc.printf("Initialisation of PM sensor success\r\n");
bjenkins 3:2ab969b31f6b 100
bjenkins 2:680fc2690d10 101 #endif
bjenkins 2:680fc2690d10 102
bjenkins 2:680fc2690d10 103 #ifdef TEST_MICS_VZ_89TE
bjenkins 2:680fc2690d10 104 pc.printf("Enabling MICS_VZ_89TE...");
bjenkins 2:680fc2690d10 105 enable_voc = true;
bjenkins 2:680fc2690d10 106 wait(1);
bjenkins 2:680fc2690d10 107 pc.printf("done\r\n");
david_hux 0:85741f91edf0 108
bjenkins 2:680fc2690d10 109 sensor_voc.getVersion();
bjenkins 2:680fc2690d10 110 #endif
bjenkins 2:680fc2690d10 111
bjenkins 2:680fc2690d10 112 #ifdef TEST_SPEC_3SP_CO
bjenkins 2:680fc2690d10 113 pc.printf("Enabling SPEC_3SP_CO...");
bjenkins 2:680fc2690d10 114 enable_co = true;
bjenkins 2:680fc2690d10 115 wait(1);
bjenkins 2:680fc2690d10 116 pc.printf("done\r\n");
bjenkins 2:680fc2690d10 117
bjenkins 2:680fc2690d10 118 sensor_co.init();
bjenkins 2:680fc2690d10 119 #endif
bjenkins 2:680fc2690d10 120
bjenkins 2:680fc2690d10 121 #ifdef TEST_K30
bjenkins 2:680fc2690d10 122 turnOn5v();
bjenkins 2:680fc2690d10 123 #endif
david_hux 0:85741f91edf0 124
david_hux 0:85741f91edf0 125 orangeLED = blueLED = false;
david_hux 0:85741f91edf0 126
bjenkins 2:680fc2690d10 127 while(1)
bjenkins 2:680fc2690d10 128 {
bjenkins 2:680fc2690d10 129 #ifdef TEST_HPM
bjenkins 2:680fc2690d10 130 b_response = hpm.read_measurement(PM25, PM10);
bjenkins 2:680fc2690d10 131 if (b_response)
bjenkins 2:680fc2690d10 132 {
bjenkins 3:2ab969b31f6b 133 pc.printf ("PM2.5 = %d ug/m3, PM10 = %d ug/m3\r", PM25, PM10);
bjenkins 2:680fc2690d10 134 }
bjenkins 2:680fc2690d10 135 else
bjenkins 2:680fc2690d10 136 {
bjenkins 2:680fc2690d10 137 pc.printf("Read measurement status is %d\r\n", b_response);
bjenkins 2:680fc2690d10 138 }
bjenkins 2:680fc2690d10 139 #endif
david_hux 0:85741f91edf0 140
bjenkins 2:680fc2690d10 141 #ifdef TEST_MICS_VZ_89TE
bjenkins 2:680fc2690d10 142 char status = sensor_voc.readSensor(co2_fromVOC, voc);
bjenkins 2:680fc2690d10 143 pc.printf ("MICS_VZ_89TE: CO2=%d ppm, VOC%d ppb (status=%02x)\r\n", co2_fromVOC, voc, status);
bjenkins 2:680fc2690d10 144 #endif
bjenkins 2:680fc2690d10 145
bjenkins 2:680fc2690d10 146 #ifdef TEST_SPEC_3SP_CO
bjenkins 2:680fc2690d10 147 sensor_co.start_conversion();
bjenkins 2:680fc2690d10 148 // wait 7.8ms
bjenkins 2:680fc2690d10 149 wait(0.01);
bjenkins 2:680fc2690d10 150
bjenkins 2:680fc2690d10 151 float co_ppm = sensor_co.read();
bjenkins 2:680fc2690d10 152 pc.printf ("SPEC_3SP_CO: CO=%.2fppm\r\n", co_ppm);
bjenkins 2:680fc2690d10 153 #endif
bjenkins 2:680fc2690d10 154
bjenkins 2:680fc2690d10 155 #ifdef TEST_K30
bjenkins 3:2ab969b31f6b 156 int rc_check = k30.readCO2(co2);
bjenkins 2:680fc2690d10 157 if (rc_check)
bjenkins 2:680fc2690d10 158 pc.printf("K30 CO2:%d ppm\r\n",co2);
bjenkins 2:680fc2690d10 159 else
bjenkins 2:680fc2690d10 160 pc.printf("Failed to read CO2 sensor\r\n");
bjenkins 2:680fc2690d10 161 #endif
bjenkins 2:680fc2690d10 162
bjenkins 2:680fc2690d10 163 wait (1);
bjenkins 2:680fc2690d10 164 blueLED = !blueLED;
bjenkins 2:680fc2690d10 165 pc.printf ("\r\n");
david_hux 0:85741f91edf0 166 }
david_hux 0:85741f91edf0 167 }