Pages: 1 [2] 3 4 ... 7   Go Down
Author Topic: i2c Pressure Sensor  (Read 9925 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
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:
Code:
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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Modifying the library to support the hp02 is certainly possible if you are comfortable coding the math needed for the calculations.

But integrating the hp03 is not difficult if your controller board has a 3.3 volt supply (or you can use a couple of diodes to drop the 5 volts line). You can do the logic level conversion with a couple of FETs and a six resistors.

Which is easier depends on whether you are more comfortable working in software or hardware.

Have fun!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I went ahead yesterday and updated the library. so far no cigar.  Arduino shoots back to the serial port some garbled symbols. Even the normal text sent from the sketch is not recognizable. I wen back to the original library and I see the same thing. Some how the serial communication is not working properly even with the sensor disconnected. I wonder it this has something to do with the fact I am using IDE 15 and Atmega 328. Your thoughts?
« Last Edit: June 10, 2009, 12:20:45 pm by nikivan » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The example sketch posted earlier in this thread uses 19200 baud, have you set that rate in the serial monitor?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hm, no, I did not. But I can execute other sketches using this bit rate without any problem.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hm, no, I did not. But I can execute other sketches using this bit rate without any problem.
I am not sure what you are saying. My question was about ensuring the baud rate on the serial monitor viewing the serial data matches the 19200 baud being sent. If the anwswer is no then that is why you are seeing gibberish characters.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I'll check again when I get home. In the mean time I was looking at the sensor spreadsheet and I could not figure out where the following values are coming from:

#define HP03_I2C_SENSOR_ADDRESS 0x77
#define HP03_I2C_CALIBRATION_ADDRESS 0x50

Why 0x77 and 0x50?

Also, I assume the following code refers to PB4(MISO) and PB5(SCK) atmega pins:

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

PB5 (17) on Atmega 328 in Arduino Pro Mini is connected to the green LED via 330 om resistor. I am not getting a good square signal there, so I am using PB3 (pin 15) instead.
 
In this regards, it would be nice if you could provide the pin connections, as you have them in your setup (Atmega -> HP03)?

Thanks again for your help.

Nick


« Last Edit: June 10, 2009, 07:07:31 pm by nikivan » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino I2C wire library requires that you divide the datasheet address by 2. The HP03 sensor address is 0xEE, which is 0x77 after dividing by 2. See the wire library reference page here: http://www.arduino.cc/en/Reference/Wire

I have not used a Pro Mini, but according to the reference page:  “The Pro Mini has 6 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values). Four of them are on the headers on the edge of the board; two (inputs 4 and 5) on holes in the interior of the board. “

MCLK_pin is analog pin 4  
XCLR_pin  is analog pin 5

So the sensor connects to analog pins 4 and 5. Although you don't need the following information, you may be interested in knowing that analog pin 4 is also digital pin 16,  this is physical port PC4 on the controllers chips physical pin numbered 27.
« Last Edit: June 10, 2009, 11:31:19 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, this is getting confusing. The analog input 4 and 5 are also marked as SDA and SCL. I thought I need to connect there SDA and SCLK pins from the sensor. If you are saying I need to connect MCLK to analog 4 and XCLR to analog 5, then where the SDA and SCLK go to?

BTW, the serial communication is working now. I found I need to press the reset button, after I start the monitor. Sure enough, the message is 'Error getting HP03 data'. Not surprising, considering the mess with the pins assigment.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The comment in that code is confusing ( I even forgot what I meant by it)

I2C uses analog pins 4 and 5:
SDA (data line) is on analog input pin 4
SCL (clock line) is on analog input pin 5.

MCLK is on analog pin 2 (the code uses it as digital pin  16)
XCLR is  on analog pin 3 (used as digital pin 17)

I hope that helps with the connections.

BTW, I think the wire library may have been modified slightly since I last ran this code so you if you still get errors, you  may need to fiddle with the wire error return codes.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, mem.

In the sketch, there is a comment:

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

I understand that means MCLK should be connected to digital pin 11 (PB3,  MOSI), but your last comment puts it to analog pin 2 (PC2, ADC2). Which one is the correct assigment?
Logged

Pages: 1 [2] 3 4 ... 7   Go Up
Jump to: