About HMC5883L module

Hi,
The examples from Arduino_HMC5883L_MASTER used :
HMC5883L compass; and compass.begin();
and the: Adafruit_HMC5886L_Unified’s magsensor used: Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345); and mag.getSensor(&sensor);

these made me confused and need help please.

  1. what's the difference between compass and mag?
  2. can use both?
    Thanks
    Adam

A magnetometer measures the strength of a magnetic field.
A compass is a magnetometer that has been calibrated to indicate magnetic north.

2 Likes

The names mag and compass are just names that identify an instance of the library's object. You could write
Adafruit_HMC5883_Unified compass = Adafruit_HMC5883_Unified(12345);
and
compass.getSensor(&sensor); (change all references to mag to compass).
or
Adafruit_HMC5883_Unified fred = Adafruit_HMC5883_Unified(12345);
and
fred.getSensor(&sensor); (change all references to compass to fred).

1 Like

Thank you a lot.
BTW: the code below :

 // Read desired heading
  sensors_event_t event;
  mag.getEvent(&event);
  desired_heading = event.orientation.x;

from a :
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345); setting.
Do I have to use the method above or can I get the : desired_heading = xxxxxxx.x; just under the compass setting? actually how to get the x axis reading.
Best.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.