View Single Post
Old Oct 07, 2012, 02:17 AM
schumixmd is offline
Find More Posts by schumixmd
schumixmd's Avatar
Moldova
Joined Jun 2010
2,053 Posts
here is my code for altimeter v4, but I'm using it with another library, not standard wire library


#define SENSOR_ADDRESS 0xEC
#include <Wire.h>
#include <I2cMaster.h>
TwiMaster ALTIMETER_SENSOR(true);// Defining sensor object

long altimeter_update(void){
static struct {
union {int16_t val; uint8_t raw[2]; } alt16; // 16-bit altitude from ALT-V4
} altv4;
long alt;

if(ALTIMETER_SENSOR.start(SENSOR_ADDRESS | I2C_WRITE))
{
delay(10);
ALTIMETER_SENSOR.write(0x07);
delay(10);
ALTIMETER_SENSOR.stop();
}

if(ALTIMETER_SENSOR.restart(SENSOR_ADDRESS | I2C_READ))
{
delay(10);
altv4.alt16.raw[0]=ALTIMETER_SENSOR.read(false);
delay(10);
altv4.alt16.raw[1]=ALTIMETER_SENSOR.read(true);
delay(10);
ALTIMETER_SENSOR.stop();
}

alt=altv4.alt16.val;
alt=alt-3000; //Substract 3000decimeters
alt=alt*10; //Convert decimeters to centimeters
return alt; //return altitude in centimeters
}


in main loop you just call altimeter_update() function. (altitude = altimeter_update()
schumixmd is offline Find More Posts by schumixmd
Reply With Quote