Advertisement
Erfinator

TMP006 code, error

Jan 4th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. /***************************************************
  2. This is an example for the TMP006 Barometric Pressure & Temp Sensor
  3.  
  4. Designed specifically to work with the Adafruit TMP006 Breakout
  5. ----> https://www.adafruit.com/products/1296
  6.  
  7. These displays use I2C to communicate, 2 pins are required to
  8. interface
  9. Adafruit invests time and resources providing this open source code,
  10. please support Adafruit and open-source hardware by purchasing
  11. products from Adafruit!
  12.  
  13. Written by Limor Fried/Ladyada for Adafruit Industries.
  14. BSD license, all text above must be included in any redistribution
  15. ****************************************************/
  16.  
  17. #include <Wire.h>
  18. #include "Adafruit_TMP006.h"
  19.  
  20. // Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
  21. // Gnd -> Gnd
  22. // SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
  23. // otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
  24. // SDA connects to the I2C data pin. On newer boards this is labeled with SDA
  25. // otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2
  26.  
  27. Adafruit_TMP006 tmp006;
  28. //Adafruit_TMP006 tmp006(0x41); // start with a diferent i2c address!
  29.  
  30. void setup() {
  31. Serial.begin(9600);
  32. Serial.println("Adafruit TMP006 example");
  33.  
  34. // you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
  35. // lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
  36. // 4 seconds per reading (16 samples)
  37. if (! tmp006.begin()) {
  38. Serial.println("No sensor found");
  39. while (1);
  40. }
  41.  
  42. Serial.println("Send s to enter sleep mode, or w to wake up. Measurements are not updated while asleep!");
  43. }
  44.  
  45. void loop() {
  46. // Check for sleep/wake command.
  47. while (Serial.available() > 0) {
  48. char c = Serial.read();
  49. if (c == 'w') {
  50. Serial.println("Waking up!");
  51. tmp006.wake();
  52. }
  53. else if (c == 's') {
  54. Serial.println("Going to sleep!");
  55. tmp006.sleep();
  56. }
  57. }
  58.  
  59. // Grab temperature measurements and print them.
  60. float objt = tmp006.readObjTempC();
  61. Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*C");
  62. float diet = tmp006.readDieTempC();
  63. Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*C");
  64.  
  65. delay(4000); // 4 seconds per reading for 16 samples per reading
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement