This library is archived and no longer supported

This library has been split into separate libararies for the magnetometer and accelerometer. The accelerometer code will be shared with another version of the LSM303 that uses the same accelerometer but not the magnetometer and this repo will be archived.

This library will no longer be supported. Please us the new libraries

The new, split libraries

https://github.com/adafruit/Adafruit_CircuitPython_LSM303_Accel

https://github.com/adafruit/Adafruit_CircuitPython_LSM303DLH_Mag

The library for the new magnetometer

https://github.com/adafruit/Adafruit_CircuitPython_LSM303AGR_Mag

You can find usage information for the new libraries in the sensor’s guide:

https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout/python-circuitpython

Introduction

Documentation Status Discord Build Status

Adafruit CircuitPython module for the LSM303 6-DoF with 3-axis accelerometer and magnetometer

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-lsm303

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-lsm303

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-lsm303

Usage Example

import time
import board
import busio

import adafruit_lsm303

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm303.LSM303(i2c)

while True:
        raw_accel_x, raw_accel_y, raw_accel_z = sensor.raw_acceleration
        accel_x, accel_y, accel_z = sensor.acceleration
        raw_mag_x, raw_mag_y, raw_mag_z = sensor.raw_magnetic
        mag_x, mag_y, mag_z = sensor.magnetic

        print('Acceleration raw: ({0:6d}, {1:6d}, {2:6d}), (m/s^2): ({3:10.3f}, {4:10.3f}, {5:10.3f})'.format(raw_accel_x, raw_accel_y, raw_accel_z, accel_x, accel_y, accel_z))
        print('Magnetometer raw: ({0:6d}, {1:6d}, {2:6d}), (gauss): ({3:10.3f}, {4:10.3f}, {5:10.3f})'.format(raw_mag_x, raw_mag_y, raw_mag_z, mag_x, mag_y, mag_z))
        print('')
        time.sleep(1.0)

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Examples

Indices and tables