Test code to interface AOD UPAS with IoT provider.

Dependencies:   ESP8266_AT NCP5623BMUTBG mbed ADS1115 AOD_Calculation BME280 PMS5003 SunPosition CAM_M8

Committer:
eawendtjr
Date:
Tue Nov 21 00:47:43 2017 +0000
Revision:
0:62df2a5864d5
Child:
1:702f144a88b2
Cycles through board operational modes and then tests wifi chip.

Who changed what in which revision?

UserRevisionLine numberNew 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 0:62df2a5864d5 4
eawendtjr 0:62df2a5864d5 5 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 6 //Define core buses and pin states.
eawendtjr 0:62df2a5864d5 7 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 8 I2C i2c(PB_9, PB_8);//(D14, D15); SDA,SCL
eawendtjr 0:62df2a5864d5 9 Serial pc(USBTX, USBRX);
eawendtjr 0:62df2a5864d5 10 DigitalOut pumps(PA_9, 0);//(D8, 0);
eawendtjr 0:62df2a5864d5 11 DigitalOut pbKill(PC_12, 1); // Digital input pin that conncect to the LTC2950 battery charger used to shutdown the UPAS
eawendtjr 0:62df2a5864d5 12 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 0:62df2a5864d5 13 NCP5623BMUTBG RGB_LED(PB_9, PB_8); //(D14, D15);
eawendtjr 0:62df2a5864d5 14
eawendtjr 0:62df2a5864d5 15 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 16 //RN4677 BT/BLE Module
eawendtjr 0:62df2a5864d5 17 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 18 Serial ble(PB_10, PB_11);
eawendtjr 0:62df2a5864d5 19 DigitalOut bleRTS(PB_14, 0);
eawendtjr 0:62df2a5864d5 20 DigitalOut bleCTS(PB_13, 0);
eawendtjr 0:62df2a5864d5 21 DigitalOut BT_IRST(PC_8, 0);
eawendtjr 0:62df2a5864d5 22 DigitalOut BT_SW(PA_12, 0);
eawendtjr 0:62df2a5864d5 23
eawendtjr 0:62df2a5864d5 24
eawendtjr 0:62df2a5864d5 25 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 26 //Analog to Digital Converter
eawendtjr 0:62df2a5864d5 27 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 28 DigitalIn ADS_ALRT(PA_10); //Connected but currently unused. (ADS1115) http://www.ti.com/lit/ds/symlink/ads1115.pdf
eawendtjr 0:62df2a5864d5 29
eawendtjr 0:62df2a5864d5 30 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 31 //Battery, Charger, & Supply Monitoring
eawendtjr 0:62df2a5864d5 32 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 33 DigitalIn LTCALT(PB_2); //High for normal operation. Low when a threshold is exceeded for Voltage, gas gauge, or temp
eawendtjr 0:62df2a5864d5 34 DigitalIn bcs1(PC_9); //Batt charging if High. (BQ24100)[U23]
eawendtjr 0:62df2a5864d5 35 DigitalIn bcs2(PA_8); //Charge complete if High. (BQ24100)[U23]
eawendtjr 0:62df2a5864d5 36 DigitalIn bc_npg(PB_1); //Power to the charge controller. (BQ24100)[U23]
eawendtjr 0:62df2a5864d5 37 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 38
eawendtjr 0:62df2a5864d5 39 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 40 //Sensirion SDP3X(s)
eawendtjr 0:62df2a5864d5 41 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 42 DigitalIn SDP3Xflt(PC_0);
eawendtjr 0:62df2a5864d5 43 DigitalIn SDP3XAltflt(PB_7);
eawendtjr 0:62df2a5864d5 44
eawendtjr 0:62df2a5864d5 45 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 46 //Accelerometer and Magnometer
eawendtjr 0:62df2a5864d5 47 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 48 DigitalOut iNemoEnable(PA_1, 0);
eawendtjr 0:62df2a5864d5 49 DigitalIn iNemoReady(PB_0);
eawendtjr 0:62df2a5864d5 50 DigitalIn iNemoInt1(PC_5);
eawendtjr 0:62df2a5864d5 51 DigitalIn iNemoInt2(PC_6);
eawendtjr 0:62df2a5864d5 52 DigitalIn iNemoInt3(PC_7);
eawendtjr 0:62df2a5864d5 53
eawendtjr 0:62df2a5864d5 54 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 55 //UV and Visible Light Sensor
eawendtjr 0:62df2a5864d5 56 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 57
eawendtjr 0:62df2a5864d5 58 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 59 //GPS
eawendtjr 0:62df2a5864d5 60 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 61 DigitalOut gpsEN(PB_15, 0);
eawendtjr 0:62df2a5864d5 62 DigitalIn gpsENFault(PB_12);
eawendtjr 0:62df2a5864d5 63
eawendtjr 0:62df2a5864d5 64
eawendtjr 0:62df2a5864d5 65 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 66 //SD Card
eawendtjr 0:62df2a5864d5 67 /////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 68 DigitalIn sdCD(PA_11);
eawendtjr 0:62df2a5864d5 69 DigitalOut sdClk(PB_3,0 );
eawendtjr 0:62df2a5864d5 70 DigitalIn sdMISO(PB_4);
eawendtjr 0:62df2a5864d5 71 DigitalOut sdMOSI(PB_5, 0);
eawendtjr 0:62df2a5864d5 72 DigitalOut sdCS(PB_6, 1);
eawendtjr 0:62df2a5864d5 73
eawendtjr 0:62df2a5864d5 74 DigitalIn pbIso(PA_0);
eawendtjr 0:62df2a5864d5 75 DigitalOut hFault1(PA_7, 0);
eawendtjr 0:62df2a5864d5 76 DigitalOut hFault2(PA_6, 0);
eawendtjr 0:62df2a5864d5 77 DigitalOut hFault3(PA_5, 0);
eawendtjr 0:62df2a5864d5 78 DigitalOut hFault4(PA_4, 0);
eawendtjr 0:62df2a5864d5 79
eawendtjr 0:62df2a5864d5 80 DigitalOut wifiNReset(PC_1, 0);
eawendtjr 0:62df2a5864d5 81 DigitalOut wifiEnable(PC_2, 0);
eawendtjr 0:62df2a5864d5 82 DigitalOut qdEnable(PC_3, 0);
eawendtjr 0:62df2a5864d5 83 DigitalIn qdFault(PC_13);
eawendtjr 0:62df2a5864d5 84
eawendtjr 0:62df2a5864d5 85 ESP8266_AT esp(PC_10, PC_11);
eawendtjr 0:62df2a5864d5 86
eawendtjr 0:62df2a5864d5 87 // For selecting the WiFi UART
eawendtjr 0:62df2a5864d5 88 const int addr = 0x3F << 1;
eawendtjr 0:62df2a5864d5 89 char aod_sel_5on[1];
eawendtjr 0:62df2a5864d5 90 char aod_sel_5off[1];
eawendtjr 0:62df2a5864d5 91 char plant_sel[1];
eawendtjr 0:62df2a5864d5 92
eawendtjr 0:62df2a5864d5 93 //////////////////////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 94 //Main Function
eawendtjr 0:62df2a5864d5 95 //////////////////////////////////////////////////////////////
eawendtjr 0:62df2a5864d5 96 int main()
eawendtjr 0:62df2a5864d5 97 {
eawendtjr 0:62df2a5864d5 98 pc.baud(115200);
eawendtjr 0:62df2a5864d5 99 RGB_LED.set_led(0.5, 0, 1);
eawendtjr 0:62df2a5864d5 100
eawendtjr 0:62df2a5864d5 101 aod_sel_5on[0] = 0xCB;
eawendtjr 0:62df2a5864d5 102 aod_sel_5off[0] = 0xC9;
eawendtjr 0:62df2a5864d5 103 plant_sel[0] = 0xCF;
eawendtjr 0:62df2a5864d5 104
eawendtjr 0:62df2a5864d5 105 wait(15);
eawendtjr 0:62df2a5864d5 106 pc.printf("Plantower on\r\n");
eawendtjr 0:62df2a5864d5 107
eawendtjr 0:62df2a5864d5 108 RGB_LED.set_led(1, 0, 1);
eawendtjr 0:62df2a5864d5 109 wait(15);
eawendtjr 0:62df2a5864d5 110 i2c.write(addr, aod_sel_5off, 1);
eawendtjr 0:62df2a5864d5 111 pc.printf("Plantower off\r\n");
eawendtjr 0:62df2a5864d5 112
eawendtjr 0:62df2a5864d5 113 RGB_LED.set_led(1, 0, 0);
eawendtjr 0:62df2a5864d5 114 wait(15);
eawendtjr 0:62df2a5864d5 115 i2c.write(addr, aod_sel_5on, 1);
eawendtjr 0:62df2a5864d5 116 pc.printf("Plantower off - 5V on\r\n");
eawendtjr 0:62df2a5864d5 117
eawendtjr 0:62df2a5864d5 118 RGB_LED.set_led(0, 0, 1);
eawendtjr 0:62df2a5864d5 119 wait(15);
eawendtjr 0:62df2a5864d5 120 i2c.write(addr, plant_sel, 1);
eawendtjr 0:62df2a5864d5 121 pc.printf("Plantower on\r\n");
eawendtjr 0:62df2a5864d5 122
eawendtjr 0:62df2a5864d5 123 RGB_LED.set_led(0, 1, 0);
eawendtjr 0:62df2a5864d5 124 wait(15);
eawendtjr 0:62df2a5864d5 125 i2c.write(addr, aod_sel_5off, 1);
eawendtjr 0:62df2a5864d5 126 pc.printf("Plantower off\r\n");
eawendtjr 0:62df2a5864d5 127
eawendtjr 0:62df2a5864d5 128 wait(15);
eawendtjr 0:62df2a5864d5 129
eawendtjr 0:62df2a5864d5 130 RGB_LED.set_led(0, 1, 1); // Light LED so we know something is happening
eawendtjr 0:62df2a5864d5 131 wifiEnable = 1; // Enable power to the WiFi while in reset, and wait a short while
eawendtjr 0:62df2a5864d5 132 wait_ms(100);
eawendtjr 0:62df2a5864d5 133 wifiNReset = 1; // Now de-assert the reset signal
eawendtjr 0:62df2a5864d5 134 RGB_LED.set_led(1, 1, 0); // Color change of LED to indicate something is happening.
eawendtjr 0:62df2a5864d5 135 wait(1);
eawendtjr 0:62df2a5864d5 136
eawendtjr 0:62df2a5864d5 137 while(1)
eawendtjr 0:62df2a5864d5 138 {
eawendtjr 0:62df2a5864d5 139 RGB_LED.set_led(1, 1, 1);
eawendtjr 0:62df2a5864d5 140 esp.check_esp();
eawendtjr 0:62df2a5864d5 141 wait(1);
eawendtjr 0:62df2a5864d5 142 RGB_LED.set_led(0, 1, 0);
eawendtjr 0:62df2a5864d5 143 wait(1);
eawendtjr 0:62df2a5864d5 144 }
eawendtjr 0:62df2a5864d5 145 }