VARIOMETER using GY63/MS5611 barometer

hippy

Technical Support
Staff member
#81
I attach the data..
It's all looking good as there's no jumps in the first, third or fourth columns. The second is the noisy byte so that is expected to jump about.
Code:
34177 96  43778 43777 floor
34176 118 43776 43774 +80 cm
34173 48  43770 43770 +180 cm
For the first column ( raw sensor ) -

A decrease of 1 for 0 to 80, -1 => 80
A decrease of 4 for 0 to 180, -1 => 45

For the third column ( adjusted to offset 16-bit )-

A decrease of 2 for 0 to 80, -1 => 40
A decrease of 8 for 0 to 180, -1 => 22.5

For the fourth column ( averaged offset 16-bit ) -

A decrease of 3 for 0 to 80, -1 => 26.7
A decrease of 7 for 0 to 180, -1 => 25.7

That's not looking too bad. We could roughly say a decrease of 1 represents a rise of 26 cm. That's pretty close to the 250mm predicted.

As to 'grnd' in the code - That was just preparing for the next step so we can store what your floor level is, 'ground', then calculate the pressure drop above that. For example, 'grnd' at 43777 -
Code:
34177 96  43778 43777 | 43777 - 43777 = 0 | floor
34176 118 43776 43774 | 43777 - 43774 = 3 | +80 cm   3 x 26 = 78
34173 48  43770 43770 | 43777 - 43770 = 7 | +180 cm  7 x 26 = 182
I would say we are getting there. I think there might be an easy way to do it all with 32-bit maths, from sensor reading up.

Can't comment on your other code. haven't had time to study it yet.
 

Benjie

Senior Member
#83
Hi Hippy,
now it works well. I had to trim the pauses and the sound parameters. It responds well for altitude variations of .40 meter/sec with different tone depending on the direction. At present the repetition rate of the tones depends on the pauses. I'll make some attempt to setfreq at m8 to double the repetition rate and create a pause between sound pulses inversely proportional to the value of "diff".
Here the current code:
Code:
#Picaxe 08M2
#Terminal 4800
#No_Data

Symbol this = w1 : Symbol this.msb = b3 : Symbol this.lsb = b2
Symbol last = w2 : Symbol last.msb = b5 : Symbol last.lsb = b4
Symbol avrg = w3
Symbol avrg1 = w4
Symbol diff = b0
Symbol grnd = w5
Symbol CMD_RESET   = $1E
Symbol CMD_D1_4096 = $48
Symbol CMD_ADC     = $00
Symbol beat = b1
PowerOnReset:

  HI2cSetup I2CMASTER, %11101110, I2CSLOW, I2CBYTE

MainLoop:

  Do
'first reading store avrg

    HI2cOut ( CMD_D1_4096 )
    Pause 10
    HI2cOut ( CMD_ADC )
    Pause 10

    HI2cIn ( this.msb, this.lsb, b0 )
    this = this Min $3000 - $3000 Max $7FFF * 2 + bit7 

    If avrg = 0 Then
      avrg = this
    Else
      w0   = this / 2
      avrg = avrg / 2 + w0 
      If grnd = 0 Then
        grnd = avrg
      End If
    End If

    Pause 100

'second reading store avrg1

       HI2cOut ( CMD_D1_4096 )
    Pause 15
    HI2cOut ( CMD_ADC )
    Pause 15

    HI2cIn ( last.msb, last.lsb, b0 )
    last = last Min $3000 - $3000 Max $7FFF * 2 + bit7 

      avrg1 = last
      w0   = last / 2
      avrg1 = avrg1 / 2 + w0

  
select case avrg1
    
case = avrg
    diff = 0 : sound 4,(0,10)
case > avrg
      diff = avrg1 - avrg 
      if diff  >= 2 then 
          sound 4,(30,10) 
      else 
          sound 4,(0,10)  
      endif
case < avrg
      diff = avrg - avrg1 
      if diff >= 2 then 
          sound 4,(110,10)
      else 
          sound 4, (0,10)  
      endif
end select
pause 100

  loop
 

hippy

Technical Support
Staff member
#84
I'll take your word for it working but I'm not entirely sure how it's working or what you are actually measuring or comparing.
Code:
avrg1 = last
w0 = last / 2
avrg1 = avrg1 / 2 + w0
All that would seem to be achieving is ...
Code:
avrg1 = last / 2 * 2
But, if it works, it works !
 

Benjie

Senior Member
#85
Your note has been taken.
Here the latest version while waiting for the FM transmitter ( I temporarely connected an earphone).
Code:
#Picaxe 08M2
#Terminal 9600
#No_Data

Symbol this = w1 : Symbol this.msb = b3 : Symbol this.lsb = b2
Symbol last = w2 : Symbol last.msb = b5 : Symbol last.lsb = b4
Symbol ripo = w3 : Symbol ripo.msb = b7 : Symbol ripo.lsb = b6

Symbol inter = w4 : Symbol inter.msb = b9 : Symbol inter.lsb = b8
Symbol diff = b0
Symbol CMD_RESET   = $1E
Symbol CMD_D1_4096 = $48
Symbol CMD_ADC     = $00

PowerOnReset:

setfreq m8
  HI2cSetup I2CMASTER, %11101110, I2CSLOW, I2CBYTE

MainLoop:

  Do

    HI2cOut ( CMD_D1_4096 )
    Pause 20
    HI2cOut ( CMD_ADC )
    Pause 20

    HI2cIn ( this.msb, this.lsb, b0 )
    this = this Min $3000 - $3000 Max $7FFF * 2 + bit7 
      
 ; set initial value of ripo    
        if ripo = 0 then 
        ripo = this
        endif
; activate a two tones sound : goes up or goes down with a gap of +- 2 
        select case this    
        case = ripo
    diff = 0 : sound 4,(0,1)
        case > ripo
      diff = this - ripo 
      if diff  >= 2 then 
          sound 4,(20,5)
      else 
          low 4  
      endif
        case < ripo
      diff = ripo - this 
      if diff >= 2 then 
          sound 4,(120,5)
      else 
          low 4 
      endif
        end select
  ; save the pressure reading for next reading comparison
        let ripo = this
  ; modulate  frequency of readings and the sound pulses interval prpoprtional to 1/diff     
    select case diff
    case =< 2 : inter = 300
    case < 10 : inter = 3000 / diff
    case >= 10 : inter = 300
    end select    
        
    Pause inter
  loop
 
Top