Arduino Duemilanove and Hmc5883l

hi ! ? have arduino duemilanove and ? use hmc5883l . ? find that link . ? try that code but ? cant see anything in serial port . but ? can see some values when ? remove hmc5883l . what can ? do ? and sorry, my english isnt good .

Do you have the pull-up resistors in place as mentioned in the tutorial? Do you use exactly the breakout board described in the tutorial? If not, which one are you using? Show us your wiring as your problems may lie there.

Have you looked out for the correct baud rate ? please confirm the serial monitor baud rate is same as the baud rate of your programme?

? have hmc5883l eval board so ? havent pull up resistors. you can see my problem from images

@NI$HANT thank you for helping , ? check baudrate . they are same

please post your code may be something in there is phishy!

there are hmc5883l.cpp and hmc5883l.h

HMC5883L.rar (4.75 KB)

You told that you don't have pull-ups but you need them!

SCA and SCL needs to be pulled up exactly once in a system, that's why no board includes the pullups internally but they are needed. In the tutorial you mentioned you can see the values for the resistors you need and where to place them. Without them you probably won't be successful and if you are, the results may be instable.

? use pull up res. (10k) between vcc and scl ,vcc and sda . but it is same . nothing happen . help me :)

I hope by Vcc you mean 3.3V and not Vcc of the Arduino which is 5V. The HMC5883l is specified only till 3.6V. For perfect operation you should insert a level converter (3.3V to 5V) for both I2C lines but pullups to 3.3V should work for the beginning.

Please supply us with the wiring, which pins you connected from the Arduino to the board and what you've put between them. There are lots of things that can go wrong in these connections.

my power supply already 3.3 volt and pullups work with 3.3v . ? use a4 pin for sda ,a5 pin for scl .

May I ask again for a picture of your circuit?

there is my circuit

I cannot find any information about the eval board you're using. Your picture aren't sharp enough to distinguish anything on the PCB. I think I recognized the pin between VDD and GND to be S1. In the documentation to the chip this signal should be connected to VDDIO which probably is connected on the eval board to VDD. I would try to connect that to VDD (3V3) and test your sketch again.

I suppose you're sure about never having connected any of the pins to the 5V of your arduino. According to the datasheet this would have fried your chip immediately which would explain why it's not responding now. Can you confirm that?

You wrote in your first post that it shows output when you remove the sensor. What action exactly do you do when removing the sensor? Pulling out the VDD connection? Pulling out SDA/SCL?

? have 3 or 4 eval board if it fried , ? will try with other board . ? connect vdd?o and vcc and ? see values serial port when i2c connected . but always 92.62 or 272.62 . when ? turn sensor ? see 92.62 . ? turn again and ? sea 272.62 . ? think there are wrong calculations .

So you do get values from the board but they are not what you expect them to be. And you do not remove the board but just move or better turn it. Is that correct?

If yes, please post your sketch (you just attached the used library yet, not your sketch), as we have just seen pictures of a part of it. Don’t forget to put code tags around it (selecting the code and hitting the # button above the smileys).

? cant take true values , when ? turn sensor . image values1 ; values changed when ? turn sensor . image values ; radian and degrees dont changed with other values .they are 272 degrees and 90 degrees , 4.76 radian and 1.72 radian . image calculate radian degrees show us how calculate radian and degrees . what is my wrong ?

when ? move up or down sensor degrees changed . ? cant understand , ? use hmc for digital compass so which axis ? use ?

Please post the code in your IDE (that's what's on your pictures).

The code you have there is called a sketch in Arduino world. So go into the IDE, hit Ctrl-A, then Ctrl-C, then come to this web page and hit the reply button. In the form there you have a "#" button. Hit that first and then press Ctrl-V (for pasting). This way you post your sketch to the forum, that's what I asked for in my last post. This way we can see what your code (not the library you're using) does.

HMC5883L_Example.ino - Example sketch for integration with an HMC5883L Triple Axis Magnetometer.
Copyright (C) 2012 Love Electronics (

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
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 <>.

// 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.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("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.

// 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_YAxis = 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:
  // 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("   ");   
   Serial.print("   ");   
   Serial.print("   Scaled:");
   Serial.print("   ");   
   Serial.print("   ");   

   Serial.print("   Heading:");
   Serial.print(" Radians   ");
   Serial.println(" Degrees   ");

sorry for my bad english