Git Product home page Git Product logo

hmc5883l-gy-273's Introduction

HMC5883L-GY-273

mbed OS 5 library for 3 Axis Compass HMC5883L Module GY-273

Description

The GY-273 module is based on the Honeywell HMC5883L (datasheet)IC for low-field magnetic sensing with a digital interface for applications such as lowcost compassing and magnetometry. The Mbed board communicates with the sensor using I2C protocol and also uses a digital input (drdy) to know when the sensor is ready

For more information about the module.

Usage

  • Connect the module to the board
    VCC -> VCC (3.3V)

    GND -> GND

    SCL -> SCL e.g. D14

    SDA -> SDA e.g. D15

    DRDY -> Digital input e.g. D2
  • Load a program using the library.

Hereafter is an example program that uses the library:

#include "mbed.h"
#include "mbed_config.h"
#include "logging.h"
#include "HMC5883L.h"

DigitalOut led1(LED1);
I2C i2c(I2C_SDA, I2C_SCL);
InterruptIn drdy(D2);
HMC5883L compass(i2c, drdy);

// main() runs in its own thread in the OS
int main() {
	LOG_DEBUG("HELLO - I am a compass")
	compass.setUp();
	LOG_DEBUG_HEXADECIMAL_VALUE("REG A", compass.getConfigurationA())
	LOG_DEBUG_HEXADECIMAL_VALUE("REG B", compass.getConfigurationB())
	LOG_DEBUG_HEXADECIMAL_VALUE("mode", compass.getMode())
	compass.run();
	int16_t data[3];
	LOG_DEBUG("ABOUT TO START")
	while (true) {
		led1 = !led1;
		if (compass.getRawXZY(data) == SUCCEEDED) {
			LOG_DEBUG("Compass values - SUCCESS")
			LOG_DEBUG_INTEGER_VALUE("X", data[0])
			LOG_DEBUG_INTEGER_VALUE("Y", data[2])
			LOG_DEBUG_INTEGER_VALUE("Z", data[1])
			LOG_DEBUG_DOUBLE_VALUE("XY", compass.getHeadingXYDeg())
			LOG_DEBUG_DOUBLE_VALUE("YZ", compass.getHeadingYZDeg())
			LOG_DEBUG_DOUBLE_VALUE("ZX", compass.getHeadingZXDeg())

		} else {
			LOG_DEBUG("Compass values - FAILURE")
		}
		wait(2);
	}
}

hmc5883l-gy-273's People

Contributors

acabarbaye avatar

Stargazers

 avatar

Watchers

 avatar

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.