You are on page 1of 6

#include <Wire.

h> (I2C communication: Arduino-PC )


#include <Adafruit_Sensor.h> (Open the library)
#include <Adafruit_BMP085_U.h>

/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor), which provides a
common 'type' for sensor data and some helper functions.
To use this driver you will also need to download the Adafruit_Sensor, library and include it in
your libraries folder.
You should also assign a unique ID to this sensor for use with the Adafruit Sensor API so that
you can identify this particular sensor in any data logs, etc. To assign a unique ID, simply
provide an appropriate value in the constructor below (12345 is used by default in this
example).
Connections
===========
Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground
. History
=======
2013/JUN/17 - Updated altitude calculations (KTOWN)
2013/FEB/13 - First version (KTOWN)
*/
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified (10085);

/**************************************************************************/
/*
Displays some basic information on this sensor from the unified sensor API sensor_t type
(see Adafruit_Sensor for more information)
*/
/**************************************************************************/

void displaySensorDetails(void)
{
sensor_t sensor(1); (sensor identification)
bmp.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor:

"); Serial.println(sensor.name);

Serial.print ("Driver Ver: "); Serial.println(sensor.version);


Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}

/**************************************************************************/
/*
Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void) (Preparar programa, dont return data)
{
Serial.begin(9600);
Serial.println("Pressure Sensor Test"); Serial.println("");

/* Initialise the sensor */


if(!bmp.begin()) (if dont receive information)
{

/* There was a problem detecting the BMP085 ... check your connections */
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
while(1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code should go here)
*/
/**************************************************************************/
void loop(void) (start)
{
/* Get a new sensor event */
sensors_event_t event; (take information of sensor)
bmp.getEvent(&event);

/* Display the results (barometric pressure is measure in hPa) */


if (event.pressure)
{
/* Display atmospheric pressue in hPa */
Serial.print("Pressure: ");
Serial.print(event.pressure);
Serial.println(" hPa");

/* Calculating altitude with reasonable accuracy requires pressure sea level pressure for your
position at the moment the data is converted, as well as the ambient temperature in degress
celcius. If you don't have these values, a 'generic' value of 1013.25 hPa can be used (defined as
SENSORS_PRESSURE_SEALEVELHPA in sensors.h), but this isn't ideal and will give variable
results from one day to the next.
* You can usually find the current SLP value by looking at weather websites or from
environmental information centers near any major airport.*

* For example, for Paris, France you can check the current mean. pressure and sea level at:
http://bit.ly/16Au8ol
/* First we get the current temperature from the BMP085 */
float temperature; (float is variable type to say which kind of data is saved)
bmp.getTemperature(&temperature);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
/* Then convert the atmospheric pressure, and SLP to altitude
/* Update this next line with the current SLP for better results
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
Serial.print("Altitude: ");
Serial.print(bmp.pressureToAltitude(seaLevelPressure,
event.pressure));
Serial.println(" m");
Serial.println("");
}
else
{
Serial.println("Sensor error");
}
delay(1000);
}

*/
*/

Codes
1.-Sensor_t
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a
specific sensor. */
typedef struct
{
char
name[12];
int32_t version;
int32_t sensor_id;
int32_t type;
float
max_value;
float
min_value;
float
resolution;
int32_t min_delay;
} sensor_t;

The individual fields are intended to be used as follows:

name: The sensor name or ID, up to a maximum of twelve characters (ex.


"MPL115A2")
version: The version of the sensor HW and the driver to allow us to differentiate
versions of the board or driver
sensor_id: A unique sensor identifier that is used to differentiate this specific
sensor instance from any others that are present on the system or in the sensor
network
type: The sensor type, based on sensors_type_t in sensors.h
max_value: The maximum value that this sensor can return (in the appropriate
SI unit)
min_value: The minimum value that this sensor can return (in the appropriate SI
unit)
resolution: The smallest difference between two values that this sensor can
report (in the appropriate SI unit)
min_delay: The minimum delay in microseconds between two sensor events, or
'0' if there is no constant sensor rate

2.- Sensor Data/Events (sensors_event_t)


/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in
a common format. */
typedef struct
{
int32_t version;
int32_t sensor_id;
int32_t type;
int32_t reserved0;
int32_t timestamp;
union
{
float
data[4];
sensors_vec_t
acceleration;
sensors_vec_t
magnetic;
sensors_vec_t
orientation;
sensors_vec_t
gyro;
float
temperature;
float
distance;
float
light;
float
pressure;
float
relative_humidity;
float
current;
float
voltage;
sensors_color_t color;
};
} sensors_event_t;

It includes the following fields:

version: Contain 'sizeof(sensors_event_t)' to identify which version of the API


we're using in case this changes in the future
sensor_id: A unique sensor identifier that is used to differentiate this specific
sensor instance from any others that are present on the system or in the sensor
network (must match the sensor_id value in the corresponding sensor_t enum
above!)
type: the sensor type, based on sensors_type_t in sensors.h
timestamp: time in milliseconds when the sensor value was read
data[4]: An array of four 32-bit values that allows us to encapsulate any type of
sensor data via a simple union (further described below)

You might also like