Permalink
Browse files

Added ID check to begin()

  • Loading branch information...
1 parent f9119a8 commit f4f02f46ebc588c8da4356902804ab166622903f @ladyada ladyada committed Sep 17, 2012
Showing with 8 additions and 3 deletions.
  1. +3 −1 Adafruit_BMP085.cpp
  2. +1 −1 Adafruit_BMP085.h
  3. +4 −1 examples/BMP085test/BMP085test.pde
View
@@ -21,13 +21,15 @@ Adafruit_BMP085::Adafruit_BMP085() {
}
-void Adafruit_BMP085::begin(uint8_t mode) {
+boolean Adafruit_BMP085::begin(uint8_t mode) {
if (mode > BMP085_ULTRAHIGHRES)
mode = BMP085_ULTRAHIGHRES;
oversampling = mode;
Wire.begin();
+ if (read8(0xD0) != 0x55) return false;
+
/* read calibration data */
ac1 = read16(BMP085_CAL_AC1);
ac2 = read16(BMP085_CAL_AC2);
View
@@ -51,7 +51,7 @@
class Adafruit_BMP085 {
public:
Adafruit_BMP085();
- void begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
+ boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
float readTemperature(void);
int32_t readPressure(void);
float readAltitude(float sealevelPressure = 101325); // std atmosphere
@@ -28,7 +28,10 @@ Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
- bmp.begin();
+ if (!bmp.begin()) {
+ Serial.println("Could not find a valid BMP085 sensor, check wiring!");
+ while (1) {}
+ }
}
void loop() {

0 comments on commit f4f02f4

Please sign in to comment.