GithubHelp home page GithubHelp logo

alex-mous / vl53l1x-c-api-for-raspberry-pi-pico Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 98 KB

VL53L1X Time-of-Flight distance sensor API/light driver for the Raspberry Pi Pico/Pico W

License: MIT License

CMake 2.27% C 97.73%
pico vl53l1x vl53l1x-sensor raspberry-pi-pico raspberry-pi-pico-rp2040 raspberry-pi-pico-sdk raspberry-pi-pico-w

vl53l1x-c-api-for-raspberry-pi-pico's Introduction

VL53L1X Distance Sensor C/C++ API for Raspberry Pi Pico/Pico W

GitHub release (latest SemVer) GitHub GitHub issues GitHub contributors

Description

A light, easy-to-use VL53L1X Time-of-Flight distance sensor driver/API in C/C++ for the Raspberry Pi Pico/Pico W. This project implements and extends the STMicroelectronics template driver for this sensor, specifically for Rasbperry Pi Pico/Pico W microcontrollers.

Contributing

Please see CONTRIBUTING.md

Future Features

  • C++ object-oriented library
  • Easy way to configure defaults passed into initialization functions
  • Thread worker

Examples

To build the examples for the project, first clone the code and then run the following:

cd examples
mkdir build
cd build
cmake ..
make

Note: if you have a Pico W, append -DPICO_BOARD=pico_w to the cmake command.

This will build the example code. Either of th resulting uf2 files in build/examples/continuous_measurement and build/examples/sampling can be uploaded to a Pico/Pico W. The former will continously print the sensor reading to stdout (over USB), whereas the second only prints samples when input is recieved from stdin (also over USB). To use these, leave your Pico connected to your computer after uploading the uf2 file, and open a USB serial connection to it (for example, using Putty on Windows or native tools on UNIX-based systems).

For the examples to work correctly, the sensor must be attached to the following pins:

VL53L1X Pico
VDD Unconnected (Provides 2.8V)
VIN 3V3
GND GND
SDA GPIO4
SDA GPIO5
XSHUT Unconnected (Used to reset device)

Installation

To use/install this library in your own project, acquire a copy of this repo in your project (such as using git submodule), and then make the following modifications to your project's CMakeLists.txt:

If your project structure is something like this:

     yourapp.h
     yourapp.c
     CMakeLists.txt
     build/
         ...
     VL53L1X-C-API-Pico/
         library/
             import.cmake
             ...
         ...

Then, add this line to your CMakeLists.txt file before defining/linking your executables (e.g. building yourapp):

include(${PROJECT_SOURCE_DIR}/VL53L1X-C-API-Pico/library/import.cmake)

Then, to link <your executable> with libraries you already have (<your libraries>) and this VL53L1X library, change the target_link_libraries line for <your executable> as follows:

target_link_libraries(<your executable> PUBLIC pico_stdlib hardware_i2c VL53L1X_pico_api <your libraries> )

Running cmake for your project will now include and compile this API.

Using C++

If you are using C++, wrap the includes of this library in your project with an extern linkage specification as follows. Instead of #include "VL53L1X_api.h", use:

extern "C" {
    #include "VL53L1X_api.h"
}

Documentation

The header files all have extensive documentation on the purpose of each function, which can be supplemented by the STMicroelectronics VL53L1X Ultra Lite Driver User Manual (UM2510).

The three header files that can be included to use API functions are: - VL53L1X_types.h: This header file store types used in the API (status and results definitions, etc.). - VL53L1X_api.h: This header file contains all of the main API functions (initialization functions, getters and setters for registers, and functions to start/stop/read ranging). - VL53L1X_calibration.h: This header file contains functions to calibrate the VL53L1X sensor. In addition, the final header file, VL53L1X_platform.h, contains platform-specific functions and definitions (e.g. I2C setup and read/write for the Pico and Pico W).

For most use cases, just including the first two header files should be sufficient.

License

This API extends, rewrites, and implements the VL53L1X driver code from STMicroelectronics. Code provided by STMicroelectronics (in core) is provided under the BSD 3-clause "New" or "Revised" License. All changes are licensed under the MIT License.

vl53l1x-c-api-for-raspberry-pi-pico's People

Contributors

alex-mous avatar justusbraun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vl53l1x-c-api-for-raspberry-pi-pico's Issues

Use on a Raspberry Pi 3

Hello, how can I adapt your code for a Raspberry Pi 3 and not a pico ? I'm looking for standard C, and I'm not very familiar with the pico.

Any hints on how I should do that ? Is it even possible ?

Thanks a lot if you can help.

Error initializing sensor

Hardware.

Im using:

  • Raspberry PI pico_w
  • MappyDot Plus (VL53L1X)

Software

I loaded the example continuous_measuring.c from this library.

pico_w MappyDot
3v3 VCC
GND GND
GPIO4 SDA
GPIO5 SCL

Problems & Troubleshooting

I ran this example and get the following errror: Error initializing sensor
i've also ran the code without sensors and get same error
I ran another code that scans i2c adresses and detected the sensor.

I've tried everything above with external pullup resistors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.