HP03S ADC reading

tjetson

Senior Member
Hi there

I am using the HP03S sensor in a circuit for a weather station. I have read all of the calibration values successfully. My values are within the ranges specified by WestAust55's pdf on this matter. I am using his code to read the raw temperature and pressure readings now. I am having some trouble, however. Both values are identical, and neither of them make sense.
I am using this code on a 20X2 at 4Mhz and 3.101 volts:
Code:
#picaxe 20x2
setfreq m4

pwmout C.5, 30, 61

; I2C ADDRESSING
SYMBOL PRE = %10100000 ; HOPERF HP03 Pressure Sensor onboard EEPROM at hard address
SYMBOL PRS = %11101110 ; HOPERF HP03 Barometric Pressure sensor
;
; CONSTANTS
SYMBOL PreConst1 = 16 ; HP03 series module EEPROM location for 1st byte
SYMBOL PreConst2 = 24 ; HP03 series module EEPROM location for 10th byte
SYMBOL Preset = c.2 ; PICAXE output 6 is for the HOPERF HP03 Pressure Sensor Reset
;
; VARIABLE name definitions
SYMBOL Pressure = w4 ; w4 = b9:b8 for the HP03 pressure sensor
SYMBOL PLSB = b8 ; need to separately define the MSB and LSB as I2C can only handle bytes
SYMBOL PMSB = b9
SYMBOL Temperature = w5 ; w5 = b11:b10 for the HP03 temperature sensor
SYMBOL TLSB = b10 ; need to separately define the MSB and LSB as I2C can only handle bytes
SYMBOL TMSB = b11


Main:
;
; perform one data read sequence from the HP03 pressure sensor module - remember to discard the first set of data after power-up
;
HIGH Preset ; place the pressure sensor module into active mode
SLAVEi2c PRS, i2cslow, i2cbyte ; set up to write to and read from the Pressure Sensor
WRITEi2c ($FF,$F0)
PAUSE 50 ; must pause at least 40ms - give it a little more at 50ms
WRITEi2c ($FD,$FD)
READi2c (PMSB, PLSB) ; fetch the Pressure – as MSB and LSB
WRITEi2c ($FF,$D0)
PAUSE 50 ; must pause at least 40ms - give it a little more at 50ms
WRITEi2c ($FD)
READi2c (TMSB, TLSB) ; fetch the Temperature – as MSB and LSB
LOW Preset ; place the pressure sensor module into idle mode
sertxd (#Pressure, " ", #Temperature) ; LCD module is connected to PICAXE Output 1
PAUSE 10000 ; wait for 10 seconds before another set of reading
GOTO Main
The terminal shows "32358 32358". According to WestAust's pdfs, he got 27669 and 6516. As can be seen, I am using PWM in lieu of a crystal for the clock line.

I can think of two reasons for my readings.
1. Do I need any components on the PWM line, or should I plug it directly into the sensor (which I have done)?

2. The code appears to be reading the same location (0) twice and trying to get different readings from it (temp AND pressure). Am I correct?


What should I do?
 

westaust55

Moderator
Sorry for delay in responding. - been in a conference all day and will be again tomorrow. Only a few minutes break here before back for an evening session.

I spotted that there is a new datasheet out for 2010 (V1.3)
http://www.hoperf.com/upfile/HP03S.pdf
and seemingly/maybe some of the command data bytes have changes since I bought mine about a year ago.

in place of these lines:
Code:
WRITEi2c ($FF,$D0)
PAUSE 50 ; must pause at least 40ms - give it a little more at 50ms
WRITEi2c ($FD)
READi2c (TMSB, TLSB) ; fetch the Temperature – as MSB and LSB
try this:

Code:
WRITEi2c ($FF,[COLOR="red"]$E8[/COLOR])
PAUSE 50 ; must pause at least 40ms - give it a little more at 50ms
WRITEi2c ($FD)
READi2c (TMSB, TLSB) ; fetch the Temperature – as MSB and LSB
 

tjetson

Senior Member
Now I get:
32460 29680
as my values. They are different, at least. But I believe they are still wrong. Your values were a lot different than mine :(.
Thanks for the help so far.
 
Last edited:

tjetson

Senior Member
Now that I look at the datasheet, on the page where it talks about timing, it says to send these values (I have converted to hex too):
Code:
Pressure:     11101110[EE]  11111111[FF]  11110000[F0] [50ms] 11101110[EE] 11111101[FD]   11101111[EF]   msb lsb
Temperature:  11101110[EE]  11111111[FF]  11101000[E8] [50ms] 11101110[EE] 11111101[FD]   11101111[EF]   msb lsb
These values seem to be a little different than your values, WestAust. You appear to send FF, F0 and then pause. The datasheet says EE, FF, F0. Is the EE unnecessary? Also, after the pause, the datasheet says EE, then FD and EF. Your code seems to omit the EE and the EF.


EDIT: I played around with the values just now. I added all the missing EEs, and then the sensor returned 0 0. I removed them again and ran THAT code, and now it goes back to "32524 29650". So the EEs aren't the problem. PS I also added the EF at the end of the Temperature sequence listed above ---^.
 
Last edited:

tjetson

Senior Member
I still can't get the sensor to give me any readings similar to yours. Do you know the allowable range for these readings?
 

westaust55

Moderator
My earlier (not 2010) datasheet indicates:
C and D in the range 1 to 15
A and B in the range 1 to 63

D1 and D2 in the range 0 to 65535
 

tjetson

Senior Member
Yep, just checked new 2010 datasheet, same ranges. Using the values I got earlier, 32460 29680, I have calculated this:

Pressure 9965.192027
Temp 214.3370904

I did it in an Excel document. Do you know what it is I am doing wrong?
 

westaust55

Moderator
Your code seems correct but the 20X2 could be a lot faster than the 18X I was using even at 4MHz.


Try adding some delays into the code as:
Code:
      WRITEi2c ($FF,$F0)
      PAUSE 50					; must pause at least 40ms for analogue to digital conversion
      WRITEi2c ($FD)
[COLOR="Red"]PAUSE 10[/COLOR]
      READi2c  (PMSB, PLSB)			; fetch the Pressure MSB and LSB
      
      WRITEi2c ($FF,$E8)
      PAUSE 50					; must pause at least 40ms - here we give just a little more time
      WRITEi2c ($FD)
[COLOR="Red"]PAUSE 10[/COLOR]
      READi2c  (TMSB, TLSB)			; fetch the Temperature MSB and LSB
 

westaust55

Moderator
HP03S Barometirc Pressure Sensor

Sorry, connot spot any specific problem.
a bit of brain drain here after listening to technical papers for 2 days solid

Where did you buy the HP03S module?

I bought 2 from Futurlec and both working okay.
Bought a 3rd from MicroZed at the same time (back in 2009)
and sadly never got that one working (not a byte out of it).
 

tjetson

Senior Member
From Futurlec. I also got a HH10D at the same time and as far as I can tell that module works. I have got a few things from Futurlec before and all of them worked.

One more thing comes to mind. Is it possible I am writing to and reading from the wrong location? As no location is specified, I believe the Picaxe defaults to location 0. I didn't know MicroZed stocked this sensor. It looks like (at present at least) they only have the HH10D.

Thanks for all of your help in this matter :)

EDIT: Actually, another thing comes to mind. I will try to use my DS1307's output as the sensor's clock tomorrow and see if my results are any different.
 
Last edited:

ValueAdd

Senior Member
In you posting, believe the line

SYMBOL PRS = %11101110 ; HOPERF HP03 Barometric Pressure sensor

defines the sensor address, and the line

SLAVEi2c PRS, i2cslow, i2cbyte ; set up to write to and read from the Pressure Sensor

sets up that address for the writei2c and readi2c commands
 

westaust55

Moderator
Actually, another thing comes to mind. I will try to use my DS1307's output as the sensor's clock tomorrow and see if my results are any different.
Okay could try that in even though by the PE Wizard the numbers you have are correct for PICAXE at 4MHz to get a 32758kHz 50% clock pulse stream.

For the DS1307, change the cotrol register (Address $07) from the usual $10 to a value of $13

I was successfully using PWMout with an 18X but in the present configuration, my circuit also has the DS1307 RTC and I obtain the 32kHz signal from the RTC.

If you want a very quick and dirty test. remove the clock signal completely from the HP03S module, then the two values for pressure and temp should read zero (0).
 

tjetson

Senior Member
If you want a very quick and dirty test. remove the clock signal completely from the HP03S module, then the two values for pressure and temp should read zero (0).
Yep, both zero. I used the DS1307's freq out at 32k and got this:
Pressure: 0 Temperature: 0

Pressure: 0 Temperature: 0

Pressure: 32449 Temperature: 29608
The 0s were before I connected the clock. Also, wrt my post about location, I did mean location in memory, 0,1,2 etc rather than location on the i2c bus %11110000 etc.
 

westaust55

Moderator
Okay, no clock means the ADC sampling part is not workling and zero for both values is the expected result.

That suggests you are reading the right "registers".
Unfortunately I cannot identify what else could be causing the significant variant from actual data.
 
Top