Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackw01/lsm303-python
Python library for the LSM303 I2C accelerometer/magnetometer
https://github.com/jackw01/lsm303-python
Last synced: about 5 hours ago
JSON representation
Python library for the LSM303 I2C accelerometer/magnetometer
- Host: GitHub
- URL: https://github.com/jackw01/lsm303-python
- Owner: jackw01
- License: mit
- Created: 2020-09-07T20:55:13.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-11T23:17:22.000Z (about 4 years ago)
- Last Synced: 2024-09-19T00:27:29.471Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```python
import time
import smbus
import lsm303i2c_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)
```