Skip to content

Zephyr/zsensor: Add sensor attribute set/get methods. #17653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bikeNomad
Copy link
Contributor

Summary

This PR adds zsensor.Sensor.attr_set() and zsensor.Sensor.attr_get() methods that are
necessary to set various sensor attributes if they haven't been set statically in the device tree.

I needed this because the LSM6DS3TR-C sensor in my XIAO BLE NRF52840 SENSE board wouldn't
work with zsensor because it didn't have any default configuration for sampling frequency.

I added the various SENSOR_ATTR_* constants from zephyr/incude/zephyr/drivers/sensor.h as
ATTR_* constants in zsensor.

I also added the below test script to the README.md.

Testing

Here is a test script that I ran on my board:

    from zsensor import *
    sensor = Sensor('lsm6ds3tr_c')  # name from Devicetree
    # Set full-scale to 2g (19.613300 m/sec^2)
    # units are micro-m/s^2
    sensor.attr_set(ACCEL_XYZ, ATTR_FULL_SCALE, 19, 613300)
    # Set sampling frequency to 104 Hz
    sensor.attr_set(ACCEL_XYZ, ATTR_SAMPLING_FREQUENCY, 104)
    sensor.measure()
    sensor.get_float(ACCEL_X) # -0.508 (m/s^2)
    sensor.get_float(ACCEL_Y) # -3.62 (m/s^2)
    sensor.get_float(ACCEL_Z) # 9.504889 (m/s^2)

Trade-offs and Alternatives

This adds a small amount of code size to the zsensor module; the whole module may be eliminated
by not #defining MICROPY_PY_ZSENSOR.

Signed-off-by: Ned Konz <ned@metamagix.tech>
@bikeNomad bikeNomad force-pushed the zephyr/add-attr-set-and-get-to-zsensor branch from bfaf78f to 99e7ba7 Compare July 10, 2025 00:55
Signed-off-by: Ned Konz <ned@metamagix.tech>
Signed-off-by: Ned Konz <ned@metamagix.tech>
@bikeNomad
Copy link
Contributor Author

I don't know why commit 99e7ba7 failed the signed-off test, as I did sign it (using git gui rather than command-line git).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy