Student project, pay no heed.

Dependencies:   MLX90614 RPCInterface adc mbed

Fork of IR_temperature by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
villeah
Date:
Thu Jan 09 06:59:47 2014 +0000
Parent:
0:bbaf949d2a27
Commit message:
Ihan kakka.

Changed in this revision

RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
adc.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
main2.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bbaf949d2a27 -r 9cd48cdf8681 RPCInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Thu Jan 09 06:59:47 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/RPCInterface/#682c65afe534
diff -r bbaf949d2a27 -r 9cd48cdf8681 adc.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/adc.lib	Thu Jan 09 06:59:47 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/flash_ahaa/code/adc/#b05e4f5e2c8c
diff -r bbaf949d2a27 -r 9cd48cdf8681 main.cpp
--- a/main.cpp	Tue Feb 21 01:47:13 2012 +0000
+++ b/main.cpp	Thu Jan 09 06:59:47 2014 +0000
@@ -1,26 +0,0 @@
-#include "mbed.h"
-#include "mlx90614.h"
-
-DigitalOut myled(LED1); //displays I2C wait
-I2C i2c(p28,p27);   //sda,scl
-Serial pc(USBTX,USBRX);  //serial usb config
-
-MLX90614 IR_thermometer(&i2c);
-//setup an MLX90614 using MLX90614 library from
-// http://mbed.org/users/aquahika/libraries/MLX90614/lsixz6
-
-float temp; //temperature in degrees C
-
-int main() {
-    while (1) {
-        myled=1; // if led1 on - waiting on I2C
-        if (IR_thermometer.getTemp(&temp)) {
-            //gets temperature from sensor via I2C bus
-            myled=0;
-            //print temperature on PC
-            printf("Temperature is %5.1F degrees C\r\n",temp);
-        }
-        //wait for device to produce next temperature reading
-        wait(0.5);
-    }
-}
diff -r bbaf949d2a27 -r 9cd48cdf8681 main2.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main2.cpp	Thu Jan 09 06:59:47 2014 +0000
@@ -0,0 +1,91 @@
+#include "mbed.h"
+#include "mlx90614.h"
+#include "rpc.h"
+#include "adc.h"
+#include "SerialRPCInterface.h"
+
+#define SAMPLE_RATE    150000
+
+
+ADC adc(SAMPLE_RATE, 1);
+// the default address of the infrared sensor (7 bit address + 1 bit for read/write, 0xB4 for write)
+char i2caddress = 0xB4; 
+
+AnalogIn ain(p20); //adc from pin 20
+DigitalOut myled(LED1); //displays I2C wait
+I2C i2c(p28,p27);   //sda,scl
+SerialRPCInterface RPC(USBTX, USBRX); 
+
+bool getTemp(float* temp_val){
+
+    char p1,p2,p3;
+    float temp_thermo;
+    bool ch;
+
+    i2c.stop();                            //stop i2c if not ack
+    wait(0.01);
+    i2c.start();                           //start I2C                   
+    ch=i2c.write(i2caddress);              //device address with write condition
+    
+    if(!ch){
+        return false;
+    }                                        //No Ack, return False
+    
+    ch=i2c.write(0x07);                    //device ram address where Tobj value is present
+
+    if(!ch){
+        return false;
+    }
+
+    i2c.start();                           //repeat start
+    ch=i2c.write(i2caddress|0x01);         //device address with read condition 
+    if(!ch){
+        return false;
+    }
+
+    p1=i2c.read(1);     //Tobj low byte
+    p2=i2c.read(1);     //Tobj heigh byte
+    p3=i2c.read(0);     //PEC
+    
+    i2c.stop();                            //stop condition
+     
+    
+    temp_thermo=((((p2&0x007f)<<8)+p1)*0.02)-0.01;      //degree centigrate conversion
+    *temp_val=temp_thermo-273;                          //Convert kelvin to degree Celsius
+    
+    return true;                            //load data successfully, return true 
+}
+
+
+float IRTemp = 0; //temperature in degrees C
+float AnalogTemp;
+float IRTempTemp;
+
+void anaali(char* input, char* output);
+void digit(char* input, char* output);
+
+RPCFunction rpc_anal(&anaali, "rpc_anal");
+RPCFunction rpc_digi(&digit, "rpc_digi");
+
+           
+int main() {
+
+    wait(1);
+    while (1) {
+        myled=1;
+        if (getTemp(&IRTempTemp)) {
+            myled=0;
+        }
+        wait(0.5);
+        if(IRTempTemp < 150) //discard clearly wrong values from trying to read the sensor when it's not ready
+            IRTemp = IRTempTemp;
+    }
+}
+
+void anaali(char* input, char* output){ 
+    sprintf(output, "%f", (float)ain); //prints the analog sensor value to the output stream
+}
+
+void digit(char* input, char* output){
+    sprintf(output, "%f", IRTemp); //prints the digital sensor value to the output stream
+}
\ No newline at end of file