Hi, 

it seem that I'm able to get the data from the  HMC5883L sensor but, the 
data is weird. The data would gain an increment of of 1 until it turn fully 
90 degree then suddenly jump to another number. Here the code can some1 
look over it.

     var i2c =  require('i2c');
    var address_compass = 0x1e;
    var wire1 = new i2c(address_compass, {device: '/dev/i2c-1'});
    var compassData_X = 0;
    var compassData_Y = 0;
    var compassData_Z = 0;
    var compass;

    wire1.writeBytes(0x00, [0x70], function(err) {})
    wire1.writeBytes(0x01, [0xA0], function(err) {})
    wire1.writeBytes(0x02, [0x00], function(err) {})

    setInterval(function(){ wire1.readBytes(0x03, 2, functions(err,res){
        
        compassData_X = res[0] << 8 | res[1] ; 
        
        compassData_Z = res[2] << 8 | res[3] ; 
        
        compassData_Y = res[4] << 8 | res[5];
        
        console.log("x: " + compassData_X + "y: " + compassData_Y + "z: " + 
compassData_X ); */


    var declinationAngle = .226; //use in compass functions, value needed 
checking with sensor
    var pi = 3.14; 
    var heading = Math.atan2(compassData_Y,compassData_X);

    // Once you have your heading, you must then add your 'Declination 
Angle', which is the 'Error' of the magnetic field in your location.
    //If you cannot find your Declination, comment out this lines, your 
compass will be slightly off.
    heading += declinationAngle;

    // Correct for when signs are reversed.
    if(heading < 0)
    heading += 2*pi;
    
     // Check for wrap due to addition of declination.
    else if(heading > 2*pi )
    heading -= 2*pi ;

    // Convert radians to degrees for readability.
    var headingDegrees = ((heading * 180)/pi); 


    console.log("x: " + compassData_X + " y: " + compassData_Y + " z: " + 
compassData_Z + " uT");    // Display the results 
                                                                                
                    
//(magnetic vector values are in micro-Tesla (uT))
    console.log('Heading: ' + headingDegrees + ' degrees' );


})}, 1000) 



Thank you, 





-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to