HMC5883L verhält sich komisch

Hallo,

ich habe vor kurzem mit Arduino angefangen und habe ein paar test's laufen zu zeit verwende ich dieses Sensorboard

Temperatur auslesen klappt prima.
Nur wenn ich den Mag. auslesen will bekomme ich nur auf der Z achse änderungen und sowohl x als auch y stehen bei -4596 oder so. PullUp's habe ich keine benutzt. Auch wenn ich multiWii zu testen einsetze bekomme ich nur auf der Y-Achse änderungen.
Ich habe schon mal sda und scl gemessen => 4,8 -4,9 V
Was denkt Ihr? PullUp's rein oder ist der Sensor hin?

/*
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 > 2*PI)
    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");
}

hi,

es wird nicht schaden 5K-pullups testweise reinzuhängen, aber nützen wird's wohl auch nicht.
Du hast nur eine I²C-schnittstelle auf dem ding, und die geht entweder oder eben nicht. sicher nicht nur bei bestimmten achsen.

gruß stefan

Hallo,
PullUp´s sind eigentlich bei ALLEN Applikationen am I2C-Bus vorgeschrieben.
Kann ohne funktionieren- muss aber nicht.
Dann würde ich mit mal ein Datenblatt für das Ding besorgen, um zu wissen
wann das Ding, was liefern muss.
Hast Du einmal den Sketch von der BestellSeite probiert?
Gruß und Spaß
Andreas

Hm ich werde nach der arbeit mal ein Paar 5K Wiederstände besorgen. Das komische ja das der BMP085 der auch auf dem Board ist prima funktioniert. Und die Z Achse liefert werte. Echt komisch. Ich bestelle mal einen Sensor diesmal einzeln ohne Bmp085.

Jupp den MultiWii Sketch habe ich probiert. => da sind auch keine PullUp's mit drin...
Auch im MultiWii Conf kommen nur werte auf der Z Achse.

Hallo,
probiere das mal:

/*
An Arduino code example for interfacing with the HMC5883

by: Jordan McConnell
 SparkFun Electronics
 created on: 6/30/11
 license: OSHW 1.0, http://freedomdefined.org/OSHW

Analog input 4 I2C SDA
Analog input 5 I2C SCL
*/

#include <Wire.h> //I2C Arduino Library

#define address 0x1E //0011110b, I2C 7bit address of HMC5883

void setup(){
  //Initialize Serial and I2C communications
  Serial.begin(9600);
  Wire.begin();
  
  //Put the HMC5883 IC into the correct operating mode
  Wire.beginTransmission(address); //open communication with HMC5883
  Wire.send(0x02); //select mode register
  Wire.send(0x00); //continuous measurement mode
  Wire.endTransmission();
}

void loop(){
  
  int x,y,z; //triple axis data

  //Tell the HMC5883 where to begin reading data
  Wire.beginTransmission(address);
  Wire.send(0x03); //select register 3, X MSB register
  Wire.endTransmission();
  
 
 //Read data from each axis, 2 registers per axis
  Wire.requestFrom(address, 6);
  if(6<=Wire.available()){
    x = Wire.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //Y lsb
  }
  
  //Print out values of each axis
  Serial.print("x: ");
  Serial.print(x);
  Serial.print("  y: ");
  Serial.print(y);
  Serial.print("  z: ");
  Serial.println(z);
  
  delay(250);
}

Gruß und Spaß
Andreas

Danke für die schnelle Antwort aber nein der geht auch nicht.
Bzw. der Code geht aber nur änderungen auf der Z Achse.

hi,

zurücksenden mit verweis auf diesen thread. kann ja schon mal passieren, daß was defekt ist.

gruß stefan

Hallo heute kam Post :slight_smile:

Ausgepackt und in froher erwartung n Sketch drauf gemacht...
Und wie sie sehen sehen sie nix! => Kotze gleicher fehler! Hmm kann nicht sein....!

Vom Kumpel n Ozi ausgeliehen und gemessen.
Und siehe da die Vcc ist immer wieder zusammen gebrochen! Das führte dann zu diesem lusstigen fehlerbild. Geht geht nur halb.... Warum? Warum auc. Ich habe den Ardu. auf einem QuadrocopterBoard gelötet. ( Pro mini)
Da werden die Pins so schön nach aussen geführt. egal
Jetzt ziehe ich mir Vcc von Vcc! Und alles ist schön bei nun 2 Mag's (HMC5883L)

Danke für eure Promte Hilfe!!!