Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tuupola/micropython-lis2hh12
MicroPython I2C driver for LIS2HH12 3-axis accelerometer
https://github.com/tuupola/micropython-lis2hh12
esp32 micropython
Last synced: about 1 month ago
JSON representation
MicroPython I2C driver for LIS2HH12 3-axis accelerometer
- Host: GitHub
- URL: https://github.com/tuupola/micropython-lis2hh12
- Owner: tuupola
- License: mit
- Created: 2017-09-27T21:44:13.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T08:32:34.000Z (10 months ago)
- Last Synced: 2024-05-01T22:03:54.049Z (8 months ago)
- Topics: esp32, micropython
- Language: Python
- Size: 13.7 KB
- Stars: 9
- Watchers: 4
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-mpython - micropython-lis2hh12 - LIS2HH12 3轴加速度计 (精选驱动库 / 传感器)
- awesome-micropython - micropython-lis2hh12 - I2C driver for LIS2HH12 3-axis accelerometer. (Libraries / Sensors)
README
# MicroPython LIS2HH12 I2C driver
MicroPython library for accessing the [STMicroelectronics LIS2HH12](http://www.st.com/en/mems-and-sensors/lis2hh12.html) 3-axis accelerometer over
I2C. The LIS2HH12 is an ultra-low-power high-performance three-axis linear accelerometer belonging to the “pico” family. It has full scales of ±2g/±4g/±8g and is capable of measuring accelerations with output data rates from 10 Hz to 800 Hz.## Usage
Simple test with never ending loop.
```python
import utime
from machine import I2C, Pin
from lis2hh12 import LIS2HH12i2c = I2C(scl=Pin(26), sda=Pin(25))
sensor = LIS2HH12(i2c)print("LIS2HH12 id: " + hex(sensor.whoami))
while True:
print(sensor.acceleration)
utime.sleep_ms(1000)
```By default the library returns 3-tuple of X, Y, Z axis acceleration values in m/s^2 which is the SI standard. To get the acceleration values in g instead set the scale factor to `SF_G` in the constructor.
```python
from machine import I2C, Pin
from lis2hh12 import LIS2HH12, SF_Gi2c = I2C(scl=Pin(26), sda=Pin(25))
sensor = LIS2HH12(i2c, sf=SF_G)
```More realistic example usage with timer. If you get `OSError: 26` or `i2c driver install error` after soft reboot do a hard reboot.
```python
import micropython
from machine import I2C, Pin, Timer
from lis2hh12 import LIS2HH12micropython.alloc_emergency_exception_buf(100)
i2c = I2C(scl=Pin(26), sda=Pin(25))
sensor = LIS2HH12(i2c)def read_sensor(timer):
print(sensor.acceleration)print("LIS2HH12 id: " + hex(sensor.whoami))
timer_0 = Timer(0)
timer_0.init(period=1000, mode=Timer.PERIODIC, callback=read_sensor)
```## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.