i2c Pressure Sensor

Hi

Firstly thanks for the great forums have learned so much already. I am working with the HP03 pressure sensor and not having much luck with reading anything off it. Here is the data sheet for it.

http://www.oceancontrols.com.au/Sensors/pressure/HP03.pdf

I have read threw the i2c playground and several other example and they seem to have only confused me more. I would like to know if anyone has an example for reading from this actual device or might be able to point me in the right direction.

Any help you can give me would be greatly appreciated.

Here is a library I use for the HP03 pressure sensor. This code works for me but has only been run with a modified wire library on Arduino version 0011. It should be ok with the standard 0012 wire library, but not yet tested.
test sketch:

// HP03 test sketch
// Created 11 July 2008

#include <HP03.h>
#include <FrequencyTimer2.h>
#include <Wire.h>

// note that the HP03 code uses digital pin 11 for the clock and analog pins 4 and 5 for I2C

unsigned long start; 
  
void setup()
{ 
  Serial.begin(19200);  // start serial for output  
  if(HP03.begin() == false)
    Serial.println("Error getting HP03 calibration, check sensor connection");

  for(long p = 1100; p >=310; p-= 50){
    Serial.print("pressure ");
    Serial.println(p,DEC); 
    HP03.distanceUnits = METERS;
    Serial.print("   Altitude, Meters = ");
    printFloat( HP03.getAltitude(p * 100L) /10.0, 1); 
    Serial.println();
    HP03.distanceUnits = FEET;
    Serial.print("   Altitude, Feet  = ");
    printFloat( HP03.getAltitude(p * 100L), 2);
    Serial.println();
    
  }
  start = millis();
  HP03.distanceUnits = METERS;
}



void loop()
{    
  if(HP03.update() == false)
    Serial.println("Error getting HP03 data, check sensor connection");
  else {  
    int dur = millis() - start;  // calculate conversion time
    output('T', HP03.Temperature/10.0, 1);  
    output('P', HP03.Pressure/100.0, 2);  
    output('A', HP03.getAltitude(HP03.Pressure)/10.0, 1); 
    output('C',dur,0); // conversion time in ms
  }
   start = millis();  
}

void output( char tag, float value, int decimalPlaces){
//send the value to the serial port with the given tag, format using given number of decimal places
  Serial.print('>');   // this is our message start indicater
  Serial.print(tag);
  Serial.print('=');
  printFloat(value,decimalPlaces);
  Serial.println();
}

void printFloat( float val, byte decimalPlaces){
// prints val with the given number of decimal places
unsigned int precision;
  Serial.print( (long)val );  //prints the integer part
  if(decimalPlaces != 0){
    Serial.print("."); // print the decimal point
    for(precision=1; decimalPlaces--; precision *= 10)
        ;
    unsigned int frac;
    if(val >= 0)
        frac = (val - int(val)) * precision;
    else
        frac = (int(val)- val ) * precision;
    Serial.print(frac,DEC) ;
  }
}

HP03.h header file to go into the library directory

/*
  HP03.h - Arduino library support for HP03 Pressure sensor
  Copyright (c)2008 Michael Margolis All right reserved

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

  Version:   1.0 - July14 2008
  
*/

#ifndef      HP03_H
#define HP03_H

typedef unsigned char boolean;

/*
  define some constants for errors based on the return values
  of the functions in utility/twi.c
*/ 
#define WIRE_OK 0
#define WIRE_ERR_NO_BUFFER_SPACE 1
#define WIRE_ERR_BAD_ADDRESS 2
#define WIRE_ERR_NOT_IN_TRNSMISSION_MODE 2
#define WIRE_ERR_DATA_NO_ACK 3
#define WIRE_ERR_BUS 4

typedef enum distanceUnits_t {METERS, FEET};

class HP03class  // shell class for HP03 glcd code
{
  private:
     // methods to send and receive data via I2C 
     int i2cTransfer(unsigned char Address, const unsigned char *TxBuf, int TxBytes, unsigned char *RxBuf, int RxBytes);
     int i2cSendCommand(unsigned char Address, unsigned char Command);
     int i2cMeasure(unsigned char SubType);
     int i2cResult(unsigned int *Result);
  public:
    HP03class();
      float Temperature;
    float Pressure;
    long   Altitude;
      unsigned int rawPressure;     // D1 - raw values are only for test purposes
    unsigned int rawTemperature;  // D2  
    distanceUnits_t distanceUnits;   // METERS or FEET
    boolean begin( void );
    boolean getCalibrationData();
#ifdef PRINT_CALIBRATION_DATA
    void HPO3class::printCalibrationData();
#endif
    boolean update();
    boolean readRawData();
    void calculatePressureAndTemperature(); 
    long getAltitude(long pressure);  //pressure is 100 times what it should be
};

extern HP03class HP03;    
#endif

The cpp file is in the next post

/*
  HP03.cpp - Arduino library support for HP03 Pressure sensor
Copyright (c)2008 Michael Margolis All right reserved

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  Version:   1.0 - July14 2008
*/

// Note that this code uses the return values in Arduino version 0012 wire.c library


extern "C" {
#include <avr/pgmspace.h>
#include <wiring.h>
#include <FrequencyTimer2.h>
#include <Wire.h>
}
#include "HP03.h"

#if !defined(NULL)
#define NULL 0
#endif

// #define PRINT_CALIBRATION_DATA  //undefine these to print low level data for debug purposes

// I2C defines
#define MCLK_pin 16   // Arduino uses analog pins 4 and 5 for I2C
#define XCLR_pin 17

#define HP03_I2C_SENSOR_ADDRESS 0x77
#define HP03_I2C_CALIBRATION_ADDRESS 0x50
#define HP03_MEASURE_COMMAND     0xff
#define HP03_RESULT_COMMAND      0xfd
#define HP03_PRESSURE_SUBTYPE    0xf0
#define HP03_TEMPERATURE_SUBTYPE 0xe8
#define HP03_RESULT_SUBTYPE      0xef

// macro to convert two bytes in an arrya to an int
#define GET_BIGENDIAN_WORD(x, y) ((((unsigned int)x[y]) << 8) | x[y+1]) 

// Pressure to altitude conversion defines
#define MAX_PRESSURE         1100L  // in Hpa
#define PRESSURE_ARRAY_ELEMS 80     // number of elements in pressure array
#define PRESSURE_INC         10L    // 10Hpa between array values in altitude table

#define HP03_NUM_COEFF 7
#define HP03_NUM_PARAMS 4

enum coefficients { C1,C2,C3,C4,C5,C6,C7};
enum params       { AA,BB,CC,DD};

unsigned int coeff[HP03_NUM_COEFF];  // these are marked C1 through C7 in the datasheet
byte  sensorParams[HP03_NUM_PARAMS];  // these are marked a,b,c,d in the datasheet 

long int pow2(byte value){ // return value raised to the power of 2    
  long uiData = 2;  
  while(--value){ 
    uiData <<= 1;         
  } 
  return uiData; 
}

//********* I2C functions ******************
int HP03class::i2cTransfer(unsigned char Address, const unsigned char *TxBuf, int TxBytes, unsigned char *RxBuf, int RxBytes){
  // send bytes to the given address and receive bytes from that address 
  int ret = WIRE_OK;    

  if(TxBytes > 0){    // send data if TxBytes greater than 0
    if(TxBytes > BUFFER_LENGTH)
      ret = WIRE_ERR_NO_BUFFER_SPACE ;
    else{      
      Wire.beginTransmission(Address); // transmit to device             
      while(TxBytes--){  
        Wire.send(*TxBuf++);         
      }
      ret = Wire.endTransmission();    // stop transmitting       
    }
  }
  if (RxBytes > 0 && ret == WIRE_OK){  // receive given number of byts if send ok 
    Wire.requestFrom(Address, (uint8_t)RxBytes);
    while(Wire.available() && RxBytes--)
    { 
      char c = Wire.receive();
      *RxBuf++ = c;
    }        
  }   
  return ret;
}

int HP03class::i2cSendCommand(unsigned char Address, unsigned char Command){
  Wire.beginTransmission(Address); // transmit to device  
  Wire.send(Command);            
  return Wire.endTransmission();    // stop transmitting   
}

int HP03class::i2cMeasure(unsigned char SubType){
//   Start a measurement on the HP03, returns WIRE_OK on success else WIRE error code
  unsigned char TxBuf[2];

  TxBuf[0] = HP03_MEASURE_COMMAND;
  TxBuf[1] = SubType;

  return i2cTransfer(HP03_I2C_SENSOR_ADDRESS, TxBuf, sizeof(TxBuf), NULL, 0);
} 

int HP03class::i2cResult(unsigned int *Result){
//   Get a measurement result from the HP03, returns WIRE_OK on success else WIRE error code
  unsigned char TxBuf[2];
  unsigned char RxBuf[2];
  int Status;

  TxBuf[0] = HP03_RESULT_COMMAND;
  TxBuf[1] = HP03_RESULT_SUBTYPE;

  Status = i2cTransfer(HP03_I2C_SENSOR_ADDRESS, TxBuf, sizeof(TxBuf), RxBuf, sizeof(RxBuf));

  *Result = (RxBuf[0] << 8) | RxBuf[1];

  return Status;
} 

  HP03class::HP03class(){
  }

boolean HP03class::begin( void ){
  // set control pins for output
  pinMode(MCLK_pin, OUTPUT);
  pinMode(XCLR_pin, OUTPUT);    
  digitalWrite(XCLR_pin,LOW) ;
  
  /* set up TIMER2 to 32768Hz with 50/50 mark/space ration with output on  */
  pinMode(11,OUTPUT);  // frequencyTimer2 is hard coded to output on this pin
  FrequencyTimer2::setPeriod(31); // 31us = 32258hz
  FrequencyTimer2::enable();
  Wire.begin();
  return getCalibrationData();  // returns true if ok, if false then probably sensor not detected
}

boolean HP03class::getCalibrationData(){
  // read the calibration values from the sensor, return true if ok, false if error  
  unsigned char CalData[18];
  boolean ret;
 
  ret = (i2cSendCommand(HP03_I2C_CALIBRATION_ADDRESS, 16) == WIRE_OK);
  if (ret == true){
    if(i2cTransfer(HP03_I2C_CALIBRATION_ADDRESS, NULL, 0, CalData, sizeof(CalData)) == WIRE_OK) {
      for (int i = 0; i < HP03_NUM_COEFF; i++)    
        coeff[i] = GET_BIGENDIAN_WORD(CalData, i*2); 

      for (int i = 0; i < HP03_NUM_PARAMS; i++)  
        sensorParams[i] = CalData[( HP03_NUM_COEFF * sizeof(int)) + i];
      ret = true; 
    }
  }
#ifdef PRINT_CALIBRATION_DATA
   printCalibrationData();
#endif   
  return ret;
}
#ifdef PRINT_CALIBRATION_DATA
void HP03class::printCalibrationData(){
  int Count;
  for (Count = 0; Count < HP03_NUM_COEFF; Count++)  {   
    Serial.print("Coeff C");
    Serial.print((char)('1' + Count));
    Serial.print(" = ");
    Serial.println((unsigned long)coeff[Count],DEC);
  }
  for (Count = 0; Count < HP03_NUM_PARAMS; Count++)  {
    Serial.print("Param");
    Serial.print((char)('A' + Count));
    Serial.print(" = ");
    Serial.println( (unsigned)sensorParams[Count],DEC);
  }
  Serial.println();
}
#endif

boolean HP03class::update(){
   if(readRawData()){
      calculatePressureAndTemperature();
      return true;   
   }  
   return false;
}

boolean HP03class::readRawData(){
  digitalWrite(XCLR_pin,HIGH);
  // send temperature measurement command 
  if ( i2cMeasure(HP03_TEMPERATURE_SUBTYPE) != WIRE_OK) {
    digitalWrite(XCLR_pin,LOW);
    return false; 
  }
  delay(40);
  if( i2cResult(&rawTemperature) != WIRE_OK){
    digitalWrite(XCLR_pin,LOW);
    return false;
  }
  if (i2cMeasure(HP03_PRESSURE_SUBTYPE) != WIRE_OK) {
    digitalWrite(XCLR_pin,LOW);
    return false;
  }
  delay(40);
  if( i2cResult(&rawPressure) != WIRE_OK){
     digitalWrite(XCLR_pin,LOW);
     return false;
  }
  return true;  
}

void HP03class::calculatePressureAndTemperature(){ 
  double MiddleData1;
  double MiddleData2; 
  double MiddleData3; 
  double MiddleData4;
  double dUT;
  double SENS;
  double OFF;
  double X;
       
  MiddleData1 = (long)rawTemperature - coeff[C5]; 
  MiddleData2 = MiddleData1 * MiddleData1/16384;
  if(rawTemperature < coeff[C5])  
     MiddleData3 = MiddleData2 * sensorParams[BB]; 
  else 
     MiddleData3 = MiddleData2 * sensorParams[AA];
  MiddleData4 = pow2(sensorParams[CC]); 
  MiddleData4 = MiddleData3 / MiddleData4;
  dUT = MiddleData1 - MiddleData4; 

  //OFF = (C2+(C4-1024)*DUT/Get2_x(14))*4;
  MiddleData1 = (long)coeff[C4] - 1024L; 
  MiddleData2 = pow2(14);
  MiddleData3 = dUT * MiddleData1;
  MiddleData4 = MiddleData3 / MiddleData2;
  MiddleData4 = (long)coeff[C2] + MiddleData4; 
  OFF = MiddleData4 * 4; 

  //SENS = C1+C3*DUT/Get2
  MiddleData1 = (long)coeff[C3] * dUT; 
  MiddleData2 = pow2(10);
  MiddleData3 = MiddleData1 / MiddleData2;
  SENS = coeff[C1] + MiddleData3; 

  //X = SENS*(D1-7168)/ Get2_x(14)-OFF;
  MiddleData1 = pow2(14); 
  MiddleData2 = (long)rawPressure - 7168;
  MiddleData3 = MiddleData2 * SENS;
  MiddleData4 = MiddleData3 / MiddleData1;
  X = MiddleData4 - OFF;   

   //Pressure = X*100/Get2_x(5)+C7*10; 
  MiddleData1 = X * 100; 
  MiddleData2 = pow2(5);
  MiddleData3 = MiddleData1 / MiddleData2;
  MiddleData4 = coeff[C7] * 10; 
  Pressure = MiddleData3 + MiddleData4;

  Temperature = 250 + dUT * coeff[C6] / pow2(16) - dUT / pow2(sensorParams[DD]); 
}

static prog_int32_t BasicAltitude[PRESSURE_ARRAY_ELEMS] PROGMEM = {
-6983,-6201,-5413,-4620,-3820,-3015,-2203,-1385,-560, 270, //0.1m
  1108, 1953, 2805, 3664, 4224, 5403, 6284, 7172, 8068, 8972,
  9885, 10805,11734,12671,13617,14572,15537,16510,17494,18486, 
  19489,20502,21526,22560,23605,24662,25730,26809,27901,29005, 
  30121,31251,32394,33551,34721,35906,37106,38322,39553,40800, 
  42060,43345,44644,45961,47296,48652,50027,51423,52841,54281, 
  55744,57231,58742,60280,61844,63436,65056,66707,68390,70105, 
  71854,73639,75461,77323,79226,81172,83164,85204,87294,89438};

long altitudeValue_P(int address){
// return the value of the altitude table 
  return pgm_read_dword(&BasicAltitude[address]  ); 
}

long  HP03class::getAltitude(long pressure){  //pressure is 100 times what it should be
   int index;
   long AltitudeDifference,PressureDifference;
   long fraction;
   long alt;

   index = (MAX_PRESSURE - pressure/100) / PRESSURE_INC + 1;
   if (index >= PRESSURE_ARRAY_ELEMS)
        index = PRESSURE_ARRAY_ELEMS-1;

   AltitudeDifference =  altitudeValue_P(index) - altitudeValue_P(index-1);
   PressureDifference = pressure - ((MAX_PRESSURE - (index* PRESSURE_INC))*100);
   fraction = (AltitudeDifference *1000) - (PressureDifference  * AltitudeDifference)    ;
   alt = ((altitudeValue_P(index-1) * 10)  + (fraction/100))/10;
   if(distanceUnits == METERS)
       return alt;
    else
       return  (long)(alt * 0.328084);
}
HP03class HP03 = HP03class();

Thanks so much for the info. I have put all the libraries etc in but am getting some errors when trying to compile.

In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:4,


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected identifier before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected `)' before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected ',' or '...' before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected initializer before ')' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared


In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:6,

I have confirmed that other programs are compiling ok so could this be something to do with the mod wire library you where talking about ?. It is prb just something I have done wrong when copying it over but it is strange as it does not seem to be referring to any of the new includes.

P.s Im still very new at all this :wink:

hmm, to test I copied the files posted back onto my computer and they compile ok for me. Are you using the test sketch I posted? Are HP03.h and HP03.cpp copied to a directory called HP03 in the hardware/libraries directory? (Note there are three files named HP03.pde, HP03.H and the third needs to be called HP03.cpp)

Mem, I haven't tried this code, but these are exactly the types of errors (stdlib.h:80) that people get when compiling old libraries with 0012. My guess is that it works for you because you disabled or undefined those pesky "function-style" cast macros in wiring.h"? If so, perhaps you'd care to share your method?

Mikal

Thanks Mikal, I had forgotten that I had removed those pesky macros in my working copy of wiring,h.

#ifdef USE_PESKY_MACROS
#define int(x) ((int)(x))
#define char(x) ((char)(x))
#define long(x) ((long)(x))
#define byte(x) ((uint8_t)(x))
#define float(x) ((float)(x))
#endif

Right-o! maca, if you follow mem's example and add the #ifdef/#endif to your copy of wiring.h (effectively removing the five #defines in between), you will probably get happiness.

Mikal

Strange thing is that I just tried re-compiling the code I posted and even with the macros enabled it compiled ok. hmm?

Thanks for all your help so far guys, I have entered the info listed below and it has def reduced the amount of errors but still will not compile. Now it says

In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:4,


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:6,

Any ideas on this one ?

Thanks

Yeah, also remove the #define of abs() in wiring.h.

Mikal

Well spotted Mikal, I do have that commented out as well !

Did you mean to remove this

#define abs(x) ((x)>0?(x):-(x))

When I remove that I get

In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:6,


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

down to 3 errors :stuck_out_tongue:

remove this:

#define round(x) ((x)>=0?(long)((x)+0.5) (long)((x)-0.5))

(although it compiles ok on my system as is)

duh forgot to bring xclear high, Working perfectly now got lost of lovely data coming threw and looks like rain is on the way :P.

Thanks so much for your help both of you have been a wealth of information. Also do you have any idea how accurate these things are in the real world the temp and pressure are spot on but the altitude is out by about 450m or so, but I guess pressure i Probly not the best way to measure altitude.

Because the pressure is varying with atmospheric conditions, you need to set an offset in the pressure value to correct it to a known altitude (or exact pressure). I may add that function to the library, but for now you will need to do it in your sketch.

I think my sensor was accurate to around 5 or 10 meters, but its been a while since I designed and tested the library so have forgotten that exact figure.

If you do some tests please do report on your results. I hope you enjoy using the library as much as I enjoyed writing that code.

First, thanks so much for all the great information!

I'm using the HP01D and I had the exact same experience as maca_404 getting the code to compile.

I'm a bit new to the arduino though, and I'm not what it means to bring xclear high:

duh forgot to bring xclear high, Working perfectly now got lost of lovely data coming threw and looks like rain is on the way

Here is what I'm getting now, which I'm guessing is similar to what maca_404 got at first:

Error getting HP01D calibration, check sensor connection
pressure 1100
   Altitude, Meters = -698.2
   Altitude, Feet  = -2291.0
pressure 1050
   Altitude, Meters = -301.5
   Altitude, Feet  = -989.0
pressure 1000
   Altitude, Meters = 110.8
   Altitude, Feet  = 363.0
pressure 950
   Altitude, Meters = 540.2
   Altitude, Feet  = 1772.0
pressure 900
   Altitude, Meters = 988.5
   Altitude, Feet  = 3243.0
pressure 850
   Altitude, Meters = 1457.1
   Altitude, Feet  = 4780.0
pressure 800
   Altitude, Meters = 1948.9
   Altitude, Feet  = 6394.0
pressure 750
   Altitude, Meters = 2466.1
   Altitude, Feet  = 8091.0
pressure 700
   Altitude, Meters = 3012.1
   Altitude, Feet  = 9882.0
pressure 650
   Altitude, Meters = 3590.6
   Altitude, Feet  = 11780.0
pressure 600
   Altitude, Meters = 4206.0
   Altitude, Feet  = 13799.0
pressure 550
   Altitude, Meters = 4865.2
   Altitude, Feet  = 15961.0
pressure 500
   Altitude, Meters = 5574.3
   Altitude, Feet  = 18288.0
pressure 450
   Altitude, Meters = 6343.6
   Altitude, Feet  = 20812.0
pressure 400
   Altitude, Meters = 7185.3
   Altitude, Feet  = 23574.0
pressure 350
   Altitude, Meters = 8117.2
   Altitude, Feet  = 26631.0
Error getting HP01D data, check sensor connection
Error getting HP01D data, check sensor connection
Error getting HP01D data, check sensor connection
Error getting HP01D data, check sensor connection

If anyone can explain this to me, I'd greatly appreciate it!

mem, thank you for posting this library. I was able to compile the sketch under IDE 15 after fuddling with frequencytimer2 library. I have two questions though. I am using Arduino Pro Mini, which is 16MHz instead of 8MHz, and I was wondering if something needs to be changed to account for this. For example, will line 141 in HP03.cpp be still accurate?

FrequencyTimer2::setPeriod(31); // 31us = 32258hz

Also, I actually have HP02D sensor, which is very similar, but it works with 5V. When comparing the spreadsheets I can see some differences in how the pressure is calculated. Do you happen to have a library for the HP02 sensor as well?

Thanks,
Nick

Hi Nick, you should not need to change anything to use the code on 16MHz or 8MHz boards, although I have only tested on 16MHz boards. FrequencyTimer2 adjusts to a board specific clock value when it is compiled should produce the correct frequencies for your board.

I have not looked at the HP02D sensor but the HP03 code could be modified to use the calculations needed for that sensor. Unfortunately, its not an easy task and I don't have the time to do this, sorry. The HP03 costs less than $10 from Futurlec so the easiest thing may be to use that module instead of the HP02.

mem, thanks for the reply. I was trying to avoid using HP03, because it is 3V device. I am prototyping an altitude monitoring system for RC helicopter. I only have 5V rail available there and I am trying to keep the number of components to a minimum (I will need additional 3V regulator and logic level converter if HP03 is used).

Anyway, your library is very well commented, so I will try to make HP02 version. The differences I see so far are in the wait time between readings: 32ms vs 40ms, and in HP02 there are only 5 calibration constants to be read. I will post here if I run into trouble.

Do you know any other low-cost pressure sensor which is easy to integrate with Arduino?

Thanks,
Nick