adafruit / adafruit_circuitpython_lsm6ds Goto Github PK
View Code? Open in Web Editor NEWCircuitPython helper library for the LSM6DS family of motion sensors from ST
License: MIT License
CircuitPython helper library for the LSM6DS family of motion sensors from ST
License: MIT License
Hello! When I updated to current version, I am unable to import adafruit_lsm6ds
. However, if I uninstall it and load a previous version with pip install adafruit-circuitpython-lsm6ds==3.0.2
, I can now import it. Am I missing something with version 4?
This fails for me on the current macOS and Ubuntu 20.04 using python 3.8.
Re this thread:
https://forums.adafruit.com/viewtopic.php?f=19&t=164655
And my testing:
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Metro M0 Express with samd21g18
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 4, in <module>
File "adafruit_lsm6ds.py", line 188, in <module>
File "adafruit_lsm6ds.py", line 217, in LSM6DS
MemoryError: memory allocation failed, allocating 184 bytes
See banner below for CP version and HW. All libraries from bundle release 2020-02-18.
Adafruit CircuitPython 5.0.0-beta.5 on 2020-02-05; Adafruit CLUE nRF52840 Express with nRF52840
>>> import board
>>> import adafruit_lsm6ds
>>> lsm = adafruit_lsm6ds.LSM6DS33(board.I2C())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "adafruit_lsm6ds.py", line 225, in __init__
File "adafruit_lsm6ds.py", line 237, in reset
File "adafruit_register/i2c_bit.py", line 70, in __set__
File "adafruit_register/i2c_bit.py", line 70, in __set__
File "adafruit_bus_device/i2c_device.py", line 99, in write
TypeError: can't convert NoneType to int
>>>
Hi,
While trying to run the example code on my Raspberry Pi 4 [model B]
SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
SPDX-License-Identifier: MIT
import time
import board
import busio
from adafruit_lsm6ds.lsm6ds33 import LSM6DS33i2c = busio.I2C(board.SCL, board.SDA)
sensor = LSM6DS33(i2c)
while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
print("")
time.sleep(0.5)
I got an ValueError : No I2C debice at address: 6a
I know there is a way to change the I2C address to 6b with the SD0 pin, but i wanted to free this pin for future expansion [maybe connecting two LSM6DS33's to the same Pi].
Is there a way to tell my Pi to read from this specific address?
Thank you (:
I'm trying to import the library on CircuitPython for the LSM6DSOX, but it keeps throwing an error on this line:
>>> from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name LSM6DSOX
The first time I ran it, it gave me a different error:
'ImportError: no module named 'adafruit_lsm6ds.LSM6DS'
but now it throws the first one every time.
This is running on the Arduino Nano RP2040 Connect using CircuitPython 7.0.0. I'm using the Mu REPL to communicate. I have the libraries loaded to the lib/ folder in .MPY format.
The same behavior happens when trying to import from any of the LSM6DS modules. The problem is not with the REPL, because I can blink the led just fine, and I can also use other libraries.
This is my first issue, so I apologize if the formatting is off.
Add a Basic DisplayIO Based Example
We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.
The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.
The new example should follow the naming convention examples/libraryname_displayio_simpletest.py
with "libraryname" being replaced by the actual name of this library.
You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72
We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github
If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord
The MicroPython driver for the LSM6DOX has example for using ST's Machine Learning Core configurations for detecting certain types of motions.
https://github.com/micropython/micropython/blob/master/drivers/lsm6dsox/lsm6dsox_mlc.py
https://github.com/STMicroelectronics/STMems_Machine_Learning_Core/tree/master/application_examples/lsm6dsox
I have tried the vibration and head gesture examples and they are seem to work.
Would there be any interest in adding the ability to load the "ucf" files via the CircuitPython driver.
We won't be able to use the Interrupt MODE, but could poll.
The change to the library would be to add the "load_mlc, read_mlc_output and set_embedded_functions" methods. There actual usage is done in the examples.
Let me know if you think this is worth adding for the lsm6dsox. It may also apply to the lsmds33 but does not appear to be supported on the lsmdso32.
The actions failure with details about duplicated sections is here
We want to avoid having duplicated code if possible. One possible way to fix might be to move duplicate code into a shared super class.
Hi :)
Could you please tell me if you plan to add temperature support for lsm6ds?
_LSM6DS_OUT_TEMP_L is available but not use inside the lib
Cheers,
Hi,
I am trying to run lsm6dsox.py and but I am getting this error.
pi@raspberrypi:~/Adafruit_CircuitPython_LSM6DS/adafruit_lsm6ds $ sudo python3 lsm6dsr.py
Traceback (most recent call last):
File "lsm6dsr.py", line 7, in
from . import LSM6DS, LSM6DS_DEFAULT_ADDRESS, LSM6DS_CHIP_ID
SystemError: Parent module '' not loaded, cannot perform relative import
What does it mean by parent module here? Do i have to run sudo pip3 install Adafruit_CircuitPython_LSM6DS before I run any of the example codes?
The temperature calculation -- all least for the lsm6dsox is not working correctly. Where did it come from?
https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS/blob/main/adafruit_lsm6ds/__init__.py#L402
According to the data sheet - section 4.3 (referenced in the comment to the code) , the temperature is just the raw value divided by the sensitivity with an offset of 25 degrees Celsius.
That is how it is implemented in Arduino
https://github.com/adafruit/Adafruit_LSM6DS/blob/master/Adafruit_LSM6DS.cpp#L468
I tried installing it several times and it wouldn't work. I ended up manually copying the adafruit_lsm6ds folder with all the other files inside from this github into my /usr/local/lib/python3.7/dist-packages/. Now it works.
The minimal example on 6.x below.
import time
import board
import busio
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
i2c = busio.I2C(board.SCL, board.SDA)
sensor = LSM6DSOX(i2c)
Gives the error.
Traceback (most recent call last):
File "main.py", line 42, in <module>
File "adafruit_lsm6ds/lsm6dsox.py", line 22, in __init__
File "adafruit_lsm6ds/__init__.py", line 208, in __init__
AttributeError: 'LSM6DSOX' object has no attribute '__class__'
I have the chip connected correctly since using direct I2C commands I can communicate with it and pull the device code. And changing the SD0
pin changes its address.
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
pass
print(i2c.scan())
i2c.unlock()
Yields
main.py output:
[106]
Code done running.
There are two 10k pullups and pin one is in the top left corner of the image.
Apologies for the horror.
The CircuitPlayground library just did this by reusing the LIS3DH implementation. So maybe this is something that should be added to the LSM6DS library? But starting the conversation here. Since this feature is just math on the x,y,z accelo readings, it's not really hardware specific to the LSM6DS.
Hi,
I've just started using the library and it was really easy to get up and running so good job there!
For my application (datalogger) it is important i read every single reading from the accel exactly once. It is also important if for some reason i miss a reading that I can tell if that has occured.
I think the easiest way to implement this would be to add a flag (or two? one for gyro, one for accel) to the class variables which can be checked before calling sensor.acceleration
or sensor.gyro
. Upon calling those functions the function would set the flag to 0 to indicate no values have changed since last read.
Within the function that gets the data over I2C or handles the update of that data it should update the flag each time adding +1 to it's value. This would mean if say 20 readings were missed the user could easily tell by looking at the flag values.
I considered trying to implement this by say checking values were consistant but this is not reliable as during static portions of my testing I will likely get the same values for a few readings.
I am happy to try help implement this if you think this is a viable route to go but as I am not the most proficient Python programmer I can't for the life of me work out where the function is that gets the raw values over I2C to increment the flag within?
Both the example lsm6ds_pedometer.py and the learn guide https://learn.adafruit.com/clue-step-counter-st-lsm6ds33/overview do fail on trying to get pedometer_steps.
Hello! I have an Adafruit LSM6DS032 board connected by Stemma QT cable to an Adafruit RP2040 Feather, all purchased about a year ago. I've dug them back out for a repeat of a workshop I ran in June last year, where I noticed that the acceleration values were all about double what they should be (Z acceleration on a flat surface was reported as about 19.5G). It didn't matter much to the workshop (just seeing any data was good enough), but I'm curious about it now.
After a peek through the code in this library:
In the LSM6DS032
class, the acceleration ranges override those from the default LSM6DS
values in __init__.py
with doubled max values and doubled conversion factors . If I use the original conversion factors, the output is reasonable. So the code matches the relevant datasheet, but my test suggests the conversion factors are "actually" somehow the same for both the ±16G max chips and the ±32G max chip, which just cannot be true.
I'm now starting to wonder if is possible that my actual board has the wrong chip on it. Is there any easy way to tell if that were the case, short of trying to put >16G's while getting data from the sensor and seeing what happens?
I saw that there is an Arduino SPI library for this device. Are there plans to support SPI for this sensor in python as well?
In the following line, you check for the chip version ID (register is called "WHO_AM_I" in the datasheet):
I designed a PCB with the LSM6DS3TR, but the manufacturer of the PCB has a messed up data bank assembled my PCB with the LSM6DS33.
The error message states that I have a wiring issue. A more appropriate message would be "wrong selected chip class, selected X found y". Or something like that.
That took quite some time to figure the actual error out.
Curious if I am missing it, but I don't think you have enabled access to the on-board temperature sensor. This is available in the Arduino version and you have the correct address in __init__.py
. Could you add this as a property?
BTW: How does this work? In LSM6DS, I can see where you create self.i2c_device(i2c_bus, address)
and I assume you read from that, but you never call a read function in the code??? I was going to just add it myself, but was confused by what you were doing.
Hello
While waiting for the LSM6DSOX to arrive I was looking on the code from Rate.add_values() the Hz values used are: 1.6, 12.5, 26, 52, 104, 208, 416, 833, 1066, 3033, 6066
But in the page 11 of the datasheet the last three values are different: 1666, 3332, 6664
Why are 1066, 3033 and 6066 used in the code?
Thanks
Discord user "Pamz" reported on #circuitpython:
Hi, I am testing Bluefruit feather sense I received couple days ago using this demo code: https://learn.adafruit.com/adafruit-feather-sense/circuitpython-sense-demo
I am watching response in serial. Everything seems to be working, except gyro and acceleration. I get 0 values no mather how much I move it.
default lsm6ds33 accelerometer_data_rate and gyro_data_rate is at 0Hz. If I set it to 1066Hz, it works like a charm, otherwise it is just zeros.
I looked at the code real quick and it looks like it should be setting RATE_104_HZ at startup, so I'll admit to being confused.
I'm not sure if this is related to a comment internally on Slack that there was "some variant of the LSM6DS33 that completely dies when you tell it to reboot", or if that recent mention is just a coincidence.
Hi,
I wanted to know if these libraries would work with LSM6DSR imu or not? Any changes are required in the library to support LSM6DSR?
Looking forward to it.
thanks,
Akshay
Wondering how I can configure this device to fire an interrupt on significant motion, per page 45 of the datasheet (here)?
The goal is to be able to set an alarm in CPy to wake when pin D3 is set high - according to the schematics for the Feather Sense (which I'm developing on), this is the GPIO connected with INT1 on the LSM6DS33.
Something like
pin_alarm = alarm.pin.PinAlarm(pin=board.D3, value=True, pull=True)
alarm.light_sleep_until_alarms(pin_alarm)
The datasheet seems to indicate that setting register 0x0D
on the device to 64 (bin 01000000) will accomplish this.
Thoughts?
The example has this line: from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
, but that produces an error (at least on my raspberry pi 3), "'adafruit_lsm6ds' is not a package". Should that line just be from adafruit_lsm6ds import LSM6DSOX
?
There are missing type annotations for some functions in this library.
The typing
module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:
try:
from typing import List, Tuple
except ImportError:
pass
Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:
def wrap_text_to_pixels(
string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:
If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github
There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs
and Check your code with pre-commit
contain the tools to install and commands to run locally to run the checks.
If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev
channel.
The following locations are reported by mypy to be missing type annotations:
Hi,
I have installed these libraries using "sudo pip3 install adafruit-circuitpython-lsm6ds". I am using default python version is 3.7.4 on Pi 3B+.
I have LSM6DSOX with me and I can run (sudo python3 example_file_name.py) its example successfully and able to see the correct values on Raspbian OS.
However, my main python application is in /usr/bin/xxx.py and I want to integrate the code snippet from the example including libraries to my main .py file and run at boot-up. Its not recognizing these libraries for some reason. I cannot figure out why? Can someone please help me out here with the suggestions and solutions? I'd appreciate that.
Thanks,
Akshay
Based on a quick test with an Adafruit CLUE using the https://github.com/adafruit/Adafruit_CircuitPython_CLUE library which is passthru for gyro value, the gyro return appears to be in degrees per second. The code in the example (and README) also suggest this is the case in the textual description of units: https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS/blob/master/examples/lsm6ds33_simpletest.py#L12
https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html#sensor-properties-and-units specifies gyro
as x, y, z radians per second
(NB: inconsistent with orientation
specification; CP is consistent with C/Arduino spec here for these two values, see https://learn.adafruit.com/using-the-adafruit-unified-sensor-driver/how-does-it-work#standardised-si-units-for-sensor-data-2-2)
Worth independent verification via datasheet or empircally before changing anything here...
The __init__.py
file does not support high-pass filter (HPF) settings for LSM6DSOX sensor. The LSM6DSOX has a different control register configuration compared to other IMU parts supported by this library. This is in register _LSM6DS_CTRL8_XL
.
I've modified the __init__.py
file as a test and it seems to work OK with LSM6DSOX. This is tested using Adafruit STM32F405 Feather and the LSM6DSOX board with a I2C connection. The HPF filters out steady-state (gravity) and passes motions. This file will break the library for other IMU parts. I don't know enough to make this work for all the parts.
init.py.zip
Thanks for this library
Regards,
Bob U.
https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS/blob/main/adafruit_lsm6ds/__init__.py#L118
Probably you have meant
1666 instead of 1066.0
3332 instead of 3033.0
6664 instead of 6066.0
see sensor datasheet
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.