reading diff-pressure form OMRON D6F-PH0505

Files at this revision

API Documentation at this revision

Comitter:
Chillee
Date:
Sat Jun 27 10:17:59 2015 +0000
Commit message:
Diff-Pressure Sensor from OMRON

Changed in this revision

D6F-PH.cpp Show annotated file Show diff for this revision Revisions of this file
D6F-PH.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1d476876f987 D6F-PH.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/D6F-PH.cpp	Sat Jun 27 10:17:59 2015 +0000
@@ -0,0 +1,83 @@
+ #include "mbed.h"
+ #include "D6F-PH.h"
+
+ 
+ // Class constructor
+
+D6F_PH::D6F_PH(I2C *i2c) :
+_i2c(i2c){
+}
+
+
+float D6F_PH::read_pressure(void) {
+    char error;
+    char rdata[2];
+    uint16_t raw_diff_pa;
+    float diff_pa;
+    
+    error = _i2c->write(D6F_ADDR, d6f_config, 5);
+    wait_us(40000);
+    error |= _i2c->write(D6F_ADDR, d6f_comp_read, 4);
+    error |= _i2c->write(D6F_ADDR, d6f_mem_read, 1, true);
+    error |= _i2c->read(D6F_ADDR, rdata, 2);
+    if(error) {
+        return(error);
+    }
+    raw_diff_pa = (rdata[0]<<8) + rdata[1];
+    diff_pa = ((float)raw_diff_pa-1024)/600 - 50;    
+    return(diff_pa);   
+}
+
+
+float D6F_PH::read_d6f_temp(void) {
+    char error;
+    char rdata[2];
+    uint16_t raw_ref_temp;
+    float ref_temp;
+    
+    error = _i2c->write(D6F_ADDR, d6f_config, 5);
+    wait_us(40000);
+    error |= _i2c->write(D6F_ADDR, d6f_temp_read, 4);
+    error |= _i2c->write(D6F_ADDR, d6f_mem_read, 1, true);
+    error |= _i2c->read(D6F_ADDR, rdata, 2);
+    if(error) {
+        return(error);
+    }
+    raw_ref_temp = (rdata[0]<<8) + rdata[1];
+    ref_temp = ((float)raw_ref_temp-10214)/37.39;
+    return(ref_temp);   
+}
+
+uint8_t D6F_PH::init(void) {
+    uint8_t error;
+    
+    // Init config cmd
+    //d6f_config[5] = {0x00, 0xD0, 0x40, 0x18, 0x06};
+    d6f_config[0] = 0x00;
+    d6f_config[1] = 0xD0;
+    d6f_config[2] = 0x40;
+    d6f_config[3] = 0x18;
+    d6f_config[4] = 0x06;
+    
+    //d6f_comp_read[4] = {0x00, 0xD0, 0x51, 0x2C};
+    d6f_comp_read[0] = 0x00;
+    d6f_comp_read[1] = 0xD0;
+    d6f_comp_read[2] = 0x51;
+    d6f_comp_read[3] = 0x2C;
+    
+    //d6f_temp_read[4] = {0x00, 0xD0, 0x61, 0x2C};
+    d6f_temp_read[0] = 0x00;
+    d6f_temp_read[1] = 0xD0;
+    d6f_temp_read[2] = 0x61;
+    d6f_temp_read[3] = 0x2C;
+    
+    //d6f_mem_read[1] = {0x07};
+    d6f_mem_read[0] = 0x07;
+    
+    d6f_init[0] = 0x0B;
+    d6f_init[1] = 0x00;
+    error = _i2c->write(D6F_ADDR, d6f_init, 2);
+    
+    return(error);
+}
+
diff -r 000000000000 -r 1d476876f987 D6F-PH.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/D6F-PH.h	Sat Jun 27 10:17:59 2015 +0000
@@ -0,0 +1,53 @@
+#ifndef D6F_PH_H
+#define D6F_PH_H
+
+#define D6F_ADDR 0xD8
+
+class D6F_PH{
+    private:
+        I2C *_i2c;
+    
+        // D6F-PH function
+        char d6f_config[5];
+        char d6f_comp_read[4];
+        char d6f_temp_read[4];
+        char d6f_mem_read[1];
+        char d6f_init[2];
+         
+    public:
+        
+        /** Constructor - create a connection to a D6F-PH diff-pressure and reference temperature sensor
+          * through an I2C interface
+          *
+         * @param *i2c a pointer to the i2c interface that is used for communication
+         */             
+        D6F_PH(I2C *i2c);
+            
+        /** Read the diff-pressure value from the sensor \n
+         *
+         *
+         *
+         *
+         *
+         * @param returns a value representing the temperature in degrees centigrade
+         */
+        float read_pressure();
+    
+        /** Read the reference temperature value from the sensor \n
+         *
+         *
+         *
+         *
+         *
+         * @param returns the percentage humidity
+         */
+        float read_d6f_temp();
+    
+        /**
+         * Perform a soft-reset of the sensor unit.
+         */
+        uint8_t init();
+        
+};
+    
+#endif // D6FS_PH_H
\ No newline at end of file