Dependencies:   ChaNFSSD mbed BMP085 SHT2x

Files at this revision

API Documentation at this revision

Comitter:
tosihisa
Date:
Mon Jan 23 15:04:58 2012 +0000
Parent:
1:83960ee4d9a2
Child:
3:844fbe607dae
Commit message:
ENV Logger v0.5

Changed in this revision

SHT25.cpp Show diff for this revision Revisions of this file
SHT25.h Show diff for this revision Revisions of this file
TextLCD.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SHT25.cpp	Fri Jan 13 10:15:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2011 Toshihisa T
- * Released under the MIT License: http://mbed.org/license/mit
- */
-
-#include "mbed.h"
-#include "SHT25.h"
-
-#define SHT25ADDR   (0x80)
-
-SHT25::SHT25(PinName p_sda, PinName p_scl) : i2c(p_sda, p_scl)
-{
-}
-
-void SHT25::SoftReset()
-{
-    //i2c.frequency(1*1000);
-
-    i2c.start();
-    i2c.write(SHT25ADDR);
-    i2c.write(0xFE);
-    i2c.stop();
-}
-
-float SHT25::get_temperature()
-{
-    char buf[3];
-    unsigned short res = 0;
-
-    //i2c.frequency(1*1000);
-
-    i2c.start();
-    i2c.write(SHT25ADDR);
-    i2c.write(0xE3);
-
-    i2c.start();
-    i2c.write(SHT25ADDR | 1);
-    wait(0.1);
-    buf[0] = i2c.read(1);
-    buf[1] = i2c.read(1);
-    buf[2] = i2c.read(0);
-    i2c.stop();
-
-    res = buf[0];
-    res = (res << 8) | buf[1];
-    res &= ~0x0003;
-
-    return -46.85 + 175.72 / 65536.0 * (float)res;
-}
--- a/SHT25.h	Fri Jan 13 10:15:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2011 Toshihisa T
- * Released under the MIT License: http://mbed.org/license/mit
- */
-
-#ifndef __SHT25_H  /* } */
-
-#include "mbed.h"
-
-class SHT25 : public Base {
-
-public:
-    SHT25(PinName p_sda, PinName p_scl);
-    float get_temperature();
-    void SoftReset();
-
-protected:
-    I2C i2c;
-};
-
-#endif  /* } */
--- a/TextLCD.lib	Fri Jan 13 10:15:08 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- a/main.cpp	Fri Jan 13 10:15:08 2012 +0000
+++ b/main.cpp	Mon Jan 23 15:04:58 2012 +0000
@@ -8,7 +8,6 @@
 #include "SDFileSystem.h"
 #include "libT/mbed/tserialbuffer.h"
 #include "BMP085.h"
-#include "SHT25.h"
 #include "SHT2x.h"
 #include "AD7994.h"
 //#include "TextLCD.h"
@@ -17,7 +16,7 @@
 
 using namespace libT;
 
-#define _CO2_TEST
+//#define _CO2_TEST
 //#define _I2C_TEST
 
 #define _USE_FS_NAME "sd"
@@ -34,7 +33,7 @@
 #endif  /* } */
 BMP085 bmp085(p9, p10);
 //SHT25 sht25(p9, p10);
-//SHT2x sht25(p9,p10);
+SHT2x sht25(p9,p10);
 AD7994 ad7994(p9,p10);
 TextLCD_20X4 lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
 
@@ -42,9 +41,7 @@
 
 DigitalOut myled(LED1);
 
-#ifdef  _CO2_TEST
 tSerialBuffer CO2(p13,p14);
-#endif
 
 struct UBXPacket_s UBXPacket;
 
@@ -84,7 +81,6 @@
     fclose(fp);
 }
 
-#ifdef  _CO2_TEST    /* { */
 int CO2_Read(unsigned short *val)
 {
     unsigned char sbuf[] = { 0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5 };
@@ -119,7 +115,6 @@
     *val = (*val << 8) | rbuf[4];
     return 0;
 }
-#endif  /* HAVE_CO2 } */
 
 // BMP085 0xee
 // AD9774 0x44
@@ -182,35 +177,39 @@
 }
 
 unsigned char wbuf[1024];
-int widx;
+int widx = 0;
 
 int main() {
     int ret = 0;
     float p, t;
     int temp;
-    int userRegister;
     unsigned short CO2_val;
     unsigned long scanCount = 0;
     FILE *fp;
     char *logname = "/" _USE_FS_NAME "/ENVLOG.TXT";
     char c;
+    unsigned long UBXCount = 0;
  
     debug.format(8,Serial::None,1);
     debug.baud(115200);
-    debug.printf("ENV Logger \"V1\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\n");
+    debug.printf("ENV Logger \"V0.5\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\n");
 
     debug.printf("LCD Display\n");
 
     //lcd.cls();
     lcd.locate(0,0);
-    lcd.printf("ENV Logger \"V1\"");
-#ifdef  _CO2_TEST
+    lcd.printf("ENV Logger \"V0.5\"");
+
+    lcd.locate(0,1);
+    lcd.printf("WAKE UP I/O...");
     wait(5.0);
-#endif
  
     //logFile_Init();
     //FileWriteTest();
 
+    lcd.locate(0,1);
+    lcd.printf("SETTING GPS...");
+
     UBXPacket.cjobst = 0;
 
     gps_pps.rise(gps_pps_rise);
@@ -221,7 +220,6 @@
     wait(0.5);
     gps_reset = 0;
 
-#if 0
     wait(0.5);
     if(1){
         //unsigned char modeStr[] = "PUBX,41,1,0007,0003,115200,0";
@@ -259,7 +257,8 @@
        }
     }
     UBXPacket.cjobst = 0;
-#endif
+    lcd.locate(0,1);
+    lcd.printf("SETTING GPS...Done.");
 
 #if 0
     debug.printf("open(%s) :", logname);
@@ -273,86 +272,67 @@
 
 //  ad7994.Start();
 
-#ifdef  _CO2_TEST
     CO2.format(8,Serial::None,1);
     CO2.baud(9600);
     CO2.recvStart();
-#endif
-
-    //sht25.SHT2x_SoftReset();
-    //sht25.SHT2x_ReadUserRegister(&userRegister);  //get actual user reg
-    //userRegister = (userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_12_14BIT;
-    //sht25.SHT2x_WriteUserRegister(&userRegister); //write changed user reg    
 
     while(1) {
         //lcd.cls();
-        lcd.locate(0,1);
-        lcd.printf("SCAN: %-10ld",scanCount);
+        //lcd.locate(0,0);
+        //lcd.printf("SCAN:%-10ld",scanCount);
 
-#if 0
         while(gps.readable()) {
             c = gps.getc();
             if(UBXPacket_Parse(&UBXPacket,c) == 100){
+                UBXCount++;
+                lcd.locate(0,0);
+                lcd.printf("UBX Recv:%-10ld",UBXCount);
                 debug.printf("%ld : GET UBX Packet (Class=0x%02X,ID=0x%02X,LEN=%d)\n",
                             scanCount,
                             UBXPacket.cls,
                             UBXPacket.id,
                             UBXPacket.len );
                 UBXPacket.cjobst = 0;
-                if(scanCount > 120){
-                    if(widx >= 0){
-                        fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
-                        widx = 0;
-                    }
-                    fclose(fp);
-                }
             }
-            if(fp != NULL){
-                wbuf[widx] = c;
-                widx++;
-                if(widx >= sizeof(wbuf)){
-                    fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
-                    widx = 0;
-                }
-            }
+            //if(fp != NULL){
+            //    wbuf[widx] = c;
+            //    widx++;
+            //    if(widx >= sizeof(wbuf)){
+            //        fwrite(&wbuf,sizeof(wbuf[0]),widx,fp);
+            //        widx = 0;
+            //    }
+            //}
         }
-#endif
 
-#if 0
-        bmp085.update();
-        p = bmp085.get_pressure();
-        t = bmp085.get_temperature();
-        lcd.locate(0,2);
-        lcd.printf("%-7.2fhPa %-7.2fC\n", p, t);
-#endif
+        if(1){
+            bmp085.update();
+            p = bmp085.get_pressure();
+            t = bmp085.get_temperature();
+            lcd.locate(0,1);
+            lcd.printf("%-8.2fhPa %-6.2fC", p, t);
+        }
 
-#if 0
-        sht25.SHT2x_MeasurePoll(TEMP,&temp);
-        p = sht25.SHT2x_CalcTemperatureC(temp);
-        sht25.SHT2x_MeasurePoll(HUMIDITY,&temp);
-        t = sht25.SHT2x_CalcRH(temp);
-        debug.printf("SHT25 = p:%6.2f C / t:%6.2f RH\n", p, t);
-        sht25.SHT2x_SoftReset();
-#endif
-
-#if 0
-        sht25.SoftReset();
-        printf("SHT25 = %f\n",sht25.get_temperature());
-#endif
+        if(1){
+            sht25.SHT2x_MeasurePoll(TEMP,&temp);
+            p = sht25.SHT2x_CalcTemperatureC(temp);
+            sht25.SHT2x_MeasurePoll(HUMIDITY,&temp);
+            t = sht25.SHT2x_CalcRH(temp);
+            lcd.locate(0,2);
+            lcd.printf("%-6.2fC %-6.2fRH", p, t);
+            //sht25.SHT2x_SoftReset();
+        }
 
 #ifdef _I2C_TEST /* { */
         i2c_found();
 #endif  /* } */
 
-#ifdef  _CO2_TEST
-        lcd.locate(0,2);
+        lcd.locate(0,3);
         ret = CO2_Read(&CO2_val);
         if(ret == 0){
-            lcd.printf("CO2:%5dppm\n",CO2_val);
+            lcd.printf("CO2:%5d.%1dppm\n",CO2_val/10,CO2_val%10);
         } else {
             lcd.printf("CO2:NG(%d)  \n",ret);
         }
-#endif
 
 #if 0
         ad7994.update();
@@ -370,3 +350,10 @@
         scanCount++;
     }
 }
+
+/*
+ * 2012-1-23 V0.5
+ * U-Blox,気圧センサー,温度センサー,CO2センサーの値を表示するようにした。
+ * U-Blox は受信できたパケット数を表示する。
+ * マイクロSDへの保存機能はまだ(H/W的に動くのは確認済み)
+ */