Code Monkey home page Code Monkey logo

vl53l0x-python's Introduction

VL53L0X Python interface on Raspberry Pi/Jetson TX2

This project provides a simplified python interface on Raspberry Pi to the ST VL53L0X API (ST Microelectronics).

Patterned after the cassou/VL53L0X_rasp repository (https://github.com/cassou/VL53L0X_rasp.git)

In order to be able to share the i2c bus with other python code that uses the i2c bus, this library implements the VL53L0X platform specific i2c functions through callbacks to the python smbus interface.

Version 1.0.2:

  • Add support for TCA9548A I2C Multiplexer. Tested with https://www.adafruit.com/products/2717 breakout. (johnbryanmoore)
  • Add python example using TCA9548A Multiplexer support (johnbryanmoore)
  • Add pip install support (grantramsay)
  • Add smbus2 support (grantramsay)
  • Update pip install support python2/3 (naisy)
  • Update smbus/smbus2 support (naisy)
  • Add gcc -fPIC CFLAGS for build on Ubuntu (naisy)
  • Add I2C address change support (naisy)

Version 1.0.1:

  • Simplify build process (svanimisetti)
  • Add python example that graphs the sensor output (svanimisetti)
  • Update the build instructions (svanimisetti, johnbryanmoore)

Version 1.0.0:

  • Add support for multiple sensors on the same bus utilizing the ST API call to change the address of the device.
  • Add support for improved error checking such as I/O error detection on I2C access.

Version 0.0.9:

  • initial version and only supports 1 sensor with limited error checking.

Notes on Multiple sensor support:

  • In order to have multiple sensors on the same bus, you must have the shutdown pin of each sensor tied to individual GPIO's so that they can be individually enabled and the addresses set.
  • Both the Adafruit and Pololu boards for VL53L0X have I2C pull ups on the board. Because of this, the number of boards that can be added will be limited to only about 5 or 6 before the pull-up becomes too strong.
  • Changes to the platform and python_lib c code allow for up to 16 sensors.
  • Address changes are volatile so setting the shutdown pin low or removing power will change the address back to the default 0x29.

Notes on using TCA9548A I2C Multiplexer:

  • If limited on GPIO's that would be needed to set a new addresses for each sensor, using a TCA9548A I2C Multiplexer is a good option since it allows using up to 8 sensors without using GPIO's.
  • The TCA9548A is also a good option if using multiple boards on the same I2C bus and the total of all the combined I2C pullups would cause the bus not to function.
  • Theoretically you can connect multiple TCA9548A Multiplexers, each with up to 8 sensors as long each TCA9548A has a different address. This has not been tested but should work in theory.

(Please note that while the author is an embedded software engineer, this is a first attempt at extending python and the author is by no means a python expert so any improvement suggestions are appreciated).

Installation

# Python2
pip2 install git+https://github.com/pimoroni/VL53L0X-python.git
# Python3
pip3 install git+https://github.com/pimoroni/VL53L0X-python.git

Compilation

  • To build on raspberry pi, first make sure you have the right tools and development libraries:
sudo apt-get install build-essential python-dev

Then use following commands to clone the repository and compile:

cd your_git_directory
git clone https://github.com/pimoroni/VL53L0X_rasp_python.git
cd VL53L0X-python
make
  • In the Python directory are the following python files:

VL53L0X.py - This contains the python ctypes interface to the ST Library

VL53L0X_example.py - This example accesses a single sensor with the default address.

VL53L0X_example_livegraph.py - This example plots the distance data from a single sensor in a live graph. This example requires matplotlib. Use sudo pip install matplotlib to install matplotlib.

VL53L0X_multi_example.py - This example accesses 2 sensors, setting the first to address 0x2B and the second to address 0x2D. It uses GPIOs 20 and 16 connected to the shutdown pins on the 2 sensors to control sensor activation.

VL53L0X_multi_example.py Diagram

VL53L0X_TCA9548A_example.py - This example accesses 2 sensors through a TCA9548A I2C Multiplexer with the first connected to bus 1 and the second on bus 2 on the TCA9548A.

VL53L0X_TCA9548A_example.py Diagram

vl53l0x-python's People

Contributors

johnbryanmoore avatar naisy avatar svanimisetti avatar gadgetoid avatar grantramsay avatar jesstr avatar

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.