Created
March 8, 2013 12:24
-
-
Save akbsteam/5116125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include <SoftwareSerial.h> | |
| int tmp102Address = 0x48; | |
| SoftwareSerial bleShield(2, 3); | |
| long interval = 1000; | |
| void setup(){ | |
| Serial.begin(19200); | |
| bleShield.begin(19200); | |
| Wire.begin(); | |
| } | |
| void loop() | |
| { | |
| digitalWrite(13, HIGH); // set the LED on | |
| bleShield.print(temperatureString()); | |
| Serial.println(temperatureString()); | |
| delay(interval); // wait for 1 sec | |
| digitalWrite(13, LOW); // set the LED off | |
| } | |
| String temperatureString() | |
| { | |
| char temp[10]; | |
| float celsius = getTemperature(); | |
| dtostrf(celsius,2,2,temp); | |
| String tempAsString = String(temp); | |
| String s = "" + tempAsString + " C "; | |
| return s.substring(0,16); | |
| } | |
| float getTemperature(){ | |
| Wire.requestFrom(tmp102Address,2); | |
| byte MSB = Wire.read(); | |
| byte LSB = Wire.read(); | |
| //it's a 12bit int, using two's compliment for negative | |
| int TemperatureSum = ((MSB << 8) | LSB) >> 4; | |
| float celsius = TemperatureSum*0.0625; | |
| return celsius; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment