HMC5883L Magnetometer chip Possibilities.


Closed Thread
Results 1 to 40 of 58

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    I bought one to play with

    after looking at the raw data I came up with this , works ok if device is held level , tilt compensation is elusive at this stage



    Code:
    '****************************************************************
    '*  Name    : hmc5883l.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 29/04/2011                                        *
    '*  Version :                                              *
    '*  Notes   :                                                *
    '*          :  12f1822     
    '*          :  
                 '
    '****************************************************************
     #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_ON
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_OFF
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
     
    
          osccon=$6A    '4 mhz
          anselA=0       'dig i/o
            
          trisA=1110
      
      
      
      
       pause 2000
      serout2 porta.0,84, ["ready",13,10]
      lata.0=1
      
      
       SDA            var      porta.2                 'transceives to/from SDA
       SCL            var      porta.4                  'sends clock pulses
    WRITE_DATA     CON     $3C  'Used to perform a Write operation
    READ_DATA      CON     $3D  'Used to perform a Read operation
    MODE           CON     $02  'Read/Write Register, Selects the operating mode. Default = Single measurement
                                 'Send $3C $02 $00 on power up to change to continuous measurement mode.
    X_MSB          CON     $03  'Read Register, Output of X MSB 8-bit value.
    X_LSB          CON     $04  'Read Register, Output of X LSB 8-bit value.
    Z_MSB          CON     $05  'Read Register, Output of Z MSB 8-bit value.
    Z_LSB          CON     $06  'Read Register, Output of Z LSB 8-bit value.
    Y_MSB          CON     $07  'Read Register, Output of Y MSB 8-bit value.
    Y_LSB          CON     $08  'Read Register, Output of Y LSB 8-bit value.
    Cont_Mode      CON     $0
    X              VAR      byte 'x sensor measured value
    Y              VAR      byte 'y sensor measured value
    Z              VAR      byte 'z sensor measured value
    READX         VAR      WORD 
    READY         VAR      WORD
    READZ         VAR      WORD
    brads          VAR      Word 'angle in brads
    degr           VAR      Word 'angle in degrees
    Radians        VAR      Word 'value calculated using X ATN -Y
    
    ' -----[ Main Routine ]-------------------------------------------------------
    PAUSE 50                                     ' Give sensor needed power up time
      I2CWRITE SDA,SCL,WRITE_DATA,MODE,[0,1,Cont_Mode]  ' Send continuous output command
    PAUSE 10 
    DO
      GOSUB GetRawReading                       ' Get RAW Compass reading
      serout2 porta.0,84, ["x ",SDEC x," y ",SDEC y ," z ",SDEC z,13,10]
      
        brads = -x ATN -y ;
        degr = brads */360 'convert to degrees
       ;serout2 porta.0,84, ["xy ",SDEC Radians ,","]
        serout2 porta.0,84, ["xy ",DEC degr ,13,10]
         brads = -x ATN -z ;
         degr = brads */360 'convert to degrees
       ; serout2 porta.0,84, ["xz ",SDEC Radians ,","]
        serout2 porta.0,84, ["xz ",DEC degr ,13,10]
           brads = -y ATN -z
           degr = brads */360 'convert to degrees
        ;serout2 porta.0,84, ["yz ",SDEC Radians ,","]
        serout2 porta.0,84, ["yz ",DEC degr ,13,10]
        
       PAUSE 2000 
    LOOP
    ' -----[ Subroutines ]--------------------------------------------------------
    GetRawReading:                                 'Compass module subroutine
                                        'Wait for new data to become available
        I2CREAD SDA,SCL,READ_DATA, X_MSB,[READX,READZ,READY]  'Read the data starting at x_msb 3
      
        x = readx >>2  
        Y = readY >>2
        Z = readZ >>2
    RETURN

  2. #2
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    Quote Originally Posted by richard View Post
    I bought one to play with

    after looking at the raw data I came up with this , works ok if device is held level , tilt compensation is elusive at this stage



    Code:
    '****************************************************************
    '*  Name    : hmc5883l.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 29/04/2011                                        *
    '*  Version :                                              *
    '*  Notes   :                                                *
    '*          :  12f1822     
    '*          :  
                 '
    '****************************************************************
     #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_ON
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_OFF
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
     
    
          osccon=$6A    '4 mhz
          anselA=0       'dig i/o
            
          trisA=1110
      
      
      
      
       pause 2000
      serout2 porta.0,84, ["ready",13,10]
      lata.0=1
      
      
       SDA            var      porta.2                 'transceives to/from SDA
       SCL            var      porta.4                  'sends clock pulses
    WRITE_DATA     CON     $3C  'Used to perform a Write operation
    READ_DATA      CON     $3D  'Used to perform a Read operation
    MODE           CON     $02  'Read/Write Register, Selects the operating mode. Default = Single measurement
                                 'Send $3C $02 $00 on power up to change to continuous measurement mode.
    X_MSB          CON     $03  'Read Register, Output of X MSB 8-bit value.
    X_LSB          CON     $04  'Read Register, Output of X LSB 8-bit value.
    Z_MSB          CON     $05  'Read Register, Output of Z MSB 8-bit value.
    Z_LSB          CON     $06  'Read Register, Output of Z LSB 8-bit value.
    Y_MSB          CON     $07  'Read Register, Output of Y MSB 8-bit value.
    Y_LSB          CON     $08  'Read Register, Output of Y LSB 8-bit value.
    Cont_Mode      CON     $0
    X              VAR      byte 'x sensor measured value
    Y              VAR      byte 'y sensor measured value
    Z              VAR      byte 'z sensor measured value
    READX         VAR      WORD 
    READY         VAR      WORD
    READZ         VAR      WORD
    brads          VAR      Word 'angle in brads
    degr           VAR      Word 'angle in degrees
    Radians        VAR      Word 'value calculated using X ATN -Y
    
    ' -----[ Main Routine ]-------------------------------------------------------
    PAUSE 50                                     ' Give sensor needed power up time
      I2CWRITE SDA,SCL,WRITE_DATA,MODE,[0,1,Cont_Mode]  ' Send continuous output command
    PAUSE 10 
    DO
      GOSUB GetRawReading                       ' Get RAW Compass reading
      serout2 porta.0,84, ["x ",SDEC x," y ",SDEC y ," z ",SDEC z,13,10]
      
        brads = -x ATN -y ;
        degr = brads */360 'convert to degrees
       ;serout2 porta.0,84, ["xy ",SDEC Radians ,","]
        serout2 porta.0,84, ["xy ",DEC degr ,13,10]
         brads = -x ATN -z ;
         degr = brads */360 'convert to degrees
       ; serout2 porta.0,84, ["xz ",SDEC Radians ,","]
        serout2 porta.0,84, ["xz ",DEC degr ,13,10]
           brads = -y ATN -z
           degr = brads */360 'convert to degrees
        ;serout2 porta.0,84, ["yz ",SDEC Radians ,","]
        serout2 porta.0,84, ["yz ",DEC degr ,13,10]
        
       PAUSE 2000 
    LOOP
    ' -----[ Subroutines ]--------------------------------------------------------
    GetRawReading:                                 'Compass module subroutine
                                        'Wait for new data to become available
        I2CREAD SDA,SCL,READ_DATA, X_MSB,[READX,READZ,READY]  'Read the data starting at x_msb 3
      
        x = readx >>2  
        Y = readY >>2
        Z = readZ >>2
    RETURN
    So according to your code , we get x , y , z raw readings as byte datas .... and xy xz yz calculations obtained using some trigonometry .. But what do those datas mean ? I think these xy xz yz readings are referring a direction but which one is what ? Does xy give me the magnetic north ? or is it xz or maybe yz ...

    I'd be so happy if any of you guys could help me with that ...

    Thanks ..

Similar Threads

  1. 3 axis digital compass sensor HMC5883L
    By ScaleRobotics in forum General
    Replies: 1
    Last Post: - 8th June 2014, 22:19
  2. How to use this IO chip?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th April 2013, 19:06
  3. compass chip
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th October 2009, 01:42
  4. Do you use ICD possibilities of MicroCode Studio
    By octal in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2007, 17:22
  5. Which chip do i use?
    By The Master in forum Off Topic
    Replies: 77
    Last Post: - 2nd December 2007, 22:28

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts