Test code to interface AOD UPAS with IoT provider.
Dependencies: ESP8266_AT NCP5623BMUTBG mbed ADS1115 AOD_Calculation BME280 PMS5003 SunPosition CAM_M8
main.cpp@3:f878eab2ebe0, 2017-11-26 (annotated)
- Committer:
- eawendtjr
- Date:
- Sun Nov 26 01:43:18 2017 +0000
- Revision:
- 3:f878eab2ebe0
- Parent:
- 2:3df874f33c42
- Child:
- 4:8a667120ee2b
Sending real AOD data to thingspeak at 30 second intervals.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eawendtjr | 0:62df2a5864d5 | 1 | #include "mbed.h" |
eawendtjr | 0:62df2a5864d5 | 2 | #include "NCP5623BMUTBG.h" |
eawendtjr | 0:62df2a5864d5 | 3 | #include "ESP8266_AT.h" |
eawendtjr | 3:f878eab2ebe0 | 4 | #include "SunPosition.h" |
eawendtjr | 3:f878eab2ebe0 | 5 | #include "AOD_Calculation.h" |
eawendtjr | 3:f878eab2ebe0 | 6 | #include "Adafruit_ADS1015.h" |
eawendtjr | 3:f878eab2ebe0 | 7 | #include "BME280.h" |
eawendtjr | 0:62df2a5864d5 | 8 | |
eawendtjr | 0:62df2a5864d5 | 9 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 10 | //Define core buses and pin states. |
eawendtjr | 0:62df2a5864d5 | 11 | ///////////////////////////////////////////// |
eawendtjr | 2:3df874f33c42 | 12 | I2C i2c(PB_9, PB_8);//(D14, D15); SDA,SCL |
eawendtjr | 2:3df874f33c42 | 13 | Serial pc(USBTX, USBRX); |
eawendtjr | 2:3df874f33c42 | 14 | DigitalOut pumps(PA_9, 0);//(D8, 0); |
eawendtjr | 2:3df874f33c42 | 15 | DigitalOut pbKill(PC_12, 1); // Digital input pin that conncect to the LTC2950 battery charger used to shutdown the UPAS |
eawendtjr | 2:3df874f33c42 | 16 | DigitalIn nINT(PA_15); //Connected but currently unused is a digital ouput pin from LTC2950 battery charger. http://cds.linear.com/docs/en/datasheet/295012fd.pdf |
eawendtjr | 2:3df874f33c42 | 17 | NCP5623BMUTBG RGB_LED(PB_9, PB_8); //(D14, D15); |
eawendtjr | 0:62df2a5864d5 | 18 | |
eawendtjr | 0:62df2a5864d5 | 19 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 20 | //RN4677 BT/BLE Module |
eawendtjr | 0:62df2a5864d5 | 21 | ///////////////////////////////////////////// |
eawendtjr | 2:3df874f33c42 | 22 | Serial ble(PB_10, PB_11); |
eawendtjr | 2:3df874f33c42 | 23 | DigitalOut bleRTS(PB_14, 0); |
eawendtjr | 2:3df874f33c42 | 24 | DigitalOut bleCTS(PB_13, 0); |
eawendtjr | 2:3df874f33c42 | 25 | DigitalOut BT_IRST(PC_8, 0); |
eawendtjr | 2:3df874f33c42 | 26 | DigitalOut BT_SW(PA_12, 0); |
eawendtjr | 0:62df2a5864d5 | 27 | |
eawendtjr | 0:62df2a5864d5 | 28 | |
eawendtjr | 0:62df2a5864d5 | 29 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 30 | //Analog to Digital Converter |
eawendtjr | 0:62df2a5864d5 | 31 | ///////////////////////////////////////////// |
eawendtjr | 2:3df874f33c42 | 32 | DigitalIn ADS_ALRT(PA_10); //Connected but currently unused. (ADS1115) http://www.ti.com/lit/ds/symlink/ads1115.pdf |
eawendtjr | 0:62df2a5864d5 | 33 | |
eawendtjr | 0:62df2a5864d5 | 34 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 35 | //Battery, Charger, & Supply Monitoring |
eawendtjr | 0:62df2a5864d5 | 36 | ///////////////////////////////////////////// |
eawendtjr | 2:3df874f33c42 | 37 | DigitalIn LTCALT(PB_2); //High for normal operation. Low when a threshold is exceeded for Voltage, gas gauge, or temp |
eawendtjr | 2:3df874f33c42 | 38 | DigitalIn bcs1(PC_9); //Batt charging if High. (BQ24100)[U23] |
eawendtjr | 2:3df874f33c42 | 39 | DigitalIn bcs2(PA_8); //Charge complete if High. (BQ24100)[U23] |
eawendtjr | 2:3df874f33c42 | 40 | DigitalIn bc_npg(PB_1); //Power to the charge controller. (BQ24100)[U23] |
eawendtjr | 2:3df874f33c42 | 41 | DigitalIn SW3flt(PC_4); //When EN = 0 pin is HIGH, When EN = 1, LOW can be current limit, thermal limit, or UVLO. |
eawendtjr | 0:62df2a5864d5 | 42 | |
eawendtjr | 0:62df2a5864d5 | 43 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 44 | //Sensirion SDP3X(s) |
eawendtjr | 0:62df2a5864d5 | 45 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 46 | DigitalIn SDP3Xflt(PC_0); |
eawendtjr | 0:62df2a5864d5 | 47 | DigitalIn SDP3XAltflt(PB_7); |
eawendtjr | 0:62df2a5864d5 | 48 | |
eawendtjr | 0:62df2a5864d5 | 49 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 50 | //Accelerometer and Magnometer |
eawendtjr | 0:62df2a5864d5 | 51 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 52 | DigitalOut iNemoEnable(PA_1, 0); |
eawendtjr | 0:62df2a5864d5 | 53 | DigitalIn iNemoReady(PB_0); |
eawendtjr | 0:62df2a5864d5 | 54 | DigitalIn iNemoInt1(PC_5); |
eawendtjr | 0:62df2a5864d5 | 55 | DigitalIn iNemoInt2(PC_6); |
eawendtjr | 0:62df2a5864d5 | 56 | DigitalIn iNemoInt3(PC_7); |
eawendtjr | 0:62df2a5864d5 | 57 | |
eawendtjr | 0:62df2a5864d5 | 58 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 59 | //UV and Visible Light Sensor |
eawendtjr | 0:62df2a5864d5 | 60 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 61 | |
eawendtjr | 0:62df2a5864d5 | 62 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 63 | //GPS |
eawendtjr | 0:62df2a5864d5 | 64 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 65 | DigitalOut gpsEN(PB_15, 0); |
eawendtjr | 0:62df2a5864d5 | 66 | DigitalIn gpsENFault(PB_12); |
eawendtjr | 0:62df2a5864d5 | 67 | |
eawendtjr | 0:62df2a5864d5 | 68 | |
eawendtjr | 0:62df2a5864d5 | 69 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 70 | //SD Card |
eawendtjr | 0:62df2a5864d5 | 71 | ///////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 72 | DigitalIn sdCD(PA_11); |
eawendtjr | 0:62df2a5864d5 | 73 | DigitalOut sdClk(PB_3,0 ); |
eawendtjr | 0:62df2a5864d5 | 74 | DigitalIn sdMISO(PB_4); |
eawendtjr | 0:62df2a5864d5 | 75 | DigitalOut sdMOSI(PB_5, 0); |
eawendtjr | 0:62df2a5864d5 | 76 | DigitalOut sdCS(PB_6, 1); |
eawendtjr | 0:62df2a5864d5 | 77 | |
eawendtjr | 0:62df2a5864d5 | 78 | DigitalIn pbIso(PA_0); |
eawendtjr | 0:62df2a5864d5 | 79 | DigitalOut hFault1(PA_7, 0); |
eawendtjr | 0:62df2a5864d5 | 80 | DigitalOut hFault2(PA_6, 0); |
eawendtjr | 0:62df2a5864d5 | 81 | DigitalOut hFault3(PA_5, 0); |
eawendtjr | 0:62df2a5864d5 | 82 | DigitalOut hFault4(PA_4, 0); |
eawendtjr | 0:62df2a5864d5 | 83 | |
eawendtjr | 0:62df2a5864d5 | 84 | DigitalOut wifiNReset(PC_1, 0); |
eawendtjr | 0:62df2a5864d5 | 85 | DigitalOut wifiEnable(PC_2, 0); |
eawendtjr | 0:62df2a5864d5 | 86 | DigitalOut qdEnable(PC_3, 0); |
eawendtjr | 0:62df2a5864d5 | 87 | DigitalIn qdFault(PC_13); |
eawendtjr | 0:62df2a5864d5 | 88 | |
eawendtjr | 3:f878eab2ebe0 | 89 | ///////////////////////////////////////////// |
eawendtjr | 3:f878eab2ebe0 | 90 | //AOD Objects |
eawendtjr | 3:f878eab2ebe0 | 91 | ///////////////////////////////////////////// |
eawendtjr | 3:f878eab2ebe0 | 92 | SunPosition sun; |
eawendtjr | 3:f878eab2ebe0 | 93 | AOD_Calculation aod_440; |
eawendtjr | 3:f878eab2ebe0 | 94 | AOD_Calculation aod_870; |
eawendtjr | 3:f878eab2ebe0 | 95 | AOD_Calculation aod_680; |
eawendtjr | 3:f878eab2ebe0 | 96 | AOD_Calculation aod_520; |
eawendtjr | 3:f878eab2ebe0 | 97 | Adafruit_ADS1115 ads_sun(&i2c, ADS1015_ADDRESS_VDD); //Adress pin connected to 3.3V |
eawendtjr | 3:f878eab2ebe0 | 98 | BME280 bme(PB_9, PB_8, 0xEC); //(D14, D15); |
eawendtjr | 3:f878eab2ebe0 | 99 | |
eawendtjr | 0:62df2a5864d5 | 100 | ESP8266_AT esp(PC_10, PC_11); |
eawendtjr | 0:62df2a5864d5 | 101 | |
eawendtjr | 1:702f144a88b2 | 102 | Timer t; |
eawendtjr | 1:702f144a88b2 | 103 | |
eawendtjr | 1:702f144a88b2 | 104 | char ssid[] = "VOLTAR"; |
eawendtjr | 1:702f144a88b2 | 105 | char password[] = "CedhCedh"; |
eawendtjr | 1:702f144a88b2 | 106 | char server[] = "api.thingspeak.com"; |
eawendtjr | 3:f878eab2ebe0 | 107 | char apiKey[] = "32QVSK5INPPAVIV0"; |
eawendtjr | 1:702f144a88b2 | 108 | char conn_type[] = "TCP"; |
eawendtjr | 1:702f144a88b2 | 109 | |
eawendtjr | 0:62df2a5864d5 | 110 | // For selecting the WiFi UART |
eawendtjr | 0:62df2a5864d5 | 111 | const int addr = 0x3F << 1; |
eawendtjr | 0:62df2a5864d5 | 112 | char aod_sel_5on[1]; |
eawendtjr | 0:62df2a5864d5 | 113 | char aod_sel_5off[1]; |
eawendtjr | 0:62df2a5864d5 | 114 | char plant_sel[1]; |
eawendtjr | 0:62df2a5864d5 | 115 | |
eawendtjr | 3:f878eab2ebe0 | 116 | //AOD Variables |
eawendtjr | 3:f878eab2ebe0 | 117 | //Globals for sun calulation input |
eawendtjr | 3:f878eab2ebe0 | 118 | int year = 2017; |
eawendtjr | 3:f878eab2ebe0 | 119 | int month = 11; |
eawendtjr | 3:f878eab2ebe0 | 120 | int day = 21; |
eawendtjr | 3:f878eab2ebe0 | 121 | int hour = 12; |
eawendtjr | 3:f878eab2ebe0 | 122 | int minute = 0; |
eawendtjr | 3:f878eab2ebe0 | 123 | double second = 0; |
eawendtjr | 3:f878eab2ebe0 | 124 | double latitude = 40.5853; |
eawendtjr | 3:f878eab2ebe0 | 125 | double longitude = -105.0844; |
eawendtjr | 3:f878eab2ebe0 | 126 | double altitude = 1525; |
eawendtjr | 3:f878eab2ebe0 | 127 | double temperature; |
eawendtjr | 3:f878eab2ebe0 | 128 | double pressure; |
eawendtjr | 3:f878eab2ebe0 | 129 | |
eawendtjr | 3:f878eab2ebe0 | 130 | //Globals for sun calculation output |
eawendtjr | 3:f878eab2ebe0 | 131 | double zenith; |
eawendtjr | 3:f878eab2ebe0 | 132 | double azimuth; |
eawendtjr | 3:f878eab2ebe0 | 133 | double radius; |
eawendtjr | 3:f878eab2ebe0 | 134 | |
eawendtjr | 3:f878eab2ebe0 | 135 | //Constants |
eawendtjr | 3:f878eab2ebe0 | 136 | const double time_zone = 0; //GPS gets Greenwich time |
eawendtjr | 3:f878eab2ebe0 | 137 | const double delta_t = 68; //This parameter will be roughly constant this year |
eawendtjr | 3:f878eab2ebe0 | 138 | const double slope = 30; |
eawendtjr | 3:f878eab2ebe0 | 139 | const double azm_rotation = 10; |
eawendtjr | 3:f878eab2ebe0 | 140 | |
eawendtjr | 3:f878eab2ebe0 | 141 | //AOD CALCULATION |
eawendtjr | 3:f878eab2ebe0 | 142 | //AOD Calculation Constants |
eawendtjr | 3:f878eab2ebe0 | 143 | const double lambda_440 = 0.440; |
eawendtjr | 3:f878eab2ebe0 | 144 | const double lambda_520 = 0.520; |
eawendtjr | 3:f878eab2ebe0 | 145 | const double lambda_680 = 0.680; |
eawendtjr | 3:f878eab2ebe0 | 146 | const double lambda_870 = 0.870; |
eawendtjr | 3:f878eab2ebe0 | 147 | const double CO2_ppv = 0.00036; |
eawendtjr | 3:f878eab2ebe0 | 148 | const double v0_440 = 1.25; |
eawendtjr | 3:f878eab2ebe0 | 149 | const double v0_520 = 1.45; |
eawendtjr | 3:f878eab2ebe0 | 150 | const double v0_680 = 1.40; |
eawendtjr | 3:f878eab2ebe0 | 151 | const double v0_870 = 1.35; |
eawendtjr | 3:f878eab2ebe0 | 152 | const double vd = 0.001225; |
eawendtjr | 3:f878eab2ebe0 | 153 | const double oz_coeff_440 = 0.0029; |
eawendtjr | 3:f878eab2ebe0 | 154 | const double oz_coeff_520 = 0.0481; |
eawendtjr | 3:f878eab2ebe0 | 155 | const double oz_coeff_680 = 0.0361; |
eawendtjr | 3:f878eab2ebe0 | 156 | const double oz_coeff_870 = 0.0013; |
eawendtjr | 3:f878eab2ebe0 | 157 | |
eawendtjr | 3:f878eab2ebe0 | 158 | //Voltage from light detector |
eawendtjr | 3:f878eab2ebe0 | 159 | double v870; //Voltage read from 870nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 160 | double v_raw870; //Raw analog output from 870nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 161 | double v680; //Voltage read from 680nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 162 | double v_raw680; //Raw analog output from 680nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 163 | double v520; //Voltage read from 520nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 164 | double v_raw520; //Raw analog output from 520nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 165 | double v440; //Voltage read from 440nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 166 | double v_raw440; //Raw analog output from 440nm photodiode |
eawendtjr | 3:f878eab2ebe0 | 167 | double AOD_870; |
eawendtjr | 3:f878eab2ebe0 | 168 | double AOD_680; |
eawendtjr | 3:f878eab2ebe0 | 169 | double AOD_520; |
eawendtjr | 3:f878eab2ebe0 | 170 | double AOD_440; |
eawendtjr | 3:f878eab2ebe0 | 171 | |
eawendtjr | 3:f878eab2ebe0 | 172 | //AOD functions |
eawendtjr | 3:f878eab2ebe0 | 173 | void getAODs(); |
eawendtjr | 3:f878eab2ebe0 | 174 | |
eawendtjr | 0:62df2a5864d5 | 175 | ////////////////////////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 176 | //Main Function |
eawendtjr | 0:62df2a5864d5 | 177 | ////////////////////////////////////////////////////////////// |
eawendtjr | 0:62df2a5864d5 | 178 | int main() |
eawendtjr | 0:62df2a5864d5 | 179 | { |
eawendtjr | 0:62df2a5864d5 | 180 | pc.baud(115200); |
eawendtjr | 1:702f144a88b2 | 181 | RGB_LED.set_led(1, 0, 1); |
eawendtjr | 1:702f144a88b2 | 182 | wait(1); |
eawendtjr | 0:62df2a5864d5 | 183 | |
eawendtjr | 0:62df2a5864d5 | 184 | aod_sel_5on[0] = 0xCB; |
eawendtjr | 0:62df2a5864d5 | 185 | aod_sel_5off[0] = 0xC9; |
eawendtjr | 0:62df2a5864d5 | 186 | plant_sel[0] = 0xCF; |
eawendtjr | 0:62df2a5864d5 | 187 | |
eawendtjr | 1:702f144a88b2 | 188 | RGB_LED.set_led(1, 1, 1); |
eawendtjr | 3:f878eab2ebe0 | 189 | i2c.write(addr, aod_sel_5on, 1); |
eawendtjr | 0:62df2a5864d5 | 190 | pc.printf("Plantower off\r\n"); |
eawendtjr | 1:702f144a88b2 | 191 | wait(1); |
eawendtjr | 0:62df2a5864d5 | 192 | |
eawendtjr | 1:702f144a88b2 | 193 | //Enable the WiFi chip |
eawendtjr | 0:62df2a5864d5 | 194 | RGB_LED.set_led(0, 1, 1); // Light LED so we know something is happening |
eawendtjr | 0:62df2a5864d5 | 195 | wifiEnable = 1; // Enable power to the WiFi while in reset, and wait a short while |
eawendtjr | 0:62df2a5864d5 | 196 | wait_ms(100); |
eawendtjr | 0:62df2a5864d5 | 197 | wifiNReset = 1; // Now de-assert the reset signal |
eawendtjr | 0:62df2a5864d5 | 198 | RGB_LED.set_led(1, 1, 0); // Color change of LED to indicate something is happening. |
eawendtjr | 1:702f144a88b2 | 199 | wait(10); |
eawendtjr | 1:702f144a88b2 | 200 | |
eawendtjr | 1:702f144a88b2 | 201 | RGB_LED.set_led(0, 1, 0); |
eawendtjr | 1:702f144a88b2 | 202 | esp.check_esp(); |
eawendtjr | 1:702f144a88b2 | 203 | esp.version_info(); |
eawendtjr | 1:702f144a88b2 | 204 | esp.software_reset(); |
eawendtjr | 1:702f144a88b2 | 205 | |
eawendtjr | 1:702f144a88b2 | 206 | esp.command_echo_mode(ESP_ECHO_ON); |
eawendtjr | 1:702f144a88b2 | 207 | esp.set_wifi_mode(ESP_DUAL_CONFIG); |
eawendtjr | 1:702f144a88b2 | 208 | esp.enable_multiple_connections(); |
eawendtjr | 0:62df2a5864d5 | 209 | |
eawendtjr | 1:702f144a88b2 | 210 | esp.create_tcp_server(80); |
eawendtjr | 1:702f144a88b2 | 211 | |
eawendtjr | 1:702f144a88b2 | 212 | //esp.set_server_timeout(5); |
eawendtjr | 1:702f144a88b2 | 213 | |
eawendtjr | 1:702f144a88b2 | 214 | esp.list_access_points(); |
eawendtjr | 1:702f144a88b2 | 215 | esp.wifi_connect(ssid, password); |
eawendtjr | 1:702f144a88b2 | 216 | esp.check_ap(); |
eawendtjr | 1:702f144a88b2 | 217 | esp.get_ip(); |
eawendtjr | 1:702f144a88b2 | 218 | |
eawendtjr | 1:702f144a88b2 | 219 | char someArray[150]; |
eawendtjr | 1:702f144a88b2 | 220 | |
eawendtjr | 1:702f144a88b2 | 221 | t.start(); |
eawendtjr | 0:62df2a5864d5 | 222 | while(1) |
eawendtjr | 0:62df2a5864d5 | 223 | { |
eawendtjr | 1:702f144a88b2 | 224 | RGB_LED.set_led(0, 0, 1); |
eawendtjr | 1:702f144a88b2 | 225 | if(t.read()>30)//if 30 seconds passed |
eawendtjr | 1:702f144a88b2 | 226 | { |
eawendtjr | 1:702f144a88b2 | 227 | t.reset();//reset timer |
eawendtjr | 3:f878eab2ebe0 | 228 | |
eawendtjr | 3:f878eab2ebe0 | 229 | RGB_LED.set_led(1, 1, 1); |
eawendtjr | 3:f878eab2ebe0 | 230 | |
eawendtjr | 3:f878eab2ebe0 | 231 | //get the AOD |
eawendtjr | 3:f878eab2ebe0 | 232 | getAODs(); |
eawendtjr | 3:f878eab2ebe0 | 233 | |
eawendtjr | 3:f878eab2ebe0 | 234 | //send data to thingspeaks |
eawendtjr | 3:f878eab2ebe0 | 235 | sprintf(someArray,"GET https://api.thingspeak.com/update?api_key=32QVSK5INPPAVIV0&field1=%.2f&field2=%.2f&field3=%.2f&field4=%.2f\r\n\r\n",AOD_440,AOD_520,AOD_680,AOD_870); |
eawendtjr | 1:702f144a88b2 | 236 | |
eawendtjr | 1:702f144a88b2 | 237 | esp.delete_tcp_server(); |
eawendtjr | 1:702f144a88b2 | 238 | esp.establish_connection(0, conn_type, server, 80); |
eawendtjr | 2:3df874f33c42 | 239 | esp.send_data_tcp(0, someArray); |
eawendtjr | 2:3df874f33c42 | 240 | esp.close_connection(0); |
eawendtjr | 1:702f144a88b2 | 241 | esp.create_tcp_server(80); |
eawendtjr | 1:702f144a88b2 | 242 | pc.printf("%s\r\n", someArray); |
eawendtjr | 1:702f144a88b2 | 243 | } |
eawendtjr | 0:62df2a5864d5 | 244 | } |
eawendtjr | 0:62df2a5864d5 | 245 | } |
eawendtjr | 3:f878eab2ebe0 | 246 | |
eawendtjr | 3:f878eab2ebe0 | 247 | void getAODs() |
eawendtjr | 3:f878eab2ebe0 | 248 | { |
eawendtjr | 3:f878eab2ebe0 | 249 | temperature = bme.getTemperature(); |
eawendtjr | 3:f878eab2ebe0 | 250 | pressure = bme.getPressure(temperature); |
eawendtjr | 3:f878eab2ebe0 | 251 | |
eawendtjr | 3:f878eab2ebe0 | 252 | sun.setValues(year, month, day, hour, minute, second, time_zone, delta_t, latitude, longitude, altitude, temperature, pressure, slope, azm_rotation); |
eawendtjr | 3:f878eab2ebe0 | 253 | sun.findSun(); |
eawendtjr | 3:f878eab2ebe0 | 254 | zenith = sun.getZenith(); |
eawendtjr | 3:f878eab2ebe0 | 255 | radius = sun.getRadius(); |
eawendtjr | 3:f878eab2ebe0 | 256 | |
eawendtjr | 3:f878eab2ebe0 | 257 | //Read the light detectors |
eawendtjr | 3:f878eab2ebe0 | 258 | v_raw870 = (double)ads_sun.readADC_SingleEnded(A3_GAIN_ONE); //Channel A3 | 1x gain | +/-4.096V | 1 bit = 2mV | 0.125mV |
eawendtjr | 3:f878eab2ebe0 | 259 | v870 = (v_raw870*0.125)/(1000); //Converts to a voltage |
eawendtjr | 3:f878eab2ebe0 | 260 | |
eawendtjr | 3:f878eab2ebe0 | 261 | v_raw680 = (double)ads_sun.readADC_SingleEnded(A2_GAIN_ONE); //Channel A2 | 1x gain | +/-4.096V | 1 bit = 2mV | 0.125mV |
eawendtjr | 3:f878eab2ebe0 | 262 | v680 = (v_raw680*0.125)/(1000); //Converts to a voltage |
eawendtjr | 3:f878eab2ebe0 | 263 | |
eawendtjr | 3:f878eab2ebe0 | 264 | v_raw520 = (double)ads_sun.readADC_SingleEnded(A1_GAIN_ONE); //Channel A1 | 1x gain | +/-4.096V | 1 bit = 2mV | 0.125mV |
eawendtjr | 3:f878eab2ebe0 | 265 | v520 = (v_raw520*0.125)/(1000); //Converts to a voltage |
eawendtjr | 3:f878eab2ebe0 | 266 | |
eawendtjr | 3:f878eab2ebe0 | 267 | v_raw440 = (double)ads_sun.readADC_SingleEnded(A0_GAIN_ONE); //Channel A1 | 1x gain | +/-4.096V | 1 bit = 2mV | 0.125mV |
eawendtjr | 3:f878eab2ebe0 | 268 | v440 = (v_raw520*0.125)/(1000); //Converts to a voltage |
eawendtjr | 3:f878eab2ebe0 | 269 | |
eawendtjr | 3:f878eab2ebe0 | 270 | //Calculate the AOD for all channels |
eawendtjr | 3:f878eab2ebe0 | 271 | aod_870.setAODInputs(longitude, latitude, altitude, lambda_870, CO2_ppv, pressure, month, day, oz_coeff_870, v0_870, vd, v870, radius, zenith); |
eawendtjr | 3:f878eab2ebe0 | 272 | aod_870.opticalDepth(); |
eawendtjr | 3:f878eab2ebe0 | 273 | AOD_870 = aod_870.getAOD(); |
eawendtjr | 3:f878eab2ebe0 | 274 | |
eawendtjr | 3:f878eab2ebe0 | 275 | aod_680.setAODInputs(longitude, latitude, altitude, lambda_680, CO2_ppv, pressure, month, day, oz_coeff_680, v0_680, vd, v680, radius, zenith); |
eawendtjr | 3:f878eab2ebe0 | 276 | aod_680.opticalDepth(); |
eawendtjr | 3:f878eab2ebe0 | 277 | AOD_680 = aod_680.getAOD(); |
eawendtjr | 3:f878eab2ebe0 | 278 | |
eawendtjr | 3:f878eab2ebe0 | 279 | aod_520.setAODInputs(longitude, latitude, altitude, lambda_520, CO2_ppv, pressure, month, day, oz_coeff_520, v0_520, vd, v520, radius, zenith); |
eawendtjr | 3:f878eab2ebe0 | 280 | aod_520.opticalDepth(); |
eawendtjr | 3:f878eab2ebe0 | 281 | AOD_520 = aod_520.getAOD(); |
eawendtjr | 3:f878eab2ebe0 | 282 | |
eawendtjr | 3:f878eab2ebe0 | 283 | aod_440.setAODInputs(longitude, latitude, altitude, lambda_440, CO2_ppv, pressure, month, day, oz_coeff_440, v0_440, vd, v440, radius, zenith); |
eawendtjr | 3:f878eab2ebe0 | 284 | aod_440.opticalDepth(); |
eawendtjr | 3:f878eab2ebe0 | 285 | AOD_440 = aod_440.getAOD(); |
eawendtjr | 3:f878eab2ebe0 | 286 | } |