Hello
For some reason the example doesn't work, am I doing something wrong?
In this example, there was no overlay file, which I made myself.
I use a sensor: https://www.mikroe.com/lightranger-2-click
https://download.mikroe.com/documents/datasheets/vl53l0x-sensor-datasheet.pdf
/* * Copyright (c) 2017 STMicroelectronics * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/zephyr.h> #include <zephyr/device.h> #include <zephyr/drivers/sensor.h> #include <stdio.h> #include <zephyr/sys/printk.h> void main(void) { const struct device *dev = DEVICE_DT_GET_ONE(st_vl53l0x); struct sensor_value value; int ret; if (!device_is_ready(dev)) { printk("sensor: device not ready.\n"); return; } while (1) { ret = sensor_sample_fetch(dev); if (ret) { printk("sensor_sample_fetch failed ret %d\n", ret); return; } ret = sensor_channel_get(dev, SENSOR_CHAN_PROX, &value); printk("prox is %d\n", value.val1); ret = sensor_channel_get(dev, SENSOR_CHAN_DISTANCE, &value); printf("distance is %.3fm\n", sensor_value_to_double(&value)); k_sleep(K_MSEC(1000)); } }
// To get started, press Ctrl+Space to bring up the completion menu and view the available nodes. // You can also use the buttons in the sidebar to perform actions on nodes. // Actions currently available include: // * Enabling / disabling the node // * Adding the bus to a bus // * Removing the node // * Connecting ADC channels // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html &arduino_i2c { status = "okay"; clock-frequency = <I2C_BITRATE_FAST>; vl53l0x: vl53l0x@52 { compatible = "st,vl53l0x"; reg = <0x52>; }; };
and prj.conf:
CONFIG_STDOUT_CONSOLE=y CONFIG_I2C=y CONFIG_GPIO=y CONFIG_SENSOR=y CONFIG_VL53L0X_PROXIMITY_THRESHOLD=100 #debug #CONFIG_DEBUG=y #CONFIG_LOG=y #CONFIG_SENSOR_LOG_LEVEL_DBG=y CONFIG_CBPRINTF_FP_SUPPORT=y
I have also used, for example, the ENS210 sensor from the same manufacturer and it has worked beautifully.
Thank you.