SOLVED!!: WORKING WITH GY-801.... EVERYTHING OK BUT HMC5883L NOT WORKING AT ALL

SOLVED!!: WORKING WITH GY-801.... EVERYTHING OK BUT HMC5883L NOT WORKING AT ALL

:frowning: :frowning: :frowning:

i think the problem from address but i'm not sure plz any one know what the problem because i work for project

Wuh?

Try suing this program and tell us how many i2c address you see

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
bool blinkState = false;
#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
  pinMode(3, OUTPUT);
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
        blinkState = !blinkState;
        digitalWrite(3, blinkState);
      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknow error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

thank you for reply
the code found all sensor
and i check on all lib is the same address

Scanning...
I2C device found at address 0x1E ! HMC5883L_h
I2C device found at address 0x53 ! ADXL345_h
I2C device found at address 0x69 ! L3G4200D_h
I2C device found at address 0x77 ! BMP180_ADDR
done

this define in the HMC5883L_h you see any thing wrong ?

#define HMC5883L_Address 0x1E
#define ConfigurationRegisterA 0x00
#define ConfigurationRegisterB 0x01
#define ModeRegister 0x02
#define DataRegisterBegin 0x03

#define Measurement_Continuous 0x00
#define Measurement_SingleShot 0x01
#define Measurement_Idle 0x03

anas_aloklah:
thank you for reply
the code found all sensor
and i check on all lib is the same address

Scanning...
I2C device found at address 0x1E ! HMC5883L_h
I2C device found at address 0x53 ! ADXL345_h
I2C device found at address 0x69 ! L3G4200D_h
I2C device found at address 0x77 ! BMP180_ADDR
done

this define in the HMC5883L_h you see any thing wrong ?

#define HMC5883L_Address 0x1E
#define ConfigurationRegisterA 0x00
#define ConfigurationRegisterB 0x01
#define ModeRegister 0x02
#define DataRegisterBegin 0x03

#define Measurement_Continuous 0x00
#define Measurement_SingleShot 0x01
#define Measurement_Idle 0x03

My post and Script was to help you determine that the hmc5883 was operational and what the address of it is and your above reply proved that. As for code or additional support to use the hmc5883, I have none and unfortunately I am not able to help further.

Do you have a problem, or not? The last post in this thread makes it seem that you do. But, your title and initial post make it seem that you do not.

If you do have a problem, what is it?

yes i have problem the Magnetometer in gy-801 is not read data the result is the same data is don’t change i want detect North and know angle between North and my head in X and Y

this my result

Raw: 570 954 12 Scaled: 524.40 877.68 11.04 Heading: 1.08 Radians 61.76 Degrees
Raw: 570 954 12 Scaled: 524.40 877.68 11.04 Heading: 1.08 Radians 61.76 Degrees
.
.
.

Raw: 570 954 12 Scaled: 524.40 877.68 11.04 Heading: 1.08 Radians 61.76 Degrees

and this is code

/*
HMC5883L_Example.pde - Example sketch for integration with an HMC5883L triple axis magnetomerwe.
Copyright (C) 2011 Love Electronics (loveelectronics.co.uk)

This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

*/

// Reference the I2C Library
#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>

// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;

// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
// Initialize the serial port.
Serial.begin(9600);

Serial.println(“Starting the I2C interface.”);
Wire.begin(); // Start the I2C interface.

Serial.println(“Constructing new HMC5883L”);
compass = HMC5883L(); // Construct a new HMC5883 compass.

Serial.println(“Setting scale to +/- 1.3 Ga”);
error = compass.SetScale(1.3); // Set the scale of the compass.
if(error != 0) // If there is an error, print it out.
Serial.println(compass.GetErrorText(error));

Serial.println(“Setting measurement mode to continous.”);
error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
if(error != 0) // If there is an error, print it out.
Serial.println(compass.GetErrorText(error));
}

// Our main program loop.
void loop()
{
// Retrive the raw values from the compass (not scaled).
MagnetometerRaw raw = compass.ReadRawAxis();
// Retrived the scaled values from the compass (scaled to the configured scale).
MagnetometerScaled scaled = compass.ReadScaledAxis();

// Values are accessed like so:
int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

// Calculate heading when the magnetometer is level, then correct for signs of axis.
float heading = atan2(scaled.YAxis, scaled.XAxis);

// Once you have your heading, you must then add your ‘Declination Angle’, which is the ‘Error’ of the magnetic field in your location.
// Find yours here: http://www.magnetic-declination.com/
// Mine is: 2� 37’ W, which is 2.617 Degrees, or (which we need) 0.0456752665 radians, I will use 0.0457
// If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
float declinationAngle = 0.0457;
heading += declinationAngle;

// Correct for when signs are reversed.
if(heading < 0)
heading += 2*PI;

// Check for wrap due to addition of declination.
if(heading > 2PI)
heading -= 2
PI;

// Convert radians to degrees for readability.
float headingDegrees = heading * 180/M_PI;

// Output the data via the serial port.
Output(raw, scaled, heading, headingDegrees);

// Normally we would delay the application by 66ms to allow the loop
// to run at 15Hz (default bandwidth for the HMC5883L).
// However since we have a long serial out (104ms at 9600) we will let
// it run at its natural speed.
// delay(66);
}

// Output the data down the serial port.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
Serial.print(“Raw:\t”);
Serial.print(raw.XAxis);
Serial.print(" “);
Serial.print(raw.YAxis);
Serial.print(” “);
Serial.print(raw.ZAxis);
Serial.print(” \tScaled:\t");

Serial.print(scaled.XAxis);
Serial.print(" “);
Serial.print(scaled.YAxis);
Serial.print(” ");
Serial.print(scaled.ZAxis);

Serial.print(" \tHeading:\t");
Serial.print(heading);
Serial.print(" Radians \t");
Serial.print(headingDegrees);
Serial.println(" Degrees \t");
}

final is work but the result is not logic

Raw: 28013 11 -19456 Scaled: 25771.96 10.12 -17899.52 Heading: 0.05 Radians 2.64 Degrees
Raw: 11 12 -11008 Scaled: 10.12 11.04 -10127.36 Heading: 0.87 Radians 50.11 Degrees
Raw: -16128 12 0 Scaled: -14837.76 11.04 0.00 Heading: 3.19 Radians 182.58 Degrees

is the big different and i dont move the sensor

i think some thing happen

how i can know if the sensor is working properly

how i can know if the sensor is working properly

Get a very small magnet and move it near the sensor.