tmf882x-driver
Easy-to-use python driver for the AMS TMF8820 and TMF8821 ToF sensors
Installation
The package is available on PyPI. Installation is can be done with your favourite package manager. For example:
pip install tmf882x-driver
Usage
In order to initialise the device we need an open SMBus object.
Depending on the machine that you are running on you may need to provide another bus number or path:
from smbus2 import SMBus
from tmf882x import TMF882x
with SMBus(1) as bus:
device = TMF882x(bus=bus)
The address of the TMF882x defaults to 0x41. If your device's address is different, you can provide it
like TMF882x(bus=bus, address=0x59).
When powering up, the device is in standby mode. To enable it, call device.enable(), and subsequently
put it back in standby using device.standby(). Or better yet, use a context manager:
with device:
pass # Here the device is enabled.
Measuring
To make a measurement, do:
with device:
measurement = device.measure()
This will yield a TMF882xMeasurement, which has (among others) the following fields:
result_number, an incremental counter for deduplicating results,temperature, the device's temperature in degrees C.ambient_light, a measure for the ambient light,photon_count, the number of photons measured.results, a list of SPAD results.
The property measurement.grid will returns a list-of-list of results,
representing the actual arrangement of SPADs. Each result has a confidence (the confidence of measurement, 255 is absolutely sure, 0 when no result)
and a distance in mm (0 when no result), as well as a secondary_confidence and secondary_distance for a secondary object.
The measurement also has primary_grid and secondary_grid properties which return list-of-list-of-ints of the primary
and secondary distances.
For example:
with device:
print(device.measure().primary_grid)
might yield [[0, 169, 196], [131, 197, 240], [192, 214, 199], [256, 210, 190], [185, 183, 165], [182, 185, 169]].
Configuration
The following configuration options are implemented:
measurement_period, the measurement period in ms (default = 33)kilo_iterations, number of measurement iterations x 1024 (default = 537, representing 549888 iterations)confidence_threshold, confidence threshold below which measurements are 0 (default = 6, max = 255).spad_map, defining the configuration of SPADs (see below).
To get / set a configuration field, do for example:
with device:
print(device.measurement_period)
device.spad_map = 6
SPAD maps
For a full list of pre-programmed SPAD Maps, see page 23 of this document, but a few useful ones are:
1: normal 3x3,6: wide 3x3,7: normal 4x4 (TMF8821 only),10: 3x6 (TMF8821 only).
Calibration
The device is supposed to be calibrated before use.
The calibration test shall be done in the final housing with minimal ambient light and no target within 40 cm in field of view of the device. The calibration generates a calibration data set, which should be permanently stored on the host.
The calibration data can be loaded after power-up using the write_calibration method. Note that the calibration data is tied to the spad map. Any change in spad map requires re-calibration (and/or loading of other calibration data).
For example:
with device:
calibration_data = device.calibrate()
And to restore:
with device:
device.write_calibration(calibration_data)
After a measurement, you can check the calibration_ok property to see whether calibration was successful.
References
See the datasheet and the communication note for more details.
Metadata
Release files for tmf882x-driver 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tmf882x_driver-0.2.0.tar.gz | 14.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tmf882x_driver-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.2 kB
Release files / tmf882x_driver-0.2.0.tar.gz
| Download URL | tmf882x_driver-0.2.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7aff4fb53d183233663670de5fdfc552a30ed88e6281e1a4cd249c50732259c6
|
|
BLAKE2b-256 checksum How to use checksums |
1cf6f3ab7fb283a5b647fbc1ac4d5d8091177871681633e9ca0c2297a9b766f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / tmf882x_driver-0.2.0-py3-none-any.whl
| Download URL | tmf882x_driver-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83924421a6157fdc8a5bfe337e44d0ca85227e65696c039b3941c4378881bcee
|
|
BLAKE2b-256 checksum How to use checksums |
4cc8358ade5cc4e62dd804507d77cc8c488072f0e5c32939e07d1e80b001538f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for tmf882x-driver 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.