Skip to main content

Python library for the LSM303 I2C accelerometer/magnetometer

Project description

lsm303d-python

Python library for the LSM303D I2C accelerometer/magnetometer

Usage

  1. Install the Python smbus module for your platform (sudo apt install python-smbus for Debian or Ubuntu Linux)
  2. pip install lsm303-python
  3. sudo lsm303_test

Example Code

import time
import smbus
import lsm303

i2c_channel = 1
bus = smbus.SMBus(i2c_channel)

# Will raise OSError if device is not connected
device = lsm303.LSM303(bus)

while True:
    # Returns x,y,z tuple with values in degrees/second
    accel_data = device.read_accel()
    # Returns x,y,z tuple with values in microtesla
    mag_data = device.read_mag()
    print(
        [round(v, 2) for v in accel_data],
        [round(v, 2) for v in mag_data]
    )
    time.sleep(0.1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsm303-python-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file lsm303-python-1.0.0.tar.gz.

File metadata

  • Download URL: lsm303-python-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2

File hashes

Hashes for lsm303-python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c34ecc62d7d048ddb17d9a0b66934f0f64e137ed89a39e5836d8af405c0685fe
MD5 90b95d4120b263d1c421c9a67b1a8e63
BLAKE2b-256 7fe054fc14479c95532ae33e4a3f5eef61e48eeb3e352565a63ed8b4c0d3baa7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page