mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
Some checks failed
JavaScript code lint and formatting with Biome / eslint (push) Has been cancelled
Check code formatting / code-formatting (push) Has been cancelled
Check spelling with codespell / codespell (push) Has been cancelled
Build docs / build (push) Has been cancelled
Check examples / embedding (push) Has been cancelled
Package mpremote / build (push) Has been cancelled
.mpy file format and tools / test (push) Has been cancelled
Build ports metadata / build (push) Has been cancelled
alif port / build_alif (alif_ae3_build) (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / build_idf (esp32_build_c2_c6) (push) Has been cancelled
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Has been cancelled
esp32 port / build_idf (esp32_build_s3_c3) (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
mimxrt port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu port / build_and_test_arm (bigendian) (push) Has been cancelled
qemu port / build_and_test_arm (sabrelite) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_hardfp) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_softfp) (push) Has been cancelled
qemu port / build_and_test_rv32 (push) Has been cancelled
qemu port / build_and_test_rv64 (push) Has been cancelled
renesas-ra port / build_renesas_ra_board (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_stm32 (stm32_misc_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_nucleo_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_pyb_build) (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / standard_v2 (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / longlong (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / gil_enabled (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / repr_b (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
unix port / sanitize_address (push) Has been cancelled
unix port / sanitize_undefined (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, true, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, true, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled
This commit adds `Sensor.attr_set()` and `Sensor.attr_get_*()` methods that are necessary to set various sensor attributes if they haven't been set statically in the device tree. This is needed, for example, because the LSM6DS3TR-C sensor on the XIAO BLE NRF52840 SENSE board will not work with `zsensor` because it doesn't have any default configuration for sampling frequency. Various `SENSOR_ATTR_*` constants from `zephyr/incude/zephyr/drivers/sensor.h` have been added as `ATTR_*` constants in the `zsensor` module. Signed-off-by: Ned Konz <ned@metamagix.tech>
235 lines
6.1 KiB
ReStructuredText
235 lines
6.1 KiB
ReStructuredText
.. currentmodule:: zsensor
|
|
|
|
:mod:`zsensor` --- Zephyr sensor bindings
|
|
=========================================
|
|
|
|
.. module:: zsensor
|
|
:synopsis: zephyr sensor bindings
|
|
|
|
The ``zsensor`` module contains a class for using sensors with Zephyr.
|
|
|
|
.. _zsensor.Sensor:
|
|
|
|
class Sensor --- sensor control for the Zephyr port
|
|
---------------------------------------------------
|
|
|
|
Use this class to access data from sensors on your board.
|
|
See Zephyr documentation for sensor usage here: `Sensors
|
|
<https://docs.zephyrproject.org/latest/reference/peripherals/sensor.html?highlight=sensor#sensors>`_.
|
|
|
|
Sensors are defined in the Zephyr devicetree for each board. The quantities that a given sensor can
|
|
measure are called a sensor channels. Sensors can have multiple channels to represent different axes
|
|
of one property or different properties a sensor can measure. See `Channels`_ below for defined sensor
|
|
channels. Each channel may have multiple attributes that can be changed and/or queried.
|
|
See `Channel Attributes`_ below for defined sensor channel attributes.
|
|
|
|
Constructor
|
|
~~~~~~~~~~~
|
|
|
|
.. class:: Sensor(device_name)
|
|
|
|
Device names are defined in the devicetree for your board.
|
|
For example, the device name for the accelerometer in the FRDM-k64f board is "FXOS8700".
|
|
|
|
Methods
|
|
~~~~~~~
|
|
|
|
.. method:: Sensor.measure()
|
|
|
|
Obtains a measurement sample from the sensor device using Zephyr sensor_sample_fetch and
|
|
stores it in an internal driver buffer as a useful value, a pair of (integer part of value,
|
|
fractional part of value in 1-millionths).
|
|
Returns none if successful or OSError value if failure.
|
|
|
|
.. method:: Sensor.get_float(sensor_channel)
|
|
|
|
Returns the value of the sensor measurement sample as a float.
|
|
|
|
.. method:: Sensor.get_micros(sensor_channel)
|
|
|
|
Returns the value of the sensor measurement sample in millionths.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1500000``)
|
|
|
|
.. method:: Sensor.get_millis(sensor_channel)
|
|
|
|
Returns the value of sensor measurement sample in thousandths.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1500``)
|
|
|
|
.. method:: Sensor.get_int(sensor_channel)
|
|
|
|
Returns only the integer value of the measurement sample.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1``)
|
|
|
|
.. method:: Sensor.attr_set(sensor_channel, channel_attribute, val1, [val2])
|
|
|
|
Set the given channel's attribute to the given value.
|
|
``val1`` may be a float, in which case ``val2`` is not given, or
|
|
``val1`` can be used for the value's
|
|
integer part and ``val2`` for the value's fractional part in millionths.
|
|
|
|
Returns ``None`` if successful, or raises ``OSError``.
|
|
|
|
.. method:: Sensor.attr_get_float(sensor_channel, channel_attribute)
|
|
|
|
Returns the value of the sensor channel's attribute as a float.
|
|
|
|
Many sensors do not support this or any other of the ``attr_get`` methods.
|
|
|
|
.. method:: Sensor.attr_get_micros(sensor_channel, channel_attribute)
|
|
|
|
Returns the value of the sensor channel's attribute in millionths.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1500000``)
|
|
|
|
.. method:: Sensor.attr_get_millis(sensor_channel, channel_attribute)
|
|
|
|
Returns the value of the sensor channel's attribute in thousandths.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1500``)
|
|
|
|
.. method:: Sensor.attr_get_int(sensor_channel, channel_attribute)
|
|
|
|
Returns only the integer value of the channel's attribute.
|
|
(Ex. value of ``(1, 500000)`` returns as ``1``)
|
|
|
|
Channels
|
|
~~~~~~~~
|
|
|
|
.. data:: ACCEL_X
|
|
|
|
Acceleration on the X axis, in m/s^2.
|
|
|
|
.. data:: ACCEL_Y
|
|
|
|
Acceleration on the Y axis, in m/s^2.
|
|
|
|
.. data:: ACCEL_Z
|
|
|
|
Acceleration on the Z axis, in m/s^2.
|
|
|
|
.. data:: ACCEL_XYZ
|
|
|
|
Pseudo-channel representing all three accelerometer axes.
|
|
Used for :meth:`Sensor.attr_set` and the ``Sensor.attr_get_xxx()`` methods.
|
|
|
|
.. data:: GYRO_X
|
|
|
|
Angular velocity around the X axis, in radians/s.
|
|
|
|
.. data:: GYRO_Y
|
|
|
|
Angular velocity around the Y axis, in radians/s.
|
|
|
|
.. data:: GYRO_Z
|
|
|
|
Angular velocity around the Z axis, in radians/s.
|
|
|
|
.. data:: GYRO_XYZ
|
|
|
|
Pseudo-channel representing all three gyroscope axes.
|
|
Used for :meth:`Sensor.attr_set` and the ``Sensor.attr_get_xxx()`` methods.
|
|
|
|
.. data:: MAGN_X
|
|
|
|
Magnetic field on the X axis, in Gauss.
|
|
|
|
.. data:: MAGN_Y
|
|
|
|
Magnetic field on the Y axis, in Gauss.
|
|
|
|
.. data:: MAGN_Z
|
|
|
|
Magnetic field on the Z axis, in Gauss.
|
|
|
|
.. data:: DIE_TEMP
|
|
|
|
Device die temperature in degrees Celsius.
|
|
|
|
.. data:: PRESS
|
|
|
|
Pressure in kilopascal.
|
|
|
|
.. data:: PROX
|
|
|
|
Proximity. Dimensionless. A value of 1 indicates that an object is close.
|
|
|
|
.. data:: HUMIDITY
|
|
|
|
Humidity, in percent.
|
|
|
|
.. data:: LIGHT
|
|
|
|
Illuminance in visible spectrum, in lux.
|
|
|
|
.. data:: ALTITUDE
|
|
|
|
Altitude, in meters.
|
|
|
|
Channel Attributes
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. data:: ATTR_SAMPLING_FREQUENCY
|
|
|
|
Sensor sampling frequency, i.e. how many times a second the sensor takes a measurement.
|
|
|
|
.. data:: ATTR_LOWER_THRESH
|
|
|
|
Lower threshold for trigger.
|
|
|
|
.. data:: ATTR_UPPER_THRESH
|
|
|
|
Upper threshold for trigger.
|
|
|
|
.. data:: ATTR_SLOPE_TH
|
|
|
|
Threshold for any-motion (slope) trigger.
|
|
|
|
.. data:: ATTR_SLOPE_DUR
|
|
|
|
Duration for which the slope values needs to be outside the threshold for the trigger to fire.
|
|
|
|
.. data:: ATTR_HYSTERESIS
|
|
|
|
.. data:: ATTR_OVERSAMPLING
|
|
|
|
Oversampling factor.
|
|
|
|
.. data:: ATTR_FULL_SCALE
|
|
|
|
Sensor range, in SI units.
|
|
|
|
.. data:: ATTR_OFFSET
|
|
|
|
The sensor value returned will be altered by the amount indicated by offset: final_value = sensor_value + offset.
|
|
|
|
.. data:: ATTR_CALIB_TARGET
|
|
|
|
Calibration target. This will be used by the internal chip's algorithms to calibrate itself on a certain axis, or all of them.
|
|
|
|
.. data:: ATTR_CONFIGURATION
|
|
|
|
Configure the operating modes of a sensor.
|
|
|
|
.. data:: ATTR_CALIBRATION
|
|
|
|
Set a calibration value needed by a sensor.
|
|
|
|
.. data:: ATTR_FEATURE_MASK
|
|
|
|
Enable/disable sensor features.
|
|
|
|
.. data:: ATTR_ALERT
|
|
|
|
Alert threshold or alert enable/disable.
|
|
|
|
.. data:: ATTR_FF_DUR
|
|
|
|
Free-fall duration represented in milliseconds.
|
|
If the sampling frequency is changed during runtime, this attribute should be set to adjust freefall duration to the new sampling frequency.
|
|
|
|
.. data:: ATTR_BATCH_DURATION
|
|
|
|
Hardware batch duration in ticks.
|
|
|
|
.. data:: ATTR_GAIN
|
|
|
|
.. data:: ATTR_RESOLUTION
|