Test code to interface AOD UPAS with IoT provider.
Dependencies: ESP8266_AT NCP5623BMUTBG mbed ADS1115 AOD_Calculation BME280 PMS5003 SunPosition CAM_M8
main.cpp
- Committer:
- eawendtjr
- Date:
- 2017-11-21
- Revision:
- 0:62df2a5864d5
- Child:
- 1:702f144a88b2
File content as of revision 0:62df2a5864d5:
#include "mbed.h" #include "NCP5623BMUTBG.h" #include "ESP8266_AT.h" ///////////////////////////////////////////// //Define core buses and pin states. ///////////////////////////////////////////// I2C i2c(PB_9, PB_8);//(D14, D15); SDA,SCL Serial pc(USBTX, USBRX); DigitalOut pumps(PA_9, 0);//(D8, 0); DigitalOut pbKill(PC_12, 1); // Digital input pin that conncect to the LTC2950 battery charger used to shutdown the UPAS 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 NCP5623BMUTBG RGB_LED(PB_9, PB_8); //(D14, D15); ///////////////////////////////////////////// //RN4677 BT/BLE Module ///////////////////////////////////////////// Serial ble(PB_10, PB_11); DigitalOut bleRTS(PB_14, 0); DigitalOut bleCTS(PB_13, 0); DigitalOut BT_IRST(PC_8, 0); DigitalOut BT_SW(PA_12, 0); ///////////////////////////////////////////// //Analog to Digital Converter ///////////////////////////////////////////// DigitalIn ADS_ALRT(PA_10); //Connected but currently unused. (ADS1115) http://www.ti.com/lit/ds/symlink/ads1115.pdf ///////////////////////////////////////////// //Battery, Charger, & Supply Monitoring ///////////////////////////////////////////// DigitalIn LTCALT(PB_2); //High for normal operation. Low when a threshold is exceeded for Voltage, gas gauge, or temp DigitalIn bcs1(PC_9); //Batt charging if High. (BQ24100)[U23] DigitalIn bcs2(PA_8); //Charge complete if High. (BQ24100)[U23] DigitalIn bc_npg(PB_1); //Power to the charge controller. (BQ24100)[U23] DigitalIn SW3flt(PC_4); //When EN = 0 pin is HIGH, When EN = 1, LOW can be current limit, thermal limit, or UVLO. ///////////////////////////////////////////// //Sensirion SDP3X(s) ///////////////////////////////////////////// DigitalIn SDP3Xflt(PC_0); DigitalIn SDP3XAltflt(PB_7); ///////////////////////////////////////////// //Accelerometer and Magnometer ///////////////////////////////////////////// DigitalOut iNemoEnable(PA_1, 0); DigitalIn iNemoReady(PB_0); DigitalIn iNemoInt1(PC_5); DigitalIn iNemoInt2(PC_6); DigitalIn iNemoInt3(PC_7); ///////////////////////////////////////////// //UV and Visible Light Sensor ///////////////////////////////////////////// ///////////////////////////////////////////// //GPS ///////////////////////////////////////////// DigitalOut gpsEN(PB_15, 0); DigitalIn gpsENFault(PB_12); ///////////////////////////////////////////// //SD Card ///////////////////////////////////////////// DigitalIn sdCD(PA_11); DigitalOut sdClk(PB_3,0 ); DigitalIn sdMISO(PB_4); DigitalOut sdMOSI(PB_5, 0); DigitalOut sdCS(PB_6, 1); DigitalIn pbIso(PA_0); DigitalOut hFault1(PA_7, 0); DigitalOut hFault2(PA_6, 0); DigitalOut hFault3(PA_5, 0); DigitalOut hFault4(PA_4, 0); DigitalOut wifiNReset(PC_1, 0); DigitalOut wifiEnable(PC_2, 0); DigitalOut qdEnable(PC_3, 0); DigitalIn qdFault(PC_13); ESP8266_AT esp(PC_10, PC_11); // For selecting the WiFi UART const int addr = 0x3F << 1; char aod_sel_5on[1]; char aod_sel_5off[1]; char plant_sel[1]; ////////////////////////////////////////////////////////////// //Main Function ////////////////////////////////////////////////////////////// int main() { pc.baud(115200); RGB_LED.set_led(0.5, 0, 1); aod_sel_5on[0] = 0xCB; aod_sel_5off[0] = 0xC9; plant_sel[0] = 0xCF; wait(15); pc.printf("Plantower on\r\n"); RGB_LED.set_led(1, 0, 1); wait(15); i2c.write(addr, aod_sel_5off, 1); pc.printf("Plantower off\r\n"); RGB_LED.set_led(1, 0, 0); wait(15); i2c.write(addr, aod_sel_5on, 1); pc.printf("Plantower off - 5V on\r\n"); RGB_LED.set_led(0, 0, 1); wait(15); i2c.write(addr, plant_sel, 1); pc.printf("Plantower on\r\n"); RGB_LED.set_led(0, 1, 0); wait(15); i2c.write(addr, aod_sel_5off, 1); pc.printf("Plantower off\r\n"); wait(15); RGB_LED.set_led(0, 1, 1); // Light LED so we know something is happening wifiEnable = 1; // Enable power to the WiFi while in reset, and wait a short while wait_ms(100); wifiNReset = 1; // Now de-assert the reset signal RGB_LED.set_led(1, 1, 0); // Color change of LED to indicate something is happening. wait(1); while(1) { RGB_LED.set_led(1, 1, 1); esp.check_esp(); wait(1); RGB_LED.set_led(0, 1, 0); wait(1); } }