Test firmware for the Supermote hardware.

Dependencies:   K30_I2C libxDot-mbed5

Fork of K30_I2C_Program by Hux Connect

Committer:
bjenkins
Date:
Fri Sep 07 02:54:05 2018 +0000
Revision:
2:680fc2690d10
Parent:
0:85741f91edf0
Child:
3:2ab969b31f6b
Initial commit

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