mjerenje pritska zraka-barometar

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

mjerenje pritska zraka-barometar

Post by febo26 »

Danas stigao s Ebaya senzor za mjerenje pritiska zraka atmosfere BMP0085 ali nisam nasao niti jedan upotrebljivi primjer da ga ozivim u Pic Basicu.
Da li se mozda netko igrao s njim i uspio ga ozivit.

Ima li koji drugi senzor koji bi se mogao upotrijebiti za mjerenje atmosferskog pritiska.

Radim si malo vremensku stanicu za doma pa skupljam komponente za nju i malo da naucim programirat.

I jos jedna stvar mada nije vezana za ovu temu.Na koji nacim izmjeriti brzinu vjetra.Gotovi anemometri su mi preskupi pa sam mislio iskoristiti motor od video glave od video rekordera posto se na njemu vec nalazi Hallov senzor.
Znaci na glavu bi nakacio tri lopatice i kako se one okrecu pod utjecajem vjetra ja dobivam impulse na halovom elementu,Sad mi je problem kako izracunati brzinu vjetra na osnovi dobivenih impulsa.
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Nece moci ovaj senzor BMP0085 da se iskoristi kao barometar jer radi na 3V3. a PIC18f4550 i LCD displej rade na 5V.
Idem potrazit neki drugi senzor za pritisak mjeriti. Nesto od motorole MPX serija
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: mjerenje pritska zraka-barometar

Post by pedja089 »

Nema to nikakve veze. Daj neku dokumentaciju...
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Evo linka sa dokumentacijom od senzora ----https://www.sparkfun.com/products/9694-----
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Na Picbasic.co.uk forumu ima primjer programa za taj senzor jedino je prikaz rezultata izveden na serijski LCD.

Da li PIC smije radit na 5Volti a Senzor na 3V3?
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: mjerenje pritska zraka-barometar

Post by pedja089 »

A zasto ne bi smelo??
Samo na senzor ne sme da dodje nista preko njegovog napona napajanja.
Stavis 3.3Vreg, pull up zakacis na 3.3V. Odmah na pocetku programa proglasis sve pinove za senzor ulaznim, da slucajno pic ne bi poslao 5V na senzor. Ne bi bilo lose 3.3V zener na svim pinovima senzora, pa se ne brines jel pic pokusava ugurati 5V. pic ako radi na 5V prepoznaje 3.3V kao logicku 1.
User avatar
morski_pas
Odlično uznapredovao
Odlično uznapredovao
Posts: 639
Joined: 07-03-2011, 23:58
Location: Rijeka

Re: mjerenje pritska zraka-barometar

Post by morski_pas »

pogledaj malo na ovoj stranici :
http://sensorapp.net/?p=278
i ovoj:
http://mbed.org/users/tkreyche/notebook ... re-sensor/

za napajanje senzora stavi neki 3,3 V regulator (LM2937ET-3.3 V , LM1117 )kao što ti je predložio pedja

Image
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Razmislajo sao i o toj ideji ali nisam mislio da pinovi na picu koji se koriste za komunikaciju moraju biti ulazni.Budem probao veceras kad se vratim s posla.Sada jos moram naci neki 3V regulator na nekoj staroj maticnoj ploci.Ovo sa zenericam je super ideja samo da li bi bilo pametno stavit neki otpornik u seriju s pinovima za kominikaciju da nebi doslo s PICa 5volta pa zenerica provede i skuri port na PICu.
User avatar
morski_pas
Odlično uznapredovao
Odlično uznapredovao
Posts: 639
Joined: 07-03-2011, 23:58
Location: Rijeka

Re: mjerenje pritska zraka-barometar

Post by morski_pas »

evo vidi i ovdje imaš jedan projekt sa kodom :)
http://blog.jacobean.net/?p=678#more-678
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: mjerenje pritska zraka-barometar

Post by pedja089 »

Pinovi kontrolera se ponasaju kao strujni izvori 20/25mA kako koji kontroler. Tako da nikakav otponik ne treba.
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Evo pozitvnih rezultata kako sam i obecao dopodne.

Napon s 5V spusten na 3V3 pomocu regulatora napona.Zener diode nesmiju biti na SDA i na SCL liniji.dok su spojene imam kriva ocitanja.
pullup otpornici spojeni na 3v3.PIC port konfiguriran kao ulazni.

slike su u attachmentu.

Posto kod nije moj vec je skinut s picbasic.co.uk foruma i prepravljen da radi na normalnom LCD displeju da li ga smijem objaviti tu na nasem forumu?
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

evo slike sa zakasnjenjem
Attachments
Fotografija0120.jpg
Fotografija0120.jpg (24.42 KiB) Viewed 9756 times
Fotografija0119.jpg
Fotografija0119.jpg (14.72 KiB) Viewed 9756 times
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: mjerenje pritska zraka-barometar

Post by pedja089 »

A zasto ne bi smeo...
Ako hoces postavi i link sa kojeg si skinuo kod...
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

link od kuda je skinut primjerhttp://www.picbasic.co.uk/forum/showthr ... ght=BMP085

Pitam reda radi,da nebi bilo da me netko banira zbog toga sto pustam tudje kodove.

Da li je moguce na neku foru izracunati visinsku razliku u metrima npr.dodjem u prizemlje zgrade i popnem se na vrh nje i da mi izracuna razliku u visini...U datashetu ima neka formula ali moja matematika to ne razumije. :oops: :oops: :oops:

evo i mojeg koda:

Code: Select all

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 2.1.2013                                          *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'PortA.0/Pin 2 = Serial TX
'PortA.1/Pin 3 = LED
'PortC.0/Pin 33 = I2C SCL clock
'PortC.1/Pin 34 = I2C SDA data
 
 
 
    DEFINE OSC 8 '8Mhz clock used.
 DEFINE LCD_BITS 4      ' LCD broj Bita na liniji 4 ili 8
DEFINE LCD_DREG PORTD  ' LCD data port
DEFINE LCD_DBIT 0      ' LCD pocetni bit podataka 0 ili 4(od kojeg pina na mikrokontroleru pocinje 0 bit podataka)
DEFINE LCD_RSREG PORTD ' LCD registar select port
DEFINE LCD_RSBIT 4     ' LCD registar select bit (na koji pin na mikrokontroleru je povezan RS bit)
DEFINE LCD_EREG PORTD  ' LCD enable port
DEFINE LCD_EBIT 5      ' LCD enable bit(na koji pin na mikrokontroleru je povezan E bit)
DEFINE LCD_LINES 4     'LCD koristi 2 reda za ispis 2x16 lcd 
        
' Software Defines (variables and pins)
    Cal_table   var word[11]         '11 word array to store calibration data
    lUpres      var long             'Long variable for Uncompensated Pressure
    lPres       var Long             'Long variable for Compensated Pressure
    lTemp_Var1  Var long             'Long temporary variable
    X1          var Long
    X2          var Long
    X3          var Long
    B3          var long
    B4          var long
    B5          var long
    B6          var Long
    B7          var long
    
    lAC1        var Long            'Long variables for cal values actually negative in my sensor
    lAC2        var long            'These are 'cast' from the Word vars into Long vars in code below
    lAC3        var Long 
    lAC4        var Long 
    lMB         var Long
    lMC         var Long
 
    bTemp_Var1  var byte             'Byte temp variable 
    wTemp_Var1  var Word	         'Word temp variable
    wTemp_Var2  var word             'Word temp variable
    lUTemp      var long             'Uncompensated temperature reading from sensor
    lCTemp      var Long             'Compensated (real) temperature x10 (1/10th of C) from sensor
    i2c_Reg     var Byte             'variable for target i2c register address

    CPIN        var     PortB.0       ' I2C clock pin 
    DPIN        var     PortB.1       ' I2C data pin
    SO          Var     PortA.0       'Serial out pin
    LED         var     PortA.1       'Indicator LED, via 500ohm to +3.3V
    
    OSS         con     $3          'This value is the Over Sampling Setting for the BMP085
                                    '0 = minimum, 3 = maximum. Also change value in Read_pres if you alter OSS 

'Alias's for calibration data in the sensor to match the Bosch parameter list names
    AC1     var     Cal_table[0]        '
    AC2     var     Cal_table[1]        'BMP085 has 11 16bit values stored in EEPROM
    AC3     var     Cal_table[2]        'First byte is at $AA last at $BF, two bytes per cal value
    AC4     var     Cal_table[3]        'Lowbyte is MSB (e.g $AA), Highbyte is LSB (e.g. $AB)
    AC5     var     Cal_table[4]        '
    AC6     var     Cal_table[5]    
    B1      var     Cal_table[6]        'Warning - AC4, AC5, AC6 are UNSIGNED values, the rest are SIGNED
    B2      var     Cal_table[7]
    MB      var     Cal_table[8]
    MC      var     Cal_table[9]    
    MD      var     Cal_table[10]
    
    
    
    'vlaznost zraka 
    RH_IN  VAR WORD
RH VAR WORD

   
    
' Initialise Processor - check for each PIC type 
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ADCON1 = %00001111              'Turn off all AD's     
    'OSCCON =  %01100111     'set INTRC to 4 MHZ    
OSCCON = %01110111     'set INTRC to 8 MHZ
'    OSCTUNE = 0                      'OSC trim set to Null 

' Set initial state of port pins as Input or Output if needed
TRISA = %11111101    'Input(0 = output, 1 = Input)
TRISB = %11111111   '
TRISC = %00000000
TRISD = %00000000
TRISE = %11111111
    
' PIC initialization code
'       Low So      'Start low, or you get rubbish on the LCD at PIC boot up.
       Gosub Alive                             'Go prove the PIC is running via LED         
       LCDOUT $FE,$01 ,"   FrSky Vario    "                ' Clear LCD & home LCD cursor.
       LCDOUT $FE,$C0, " Development Jig  "                ' Shift cursor to line2
       Pause   2000
        
        i2c_Reg =$AA                            'Start address of the BMP085 calibration data
        I2CREAD DPIN,CPIN,$EF,I2C_REG,[STR Cal_table\11],cal_error  'Read 11 reversed words out of sensor

        AC1 = (AC1.lowbyte<<8) + AC1.highbyte   'swap MSB and LSB of each to use in PBP (un-reverse then)    
        AC2 = (AC2.lowbyte<<8) + AC2.highbyte   'device stores the MSB in the Low byte, LSB in the High byte
        AC3 = (AC3.lowbyte<<8) + AC3.highbyte   
        AC4 = (AC4.lowbyte<<8) + AC4.highbyte          
        AC5 = (AC5.lowbyte<<8) + AC5.highbyte
        AC6 = (AC6.lowbyte<<8) + AC6.highbyte
        B1 = (B1.lowbyte<<8) + B1.highbyte
        B2 = (B2.lowbyte<<8) + B2.highbyte
        MB = (MB.lowbyte<<8) + MB.highbyte
        MC = (MC.lowbyte<<8) + MC.highbyte
        MD = (MD.lowbyte<<8) + MD.highbyte 

'Cast (convert) signed PBP Word vars to signed PBP Long vars where needed by math routines below
        lAC1 = AC1                           'copy word to long   
        if AC1.15 then lAC1.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true 

        lAC2 = AC2                           'copy word to long   
        if AC2.15 then lAC2.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true 

        lAC3 = AC3                           'copy word to long
        if AC3.15 then lAC3.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true

        lMB = MB                            'copy word to long
        if MB.15 then lMB.HIGHWORD = $FFFF  'Check for negative, set top 16bits to all 1's if true

        lMC = MC                            'copy word to long
        if MC.15 then lMC.HIGHWORD = $FFFF  'Check for negative, set top 16bits to all 1's if true

'Cast (convert) UN-signed PBP Word var to UN-signed PBP Long var for math routines below
        lAC4 = AC4                          'copy word to long, both unsigned
                                
      LCDOUT $FE,1            'CLEAR LCD.    '

'Main loop -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Main:  
                                
COUNT PORTA.0,1000,RH_IN
rh = (9740-rh_in) / 18

lcdout $fe,$c0,"RH = ",dec rh ," %  "
      
        Gosub Read_temp                        'get Temp via I2C
        
        'LCDOUT $FE,$80, "UT=",SDEC lUtemp," "      'Send Word size number to LCD
        
        lTemp_Var1 = 0                          'Clear the last pressure reading
        For bTemp_Var1 = 0 to 9                 'Start of 10x averaging routine
        Gosub Read_pres                         'get Long uncompensated pressure via I2C
        lTemp_Var1 = lTemp_Var1 + lUpres
        Next bTemp_Var1
        lUpres = lTemp_Var1 / 10                'finish of the 10x Averaging routine   

        'LCDOUT $FE,$C0,"UP=",SDEC lUpres," "       'Send Word size number to LCD

'Calculate temperature in 1/10ths of Deg C  from lUTemp     ' Note 2^15 = 32768 Dec or $8000
        X1 = ((lUtemp - AC6) * AC5) / $8000     'find X1. 
        X2 = (lMC * $800) / (X1 + MD)           'Find X2.  Note:- math rounding results in X2 being in error by 1 ?
        B5 =  X1 + X2                           'Find B5 from X1 and X2.
        lCTemp = (B5 + 8) / 16                  'Hey presto, lCTemp appears... 

'DISPLAY true temperature in C 
        X1 = lCTemp / 10                         'find value above decimal point
       LCDOUT $FE,$94 ,"TEMP= ",DEC X1,"."       ' Shift cursor to line_2   
        X1 = lCTemp // 10                        'Find decimal value
       LCDOUT $FE,$94+9 ,DEC X1,"'C"            'Send Word size number to LCD 
         
'Calculate pressure in Pascals from uncompensated pressure lUpres (1/100th's of hPa's)        
        B6 = b5 - 4000

        x1 = (b2 * (B6 * B6 / $1000)) / $800 
        x2 = (lac2 * B6) / $800
        x3 = x1 + x2
        B3 = ((lac1 * 4 + x3) << OSS + 2) / 4     'OSS = Over Sampling constant set above  
 
        x1 = (lac3 * b6) / $2000
        x2 = (b1 * (b6 * b6 / $1000)) / $10000
        x3 = ((x1 + x2) + 2) / 4
        B4 = (lac4 * (x3 + 32768)) / $8000        'Find B4, note lAC4 is an unsigned Long

        B7 = (lUPres - B3) * (50000 >> OSS)       'OSS = Over Sampling constant set above
 
        If B7 < $80000000 then                    'branch if value is above or below range
            lPres = (B7 * 2) / B4
            Else
            lPres = (B7 / B4) * 2
        Endif

        X1 = (lPres / 256) * (lPres / 256)
        X1 = (X1 * 3038) / $10000                 '$10000 = 2^16
        X2 = (-7357 * lPres) / $10000
        lPres = lPres + (X1 + X2 + 3791) / 16     'lPres is the true pressure in Pa

'DISPLAY true pressure in hPa
        X1 = lPres / 100                          'find value above decimal point
                                                  'Shift cursor to line_3   
       LCDOUT $FE,$D4, "hPa= ",DEC X1,"."          'Send Word size number to LCD        
        X1 = lPres // 100                         'find value below decimal point
        LCDOUT $FE,$D4+10, DEC X1,"  "               'Send Word size number to LCD         
        pause 2000
        Toggle LED                                'flash the 'im alive' LED
        Goto main
        
'SUBROUTINES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-      
Read_pres: 
        i2c_Reg = $F4                               '$F4 is the control register address
        I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$F4]        ' Write $34+(oss << 6) to set pressure conversion 
        Pause 30                                    ' Delay 10ms after each write (30mS for HiRes results (oss=3))
        i2c_Reg = $F6                               '$F6 is the result register MSB
        I2CREAD DPIN,CPIN,$EF,I2C_REG,[lUpres],I2C_error  'Read pressure MSB, LSB, XLSB, $F9 ($F9 not actually wanted).
        lUpres = lUpres >> (16 - oss)               'remove $F9 from result (>>8), and left shift result back to 16 to 19 Bits (OSS value dependant)
                                                    'it's because PBP reads four bytes if [Var] is a long...
        return                                      'we only want top 19bits of the result.
              
Read_temp:
        i2c_Reg = $F4                               '$F4 is the control register address
        I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$2E]        ' Write $2E to set temperature conversion 
        Pause 10                                    ' Delay 10ms after each write
        i2c_Reg = $F6                               '$F6 is the result register MSB
        I2CREAD DPIN,CPIN,$EF,I2C_REG,[wTemp_Var1],I2C_error  'Read temperature MSB, LSB.
        lUTemp = wTemp_Var1                          'copy word to long. Note BMP085 UT is NOT a signed value   
        return

'Prove it's alive
Alive:
        High LED                                     'flash LED routine
        For btemp_var1 = 10 to 110 step 10
        Low LED
        Pause bTemp_Var1
        High LED
        Pause bTemp_Var1
        Next bTemp_Var1
        
        Return

'trap and display I2C problems        
I2C_error:     
        LCDOUT $FE,$01 ,"i2c bus read error"            ' Clear LCD & home LCD cursor. 
        Pause 10                              ' wait for LCD to catch up        
        pause 2000        
        Toggle LED
        Goto main
         
Cal_error:
       
        LCDOUT $FE,$01 ,"i2c cal read error " 
        PAUSE 2000      '        
        GOTO main
        
End
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

zaboravih napisat mikrokontroler je PIC18F4550 i koristi se interni oscilator na 8MHz
User avatar
rajac
Napredujem
Napredujem
Posts: 129
Joined: 11-03-2009, 19:01

Re: mjerenje pritska zraka-barometar

Post by rajac »

pedja089 wrote:Pinovi kontrolera se ponasaju kao strujni izvori 20/25mA kako koji kontroler.
Otkud taj podatak?
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: mjerenje pritska zraka-barometar

Post by pedja089 »

Iz datasheet-a.
Kada se predje odredjena struja(zavisi od konkretnog pina na kontroleru i kontrolera) samo napon pada, struja neznatno raste...

Evo provereno, kratak spoj na 18F4550 napajan sa 5V daje 18,65mA,
5R:18,53mA
10R:18,43mA
20R:18,25
47R:17.56mA
94R:16,21mA
Otpornici su 1% metal film.
Sto je priblizno kao strujni izvor, zar ne?

EDIT:
Za zenerice sam zaboravio napisati...
Verovatno im je prevelika parazitna kapacitivnost, pa zato stvaraju probleme. Inace to sluzi samo ako ti u kodu napise da je pin izlazni...
Kod I2C pin je ili ulaz ili 0.
User avatar
rajac
Napredujem
Napredujem
Posts: 129
Joined: 11-03-2009, 19:01

Re: mjerenje pritska zraka-barometar

Post by rajac »

To je onda prije naponski izvor sa strujnim ograničenjem(zaštitom),samo treba pazit jer to vrijedi samo za source,za sinking nema nikave zaštite,bar tako piše u DS.
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Evo moje male vremenske stanice.Nije nesto, ali funkcionira.
Jos fali brzina i smjer vjetra.
Attachments
Fotografija0122.jpg
Fotografija0122.jpg (16.34 KiB) Viewed 9633 times
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: mjerenje pritska zraka-barometar

Post by febo26 »

Koji je znak za prikaz stupnjeva na LCD-u,sad imamznak apostrofa prije znaka C,malo me zivcira to
Post Reply