First publish Luci

Dependencies:   Adafruit_RTCLib SoftI2C SoftSerial mbed

Files at this revision

API Documentation at this revision

Comitter:
arsenalist
Date:
Sun Nov 12 23:52:50 2017 +0000
Parent:
1:6cbf32f31179
Commit message:
Latest Luci commit

Changed in this revision

Adafruit_RTCLib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Adafruit_RTCLib.lib	Thu Jun 08 15:26:56 2017 +0000
+++ b/Adafruit_RTCLib.lib	Sun Nov 12 23:52:50 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/nkhorman/code/Adafruit_RTCLib/#f372b273d88f
+https://os.mbed.com/users/arsenalist/code/Adafruit_RTCLib/#f372b273d88f
--- a/main.cpp	Thu Jun 08 15:26:56 2017 +0000
+++ b/main.cpp	Sun Nov 12 23:52:50 2017 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "SoftSerial.h"
+//#include "SoftSerial.h"
 //#include "SoftI2C.h"
 //#include "DS1307.h"
 
@@ -11,7 +11,7 @@
 Serial DBG(PA_9, PA_10);    //tx, rx
 
 //Init xbee
-SoftSerial XB(PC_0, PC_1);       //tx, rx
+Serial XB(PC_10, PC_11);    //tx, rx
 
 //Init rtc
 //I2C         luciI2C (PB_7,PB_6);    //sda, scl
@@ -19,27 +19,32 @@
 //RtcDs1307   luciRTC(luciI2C);
 
 //Init adc
-AnalogIn anVP(PA_1);
-AnalogIn anIP(PA_0);
+AnalogIn anVP(PA_0);
+AnalogIn anIP(PA_3);
 AnalogIn anVL(PA_2);
-AnalogIn anIL(PA_3);
+AnalogIn anIL(PA_1);
 AnalogIn anVB(PB_1);
 AnalogIn anIB(PB_0);
 AnalogIn anTE(PC_2);
 
+//Init switch control
+DigitalOut PB12(PB_12);
+
 //Declared unused adc as digital out
 //PA0 used      //PA1 used
 //PA2 used      //PA3 used
 //PA4 UN        //PA5 SPI UN
 //PA6 SPI UN    //PA7 SPI UN
 //PB0 used      //PB1 used
-//PC0 Ser used  //PC1 Ser used
-//PC2 UN        //PC3 UN
+//PC0 UN        //PC1 UN
+//PC2 Temp UN   //PC3 UN
 //PC4 UN        //PC5 UN
 DigitalOut PA4(PA_4);
 DigitalOut PA5(PA_5);
 DigitalOut PA6(PA_6);
 DigitalOut PA7(PA_7);
+DigitalOut PC0(PC_0);
+DigitalOut PC1(PC_1);
 DigitalOut PC2(PC_2);
 DigitalOut PC3(PC_3);
 DigitalOut PC4(PC_4);
@@ -75,7 +80,11 @@
 float currentCalculate(float adcVal, int type) {
     float res = 0;
     
-    adcVal = adcVal - 0.510980;  //Remove offset
+    if(type == typeIP || type == typeIB) {
+        adcVal = adcVal - 0.510980;  //Remove offset
+    } else {
+        adcVal = adcVal - 0.491730; //Remove offset for IL    
+    }
     if(-0.0025 < adcVal && adcVal < 0.0025) { //No current
         res = 0;
     } else {
@@ -84,8 +93,6 @@
     
     if(type == typeIP) {
         if(res < 0) res = 0;    
-    } else if(type == typeIL) {
-        res = -1*res;    
     }
     return res;
 }
@@ -126,15 +133,20 @@
     //DBG.printf("compiled %s %s\r\n",__DATE__,__TIME__);
     //DBG.printf("rtc clock is %s\r\n", (luciRTC.isRunning() ? "running" : "halted"));
     
+    //Set switch control always on
+    PB12.write(1);
+    
     PA4.write(0);
     PA5.write(0);
     PA6.write(0);
     PA7.write(0);
+    PC0.write(0);
+    PC1.write(0);
     PC2.write(0);
     PC3.write(0);
     PC4.write(0);
     PC5.write(0);
-    
+        
     while(1){
         //Read sensor
         valVP = 0;
@@ -146,14 +158,22 @@
         valTE = 0;
         
         //Read sensor
-        valVP = adcRead(anVP)*52.8;
-        valVL = adcRead(anVL)*52.8;
-        valVB = adcRead(anVB)*52.8;
+        valVP = adcRead(anVP)*48.21;
+        valVL = adcRead(anVL)*48.21;
+        valVB = adcRead(anVB)*48.21;
         valIP = currentCalculate(adcRead(anIP),typeIP);
         valIL = currentCalculate(adcRead(anIL),typeIL);
         valIB = currentCalculate(adcRead(anIB),typeIB);
         valTE = adcRead(anTE);
         
+        //valVP = adcRead(anVP)*52.8;
+        //valVL = adcRead(anVL)*52.8;
+        //valVB = adcRead(anVB)*52.8;
+        //valIP = currentCalculate(adcRead(anIP),typeIP);
+        //valIL = currentCalculate(adcRead(anIL),typeIL);
+        //valIB = currentCalculate(adcRead(anIB),typeIB);
+        //valTE = adcRead(anTE);
+        
         //Read time
         //dt = luciRTC.now();
         //DBG.printf("%02u%02u%02u %02u:%02u:%02u\r\n"
@@ -164,11 +184,11 @@
         //,i,dt.year(),dt.month(),dt.day(),dt.hour(),dt.minute(),dt.second(),valVP,valIP,valVL,valIL,valVB,valIB,valTE);
         //XB.printf("{DT=\"%02u%02u%02u %02u:%02u:%02u\",VP=%.1f,IP=%.1f,VL=%.1f,IL=%.1f,VB=%.1f,IB=%.1f,TE=%.1f}"
         //,dt.year(),dt.month(),dt.day(),dt.hour(),dt.minute(),dt.second(),valVP,valIP,valVL,valIL,valVB,valIB,valTE);
-        DBG.printf("[%d]{DT=\"YYYYMMDD HH:MM:SS\",VP=%.1f,IP=%.1f,VL=%.1f,IL=%.1f,VB=%.1f,IB=%.1f,TE=%.1f}\r\n"
+        DBG.printf("[%d]{DT=\"YYYYMMDD HH:MM:SS\",VP=%.5f,IP=%.5f,VL=%.5f,IL=%.5f,VB=%.5f,IB=%.5f,TE=%.5f}\r\n"
         ,i,valVP,valIP,valVL,valIL,valVB,valIB,valTE);
         XB.printf("{DT=\"YYYYMMDD HH:MM:SS\",VP=%.1f,IP=%.1f,VL=%.1f,IL=%.1f,VB=%.1f,IB=%.1f,TE=%.1f}"
         ,valVP,valIP,valVL,valIL,valVB,valIB,valTE);
-        wait(60);
+        wait(30);
         i++;
     }    
 }
\ No newline at end of file