Skip to content

Can't read HMC5883l data correctly using I2C #470

@leandrogs

Description

@leandrogs

I'm using HMC5883l to read earth's magnetic field. Testing the same library and same code on Arduino Uno it gives correct output, but running on ESP give me wrong values.

For example:
Arduino reading: -123.25 | 9.13 | -35.67
ESP reading: -123.00 | 9.00 | -35.00
I cannot read decimal values on ESP.

Also, sometimes it puts the number 65 at the beginning of negavite numbers like -65123.00 | 9.00 | -6535.00

Here follows my code:

#include <Wire.h>
#include <HMC5883L.h>

HMC5883L magnetometer;
MagnetometerScaled scaledVals;

void setup() {
    Serial.begin(115200);
    Wire.setClock(450000);
    Wire.pins(0, 2);
    Wire.begin();
    magnetometer = HMC5883L();
    magnetometer.SetScale(1.3);
    magnetometer.SetMeasurementMode(Measurement_Continuous);
}

void loop() {
    scaledVals = magnetometer.ReadScaledAxis();
    printScaled(scaledVals);
}

void printScaled(MagnetometerScaled scaled)
{
    Serial.print(scaled.XAxis);
    Serial.print(" | ");
    Serial.print(scaled.YAxis);
    Serial.print(" | ");
    Serial.print(scaled.ZAxis);
    Serial.print("\n");
}

Should I post library code?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions