GithubHelp home page GithubHelp logo

patronne / lsm303dlh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pololu/lsm303dlh-arduino

0.0 1.0 0.0 89 KB

Arduino library for the Pololu LSM303DLH carrier board (deprecated; replaced by https://github.com/pololu/LSM303)

Home Page: http://www.pololu.com/catalog/product/1250

License: Other

lsm303dlh's Introduction

Arduino library for the Pololu LSM303DLH carrier board

Version: 1.1.1
Release Date: 2011-09-14
www.pololu.com

This library is deprecated; you should use the newer Pololu LSM303 library instead, which also supports the LSM303DLM.

Summary

This is a library for the Arduino that interfaces with the Pololu LSM303DLH 3D compass and accelerometer carrier. It makes it simple to read the raw accelerometer and magnetometer data, and it has a function for computing the tilt-compensated heading for those looking to use this sensor as a tilt-compensated compass.

Getting Started

Software

Download the archive from GitHub, decompress it, and drag the “LSM303DLH” folder to your arduino-00xx/libraries directory. Then restart the Arduino environment, so the libraries can be updated to include the LSM303DLH library and its examples.

Hardware

The board for the LSM303DLH can be purchased on Pololu’s website.

Make the following connections with wires between the Arduino and the LSM303DLH:

Arduino Uno/Duemilanove     LSM303DLH Carrier
                    5V  ->  VIN
                   GND  ->  GND
          Analog Pin 5  ->  SCL
          Analog Pin 4  ->  SDA
Arduino Mega                LSM303DLH Carrier
                    5V  ->  VIN
                   GND  ->  GND
         Analog Pin 21  ->  SCL
         Analog Pin 20  ->  SDA

Example Programs

Open an example code sketch by selecting File→Examples→LSM303DLH→example_name

Serial

This program continuously reads the accelerometer and magnetometer, communicating the readings over the serial interface. You can display the readings with the Arduino Serial Monitor.

Example output:

A X: -151 Y: 848 Z: -509 M X: 281 Y: -442 Z: 87
A X: -147 Y: 847 Z: -509 M X: 266 Y: -446 Z: 78
A X: -147 Y: 849 Z: -508 M X: 280 Y: -450 Z: 81

Calibrate

This program is similar to the Serial example, but instead of printing the most recent readings, it prints a running minimum and maximum of the readings from each magnetometer axis. These values can be used to calibrate the heading() functions and the Heading example after moving the LSM303DLH through every possible orientation.

Heading

This program uses readings from the accelerometer and magnetometer to calculate a tilt-compensated compass heading (in degrees relative to the negative Y axis), which is communicated serially and can be displayed with the Arduino Serial Monitor. For the most accurate results, you should replace the values of m_min and m_max assigned in the setup() function with your own values obtained from the Calibrate example.

Library Reference

vector a
The last values read from the accelerometer.
vector m
The last values read from the magnetometer.
vector m_min
Lower bounds (minimum values) for the magnetometer readings on each axis; set this appropriately to calibrate heading().
vector m_max
Upper bounds (maximum values) for the magnetometer readings on each axis; set this appropriately to calibrate heading().
LSM303DLH(void)
Constructor; initializes m_min and m_max with placeholder values.
void enableDefault(void)
Turns on the accelerometer and magnetometer in the default configuration. (This function was previously called enable().)
void writeAccReg(byte reg, byte value)
Writes an accelerometer register with the given value. Register address constants are defined in LSM303DLH.h.
byte readAccReg(byte reg)
Reads an accelerometer register and returns the value read.
void writeMagReg(byte reg, byte value)
Writes a magnetometer register with the given value.
byte readMagReg(byte reg)
Reads a magnetometer register and returns the value read.
void readAcc(void)
Takes a reading from the accelerometer and stores the values in the vector a.
void readMag(void)
Takes a reading from the magnetometer and stores the values in the vector m.
void read(void)
Takes a reading from both the accelerometer and magnetometer and stores the values in the vectors a and m.
int heading(void)
Returns the tilt-compensated heading in degrees headed away from the negative Y axis.
int heading(vector from)
Returns the tilt-compensated heading in degrees headed away from the from vector.

lsm303dlh's People

Contributors

ryantm avatar kevin-pololu 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.