Bulme lib for temp sensor LM75B

Dependents:   mbed-os-example-wifi-ThingSpeak mbed_freeRTOS_send STM_Statemachine

Files at this revision

API Documentation at this revision

Comitter:
bulmecisco
Date:
Mon Mar 14 13:23:07 2016 +0000
Commit message:
Bulme Lib for temp sensor LM75B;

Changed in this revision

LM75B.cpp Show annotated file Show diff for this revision Revisions of this file
LM75B.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 29546bb2c7dd LM75B.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.cpp	Mon Mar 14 13:23:07 2016 +0000
@@ -0,0 +1,19 @@
+#include "LM75B.h"
+
+LM75B :: LM75B(PinName sda, PinName scl) : i2c(sda, scl)
+{
+    cmd[0] = LM75B_CONF;            // Pointerregister
+    cmd[1] = 0x0;                   // Default siehe 7.4.2 Tabelle 8
+    i2c.write(LM75B_ADDR, cmd, 2);  // Adr., char *, Länge   
+}
+
+float LM75B :: read()
+{
+    cmd[0] = LM75B_TEMP;
+    
+    i2c.write(LM75B_ADDR, cmd, 1);  // sende Temperatur Befehl
+    i2c.read(LM75B_ADDR, cmd, 2);   // bekommmen den command string
+    return (float ((cmd[0] << 8) | cmd[1])/256.0);    
+}
+
+LM75B :: ~LM75B() {}
diff -r 000000000000 -r 29546bb2c7dd LM75B.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.h	Mon Mar 14 13:23:07 2016 +0000
@@ -0,0 +1,24 @@
+#ifndef LM75B_H
+#define LM75B_H
+
+#include "mbed.h"
+
+// LM75B Adresse
+#define LM75B_ADDR 0x90
+
+// LM75B Register
+#define LM75B_CONF 0x01
+#define LM75B_TEMP 0x00
+
+class LM75B
+{
+public:
+  LM75B(PinName sda, PinName scl);  // I2C Pins übergeben p28, p27
+  ~LM75B();
+  float read(); 
+  
+private:
+  char cmd[2];
+  I2C i2c;
+};
+#endif
\ No newline at end of file