GithubHelp home page GithubHelp logo

adafruit_hmc5883_unified's Introduction

Adafruit HMC5883L Driver (3-Axis Magnetometer) Build StatusDocumentation

This driver is for the Adafruit HMC5883L Breakout (http://www.adafruit.com/products/1746), and is based on Adafruit's Unified Sensor Library (Adafruit_Sensor).

About the HMC5883

The HMC5883L is a digital (I2C) compass (magnetometer). The magnetometer measure magnetic force, which is useful to detect magnetic north.

More information on the HMC5883L can be found in the datasheet: http://www.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf

What is the Adafruit Unified Sensor Library?

The Adafruit Unified Sensor Library (Adafruit_Sensor) provides a common interface and data type for any supported sensor. It defines some basic information about the sensor (sensor limits, etc.), and returns standard SI units of a specific type and scale for each supported sensor type.

It provides a simple abstraction layer between your application and the actual sensor HW, allowing you to drop in any comparable sensor with only one or two lines of code to change in your project (essentially the constructor since the functions to read sensor data and get information about the sensor are defined in the base Adafruit_Sensor class).

This is imporant useful for two reasons:

1.) You can use the data right away because it's already converted to SI units that you understand and can compare, rather than meaningless values like 0..1023.

2.) Because SI units are standardised in the sensor library, you can also do quick sanity checks working with new sensors, or drop in any comparable sensor if you need better sensitivity or if a lower cost unit becomes available, etc.

Light sensors will always report units in lux, gyroscopes will always report units in rad/s, etc. ... freeing you up to focus on the data, rather than digging through the datasheet to understand what the sensor's raw numbers really mean.

About this Driver

Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Kevin (KTOWN) Townsend for Adafruit Industries.

adafruit_hmc5883_unified's People

Contributors

caternuson avatar driverblock avatar evaherrada avatar ladyada avatar microbuilder avatar tdicola avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_hmc5883_unified's Issues

Value doesn't change

Used this library with a HMc5883L board but it always shows the same.
I have no option to set the i2c bus pins

Incorrect Z scale factor on +/- 4.7G range

In Adafruit_HMC5883_Unified::setMagGain() the Z scale factor for the +/- 4.7 G range is set as 255
This seems to be a typo - it should be something like 355

This also brings up the question of why XY and Z axes have different scale factors. The data sheet says nothing about this and the scale factors in the data sheet are not the same as in the code. Has the author of the code done their own calibration ? Or is the code for an earlier version of the chip?

error compiling for esp32 in arduino ide

  • Arduino board: ESP32-WROOM-32

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.19

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): here is a log of the compilation error:
    C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp: In member function 'void Adafruit_HMC5883_Unified::read()': C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:112:60: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6, true); ^ In file included from C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:38: C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)' uint8_t requestFrom(int address, int size, int sendStop); ^~~~~~~~~~~ C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:122:12: note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)' size_t requestFrom(uint8_t address, size_t len, bool stopBit); ^~~~~~~~~~~ C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:112:60: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6, true); ^ In file included from C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:38: C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)' uint8_t requestFrom(int address, int size, int sendStop); ^~~~~~~~~~~ C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:121:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint16_t, uint8_t, uint8_t)' uint8_t requestFrom(uint16_t address, uint8_t size, uint8_t sendStop); ^~~~~~~~~~~ C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:112:60: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6, true); ^ In file included from C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:38: C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)' uint8_t requestFrom(int address, int size, int sendStop); ^~~~~~~~~~~ C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:120:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint16_t, uint8_t, bool)' uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop); ^~~~~~~~~~~ C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:112:60: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6, true); ^ In file included from C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:38: C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)' uint8_t requestFrom(int address, int size, int sendStop); ^~~~~~~~~~~ C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:119:12: note: candidate 2: 'size_t TwoWire::requestFrom(uint16_t, size_t, bool)' size_t requestFrom(uint16_t address, size_t size, bool sendStop); ^~~~~~~~~~~ C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:112:60: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6, true); ^ In file included from C:\Users\danda\OneDrive\Documents\Arduino\libraries\Adafruit_HMC5883_Unified-1.2.2\Adafruit_HMC5883_U.cpp:38: C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)' uint8_t requestFrom(int address, int size, int sendStop); ^~~~~~~~~~~ C:\Users\danda\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire\src/Wire.h:124:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)' uint8_t requestFrom(uint8_t address, uint8_t size, uint8_t sendStop); ^~~~~~~~~~~

The "begin" function always returns TRUE

This function apparently means to detect whether an HMC5883 device is detected, and if no device is detected, to trigger the "Ooops, no HMC5883 detected ... Check your wiring!" message in the Adafruit sensor initialization example code. It does not. As written, the function must always returns TRUE.

bool Adafruit_HMC5883_Unified::begin()
{
  // Enable I2C
  Wire.begin();

  // Enable the magnetometer
  write8(HMC5883_ADDRESS_MAG, HMC5883_REGISTER_MAG_MR_REG_M, 0x00);

  // Set the gain to a known level
  setMagGain(HMC5883_MAGGAIN_1_3);

  return true;
}

Missing gain setting (0.88 G)

The code does not support the 0.88 G setting.
I've added it myself and it seems to work.
Is there a reason it's missing?

No need to wait for Wire.available().

After Wire.requestFrom() there is not need to wait for data like this : "while (Wire.available() < 6);".
When the Wire.requestFrom() returns, the I2C transmission has completely finished.

There is also a Wire.endTransmission() after a Wire.requestFrom(), that Wire.endTransmission() does not belong there.

A test for the return value of Wire.endTransmission can be used to detect if the device is detected. Also the return value of Wire.requestFrom can be tested to detect a collision in a multi-Master bus.

Missing file

Need help to fix this problem.
The file "magsensor.ino" exists and so does the file "Adafruit_Sensor.h"

Here is the console log for the problem

C:\Users\Administrator\Desktop\Adafruit_HMC5883_Unified-master\examples\magsensor\magsensor.ino:33:29: fatal error: Adafruit_Sensor.h: No such file or directory

#include <Adafruit_Sensor.h>

                         ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

Description of functions?

Is there a description of the functions of this library besides the example? I appreciate your effort creating this library, but there should be a description of what the functions are in a readme file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.