Help with Adafruit Sensor

I'm hoping someone might point me in the right direction for me. I'm brand new at all of this stuff and I'm finally getting away from the prefab kit I bought.

I'm using an Adafruit BPAT sensor

to try and read temperature and pressure.

I'm using the Mega 2560 Arduino.

The code is pretty simple, I think....

#include "Wire.h"    // imports the wire library for talking over I2C 
#include "Adafruit_BMP085.h"  // import the Pressure Sensor Library
Adafruit_BMP085 mySensor;  // create sensor object called mySensor

float tempC;  // Variable for holding temp in C
float tempF;  // Variable for holding temp in F
float pressure; //Variable for holding pressure reading

void setup(){
Serial.begin(9600); //turn on serial monitor
mySensor.begin();   //initialize mySensor
}

void loop() {
tempC = mySensor.readTemperature(); //  Read Temperature
tempF = tempC*1.8 + 32.; // Convert degrees C to F
pressure=mySensor.readPressure(); //Read Pressure

Serial.print("The Temp is: "); //Print Your results
Serial.print(tempF);
Serial.println(" degrees F");
Serial.print("The Pressure is: ");
Serial.print(pressure);
Serial.println(" Pa.");
Serial.println("");
delay(250); //Pause between readings.
}

However, the results I get at all times is
The Pressure is: 234.00 Pa.
The Temperature is: 32.00 degrees F

Neither of these are correct :slight_smile:

I've looked at sensor stuff so much on the internet I'm completely confused if I'm doing this correct. OR.....is it possible I fried the sensors when I soldered the header pins on? Or am I just completely messed up in my code?

Thank you for any help.....

Russ

Have you tried this example from the Adafruit library?

#include <Wire.h>
#include <Adafruit_BMP085.h>

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

Adafruit_BMP085 bmp;
  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

    Serial.print("Pressure at sealevel (calculated) = ");
    Serial.print(bmp.readSealevelPressure());
    Serial.println(" Pa");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");
    
    Serial.println();
    delay(500);
}

I had not, but when I ran it I get the "Could not find a valid BMP085 sensor, check wiring!" message.

I connected the SCL to A5 and the SDA to A4.

Could the fact that I'm using a MPL3115A2 sensor and not a BMP085 sensor have anything to do with this failure?

I installed the Adafruit_MPL3115A2.h library and used their example code and still got the "no sensor" error.

Try running this I2C scanner, see if you get anything.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
 Wire.begin();

 Serial.begin(9600);
 while (!Serial);             // Leonardo: wait for serial monitor
 Serial.println("\nI2C Scanner");
}


void loop()
{
 byte error, address;
 int nDevices;

 Serial.println("Scanning...");

 nDevices = 0;
 for(address = 1; address < 127; address++ ) 
 {
   // The i2c_scanner uses the return value of
   // the Write.endTransmisstion to see if
   // a device did acknowledge to the address.
   Wire.beginTransmission(address);
   error = Wire.endTransmission();

   if (error == 0)
   {
     Serial.print("I2C device found at address 0x");
     if (address<16) 
       Serial.print("0");
     Serial.print(address,HEX);
     Serial.println("  !");

     nDevices++;
   }
   else if (error==4) 
   {
     Serial.print("Unknown error at address 0x");
     if (address<16) 
       Serial.print("0");
     Serial.println(address,HEX);
   }    
 }
 if (nDevices == 0)
   Serial.println("No I2C devices found\n");
 else
   Serial.println("done\n");

 delay(5000);           // wait 5 seconds for next scan
}

That chip's max Vdd is 3.6V, you aren't putting 5V on it, are you?

No, I have it plugged into the 3.3v.

When I run that code, I get the No I2C devices found.

Don't sound good, check your soldering with a magnifying glass, make sure there's no shorts between pins or lifted traces from overheating.

Yeah......

My first attempt at soldering, I'm assuming I screwed it up. Thank you very much for the testing code and the advice. I really appreciate it.

That 32F = 0C and indeed likely means your sensor is not found.

Make sure it's connected to I2C though level shifters - it may be killed by the 5V I2C lines.

Make sure those level shifters are connected properly (including Vcc both sides, GND at least one side) and are bidirectional.

However, you said you have the Adafruit version, which would mean you can directly connect it to the 5V as it has a regulator and level shifting goodness on board and all the above is moot.

Then, what's left is your wiring. Make sure all is connected the right way, and your I2C scanner should pick it up. Then ensure the correct I2C address is set in your code.