Go Down

Topic: i2c Pressure Sensor (Read 26833 times) previous topic - next topic


By how much do the altitude readings vary? If the readings are within 10 meters or so of your actual altitude then the sensor is probably working.


I found in the intertet these altitudes for my city: 2160, 2135,2220.

but, the values of HP03d changes every reading, here is the txt for the readings:

pressure is in hPA, right??


yess, pressure is in hPa

The altitude variations are higher then they should be but still close enough to the expected readings to indicate that the sensor is probably working.

Do you have a decoupling capacitor on the 3.3v line? How long are the wires connecting the sensor?

Perhaps post a photo of you layout.


These are the pictures of my circuit:

these are  readings (today):

Altitud must be the same almost always?? because today changes a lot from yesterday.


Jul 16, 2009, 10:50 pm Last Edit: Jul 16, 2009, 10:53 pm by mem Reason: 1
altitud must be the same almost always?? because today changes a lot from yesterday.

I think your wiring is sort enough not to be causing a problem. It may be worth experimenting to see if its any more stable if you keep the circuit as far from your computer as possible

If you are saying that the readings are more stable then yesterday, I agree.

I wonder if you should try smoothing the output. You should be able to find code in the playground the will provide an moving average.

It would also be interesting to note the atmospheric pressure in your location and see if the readings track the changes in pressure.


ok, it´s possible change pin 11 to another that not interfere with SPI communication??

I`ll use the ethernet shield, but this communicates with pins (10,11,12,13), right?


Jul 17, 2009, 09:32 am Last Edit: Jul 17, 2009, 09:37 am by mem Reason: 1
The HP03 needs a 32kHz signal and this is provided by the FrequencyTimer2 library. FrequencyTimer2 uses hardware PWM to create the signal and this is hard wired in the controller chip to pin 11. If you want to free up pin 11 then you need to provide another source for the 32kHz signal.

One way of doing that is to use a timer chip like the 555. There are lots of resources on the web for this part (google 555), here is one: http://www.doctronics.co.uk/555.htm  the circuit you want is called an astable (multivibrator)

To free up pin 11 you need to turn off FrequencyTimer2. In the HP03 library source file you comment out these lines as follows in the begin method:
Code: [Select]

 /* 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();


Jul 17, 2009, 03:15 pm Last Edit: Jul 17, 2009, 03:16 pm by mem Reason: 1
For  anyone looking to use the HP03 code posted earlier in this thread,  here is a new test sketch that displays the various values from the sensor. It includes a function to smooth the altitude readings. I found that individual readings could vary by plus/minus four or five meters. Smoothing the data drops the deviation down to plus/minus a meter or so.  

Code: [Select]
// HP03 example sketch
// prints the temperature, presssure and altitude to the serial port
// also shows the maximum deviation in feet from the average altitude
// Created 17 July 2009

#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

const int numReadings = 12;    // the number of readings to smooth
                             // with HP03 conversion rate of 85ms, 12 readings takes one second
long count = 0;               // the number of readings taken

long minA = 9999999;          // used to show how much the altitude deviates
long maxA = 0;
long deviation;    
void setup()
 Serial.begin(9600);  // start serial for output  
 if(HP03.begin() == false)
   Serial.println("Error getting HP03 calibration, check sensor connection");    

void loop()
 if(HP03.update() == false)
   Serial.println("Error getting HP03 data, check sensor connection");

void showReadings()
   Serial.print("Temp ");
   Serial.print(" Pressure ");
   HP03.distanceUnits = METERS;
   Serial.print("   Altitude: Meters = ");
   Serial.print(HP03.getAltitude(HP03.Pressure)/ 10);
   HP03.distanceUnits = FEET;
   Serial.print(", Feet  = ");
   long feet = HP03.getAltitude(HP03.Pressure);
   feet = smooth(feet);
   if(count >= numReadings)
     Serial.print(" smoothed = ");
     if(feet < minA) minA = feet;
     if(feet > maxA) maxA = feet;          
     Serial.print(", deviation = ");
     Serial.print( (maxA-minA) /2 );      

long smooth(long value)
static int index = 0;
static long readings[numReadings]  ;
static boolean isPrimed = false;   // set to true when at least numReadings have been received
static long total = 0;

  total = total - readings[index];    // remove the oldest value
  readings[index] = value;            // store the new value
  total= total + readings[index];     // add the reading to the total:    
  index = index + 1;                  // advance to the next position in the array:    
  // if we're at the end of the array...
  if (index >= numReadings)          // check if this is the end of the array    
     index = 0;                      // and wrap to the beginning if so    
     isPrimed  = true;               // enough readings received for average
     return total / numReadings;  
    return value; // return the raw value if not enough samples received;  


With 555, whats the minimum/highest  duty cycle, or it doesn´t matter?

I compiled your new sketch, but i have these errrors. Thanks.

In function 'void showReadings()':
error: call of overloaded 'print(double)' is ambiguousC:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:37: note: candidates are: void Print::print(char)

C:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:39: note:                 void Print::print(uint8_t)

C:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:40: note:                 void Print::print(int)

C:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:41: note:                 void Print::print(unsigned int)

C:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:42: note:                 void Print::print(long int)

C:\Documents and Settings\12ic412d06\Escritorio\arduino-0012\hardware\cores\arduino/Print.h:43: note:                 void Print::print(long unsigned int)


Jul 17, 2009, 08:17 pm Last Edit: Jul 17, 2009, 08:18 pm by mem Reason: 1
It uses floating point support in the serial code. As I recall this was introduced in version 0013. Looks like you are using version 0012.

If you change 10.0 to 10 and 100.0 to 100 it should compile in 0012 but you will lose the values after the decimal point.

Why not upgrade to a later version?

I don't know if the duty cycle matters. See how close you can get to 50% and see if it works.


Hi, i  compare my readings whith DAVIS weather station, and i'm 8-11 hpa under the DAVIS, and that´s  much. Datasheet HP03d says that pressure accuracy is about plus/minus 1hpa.

Some idea about what´s happening?

Temperature Readings are OK comparated with DAVIS and SHT15.



Are you at exactly the same altitude as that station, 8-11 hpa lower would be perhaps a hundred meters higher.

Also, the spec may be for the relative accuracy (after calibration).  You can calibrate the values by adding (subtracting) a constant to the readings.


yes, DAVIS and HP03d(with metoerological shelter ) are togheter. the problem if i add a constant,  it isn´t lineal. sometimes the difference is 8.XX and sometimes is 11.XX mb. thanks.


Have you tried measuring at significantly different altitudes? Is the variation still +-1.5 hpa or does the error increase or decrease at different altitudes.


Mar 14, 2010, 03:08 am Last Edit: Mar 14, 2010, 03:17 am by nscadarduino Reason: 1
I've had mixed results so far with the HP03. I develop using a netbook running Ubuntu Linux, and was not able to fix compiling errors using version 0018. I tried installing 0011 and 0012 but they would not run (I guess this is a limitation of the OS--I'm a Mac guy without a lot of experience with Linux).

Next I switched to Mac OSX Leopard and loaded 0012. With the adjustments to wiring.h as described earlier in this thread, I was able to get the data stream in the serial monitor. According to Google Earth I'm located at 77m but the HP03 says I'm -44m, and although Environment Canada gives the pressure at 1031, the HP03 says it's 1018.

I'm interested in the barometric pressure delta so absolutes are not necessary, but it is troubling that I can't get accuracy as close as is claimed by the datasheet.

Later on in this thread mem offers another sketch, which I loaded and tried to run with 0012 but had similar compile errors to ricarDOGS. mem suggests upgrading to 0013. Has anyone had success using this library with the most recent distribution 0018?

Go Up