vl53l1x

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: BSD-3-Clause Imports: 3 Imported by: 16

Documentation

Overview

Package vl53l1x provides a driver for the VL53L1X time-of-flight distance sensor

Datasheet: https://www.st.com/resource/en/datasheet/vl53l1x.pdf This driver was based on the library https://github.com/pololu/vl53l1x-arduino and ST's VL53L1X API (STSW-IMG007) https://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img007.html

Index

Constants

View Source
const (
	CHIP_ID                                                 = 0xEACC
	SOFT_RESET                                              = 0x0000
	I2C_SLAVE_DEVICE_ADDRESS                                = 0x0001
	OSC_MEASURED_FAST_OSC_FREQUENCY                         = 0x0006
	VHV_CONFIG_TIMEOUT_MACROP_LOOP_BOUND                    = 0x0008
	VHV_CONFIG_INIT                                         = 0x000B
	ALGO_PART_TO_PART_RANGE_OFFSET_MM                       = 0x001E
	MM_CONFIG_OUTER_OFFSET_MM                               = 0x0022
	DSS_CONFIG_TARGET_TOTAL_RATE_MCPS                       = 0x0024
	PAD_I2C_HV_EXTSUP_CONFIG                                = 0x002E
	GPIO_TIO_HV_STATUS                                      = 0x0031
	SIGMA_ESTIMATOR_EFFECTIVE_PULSE_WIDTH_NS                = 0x0036
	SIGMA_ESTIMATOR_EFFECTIVE_AMBIENT_WIDTH_NS              = 0x0037
	ALGO_CROSSTALK_COMPENSATION_VALID_HEIGHT_MM             = 0x0039
	ALGO_RANGE_MIN_CLIP                                     = 0x003F
	ALGO_CONSISTENCY_CHECK_TOLERANCE                        = 0x0040
	CAL_CONFIG_VCSEL_START                                  = 0x0047
	PHASECAL_CONFIG_TIMEOUT_MACROP                          = 0x004B
	PHASECAL_CONFIG_OVERRIDE                                = 0x004D
	DSS_CONFIG_ROI_MODE_CONTROL                             = 0x004F
	SYSTEM_THRESH_RATE_HIGH                                 = 0x0050
	SYSTEM_THRESH_RATE_LOW                                  = 0x0052
	DSS_CONFIG_MANUAL_EFFECTIVE_SPADS_SELECT                = 0x0054
	DSS_CONFIG_APERTURE_ATTENUATION                         = 0x0057
	MM_CONFIG_TIMEOUT_MACROP_A                              = 0x005A
	MM_CONFIG_TIMEOUT_MACROP_B                              = 0x005C
	RANGE_CONFIG_TIMEOUT_MACROP_A                           = 0x005E
	RANGE_CONFIG_VCSEL_PERIOD_A                             = 0x0060
	RANGE_CONFIG_TIMEOUT_MACROP_B                           = 0x0061
	RANGE_CONFIG_VCSEL_PERIOD_B                             = 0x0063
	RANGE_CONFIG_SIGMA_THRESH                               = 0x0064
	RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT_MCPS              = 0x0066
	RANGE_CONFIG_VALID_PHASE_HIGH                           = 0x0069
	SYSTEM_INTERMEASUREMENT_PERIOD                          = 0x006C
	SYSTEM_GROUPED_PARAMETER_HOLD_0                         = 0x0071
	SYSTEM_SEED_CONFIG                                      = 0x0077
	SD_CONFIG_WOI_SD0                                       = 0x0078
	SD_CONFIG_WOI_SD1                                       = 0x0079
	SD_CONFIG_INITIAL_PHASE_SD0                             = 0x007A
	SD_CONFIG_INITIAL_PHASE_SD1                             = 0x007B
	SYSTEM_GROUPED_PARAMETER_HOLD_1                         = 0x007C
	SD_CONFIG_QUANTIFIER                                    = 0x007E
	ROI_CONFIG_USER_ROI_CENTRE_SPAD                         = 0x007F
	ROI_CONFIG_USER_ROI_REQUESTED_GLOBAL_XY_SIZE            = 0x0080
	SYSTEM_SEQUENCE_CONFIG                                  = 0x0081
	SYSTEM_GROUPED_PARAMETER_HOLD                           = 0x0082
	SYSTEM_INTERRUPT_CLEAR                                  = 0x0086
	SYSTEM_MODE_START                                       = 0x0087
	RESULT_RANGE_STATUS                                     = 0x0089
	PHASECAL_RESULT_VCSEL_START                             = 0x00D8
	RESULT_OSC_CALIBRATE_VAL                                = 0x00DE
	FIRMWARE_SYSTEM_STATUS                                  = 0x00E5
	WHO_AM_I                                                = 0x010F
	SHADOW_RESULT_FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI = 0x0FBE

	TIMING_GUARD = 4528
	TARGETRATE   = 0x0A00
)

Registers

View Source
const Address = 0x29 //0x52

The I2C address which this device listens to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Address uint16

	VHVInit    uint8
	VHVTimeout uint8
	// contains filtered or unexported fields
}

Device wraps an I2C connection to a VL53L1X device.

func New

func New(bus drivers.I2C) Device

New creates a new VL53L1X connection. The I2C bus must already be configured.

This function only creates the Device object, it does not touch the device.

func (*Device) AmbientRate

func (d *Device) AmbientRate() int32

AmbientRate returns the ambient rate in count per second (cps)

func (*Device) Configure

func (d *Device) Configure(use2v8Mode bool) bool

Configure sets up the device for communication

func (*Device) Connected

func (d *Device) Connected() bool

Connected returns whether a VL53L1X has been found. It does a "who am I" request and checks the response.

func (*Device) Distance

func (d *Device) Distance() int32

Distance returns the distance in mm

func (*Device) EffectiveSPADCount added in v0.24.0

func (d *Device) EffectiveSPADCount() uint16

EffectiveSPADCount returns the effective number of SPADs

func (*Device) GetAddress added in v0.21.0

func (d *Device) GetAddress() uint8

GetAddress returns the I2C address which this device listens to.

func (*Device) GetMeasurementTimingBudget

func (d *Device) GetMeasurementTimingBudget() uint32

GetMeasurementTimingBudget returns the timing budget in microseconds

func (*Device) GetROI added in v0.20.0

func (d *Device) GetROI() (x, y uint8, err error)

GetROI returns the currently configured 'region of interest' for x and y coordinates.

func (*Device) Read

func (d *Device) Read(blocking bool) uint16

Read stores in the buffer the values of the sensor and returns the current distance in mm

func (*Device) SetAddress added in v0.21.0

func (d *Device) SetAddress(address uint8)

SetAddress sets the I2C address which this device listens to.

func (*Device) SetDistanceMode

func (d *Device) SetDistanceMode(mode DistanceMode) bool

SetDistanceMode sets the mode for calculating the distance. Distance mode vs. max. distance SHORT: 136cm (dark) - 135cm (strong ambient light) MEDIUM: 290cm (dark) - 76cm (strong ambient light) LONG: 360cm (dark) - 73cm (strong ambient light) It returns false if an invalid mode is provided

func (*Device) SetMeasurementTimingBudget

func (d *Device) SetMeasurementTimingBudget(budgetMicroseconds uint32) bool

SetMeasurementTimingBudget configures the timing budget in microseconds It returns false if an invalid timing budget is provided

func (*Device) SetROI added in v0.20.0

func (d *Device) SetROI(x, y uint8) error

SetROI sets the 'region of interest' for x and y coordinates. Valid ranges are from 4/4 to 16/16.

func (*Device) SetTimeout

func (d *Device) SetTimeout(timeout uint32)

SetTimeout configures the timeout

func (*Device) SignalRate

func (d *Device) SignalRate() int32

SignalRate returns the peak signal rate in count per second (cps)

func (*Device) StartContinuous

func (d *Device) StartContinuous(periodMs uint32)

StartContinuous starts the continuous sensing mode

func (*Device) Status

func (d *Device) Status() RangeStatus

Status returns the status of the sensor

func (*Device) StopContinuous

func (d *Device) StopContinuous()

StopContinuous stops the continuous sensing mode

type DistanceMode

type DistanceMode uint8
const (
	SHORT DistanceMode = iota
	MEDIUM
	LONG
)

type RangeStatus

type RangeStatus uint8
const (
	RangeValid RangeStatus = iota
	SigmaFail
	SignalFail
	RangeValidMinRangeClipped
	OutOfBoundsFail
	HardwareFail
	RangeValidNoWrapCheckFail
	WrapTargetFail
	ProcessingFail
	XtalkSignalFail
	SynchronizationInt
	MergedPulse
	TargetPresentLackOfSignal
	MinRangeFail
	RangeInvalid

	None RangeStatus = 255
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL