Teensy Theramin using VL53L1X Time Of Flight Sensor (Library issue)

Status
Not open for further replies.

propa

Well-known member
Hello again,

I have a VL53L1X breakout, have connected SDA/SCL via 4.7k pullup resistors, but when using the example code I get nothing on the serial monitor, not even the sensor not found. Have tried a couple of libraries now, Pollou and Sparkfun, both with same issue. I have set SDA and SCL pins via the setSDA and setSCL functions in wire. Then tried the libraries with no sensor plugged in, expecting a read out of the serial monitor saying sensor not found, but I'm not getting anything.


The Polou library for the VL53L1X is here: https://github.com/pololu/vl53l1x-arduino

I'm wondering if there's something deeper that I'm missing, maybe these libraries weren't made for Teensy 3.x in mind.

Has anyone got this sensor to work with any 3.x's and care to point me in the right direction?

I thought it was strange to not get a sensor not found pinging back in the serial monitor:
Code:
/*
This example shows how to take simple range measurements with the VL53L1X. The
range readings are in units of mm.
*/

#include <Wire.h>
#include <VL53L1X.h>

VL53L1X sensor;

void setup()
{

  Wire.begin();
//  Wire.setSDA(38); // SDA1
//  Wire.setSCL(37); // SCL1
  Wire.setClock(400000); // use 400 kHz I2C
  Serial.begin(115200);
  delay(200); // 

  sensor.setTimeout(500);
  if (!sensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }
  
  // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
  // You can change these settings to adjust the performance of the sensor, but
  // the minimum timing budget is 20 ms for short distance mode and 33 ms for
  // medium and long distance modes. See the VL53L1X datasheet for more
  // information on range and timing limits.
  sensor.setDistanceMode(VL53L1X::Short);
  sensor.setMeasurementTimingBudget(50000);

  // Start continuous readings at a rate of one measurement every 50 ms (the
  // inter-measurement period). This period should be at least as long as the
  // timing budget.
  sensor.startContinuous(50);
}

void loop()
{
  Serial.print(sensor.read());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

After getting it to work the idea would be to map the sensor data to pitch to investigate it's effectiveness.
 
1.) The communication with that sensor is more complicated. You need to send commands over I2C to start ranging and wait for an interrupt to read the result.

2.) Forget it for Theremin use. Been there, tested a lot, and finally trashed the concept. The ranging time (even when taking the shortest possible 20ms) and the coarse ~1mm resolution does not allow continuously sliding pitch over several octaves and smooth vibrato. Resolution is not fine enough and latency is ways too high. The Moog Etherwave Pro theremin has 5 octaves on a linear 60cm pitch field. Five Octaves means 60 halftones à 1cm. Means that with 1mm resolution, pitch is in the best case quantized into clearly audible 10ct steps. Steps would have to be <= 2ct (50 steps per halftone) to give continuous impression. And the overall latency must be < 1ms for giving the player the impression of immediate reaction. Playing, teaching, fixing and designing Theremins for over 10 years. I know what I'm talking about.
 
1.) The communication with that sensor is more complicated. You need to send commands over I2C to start ranging and wait for an interrupt to read the result.

2.) Forget it for Theremin use. Been there, tested a lot, and finally trashed the concept. The ranging time (even when taking the shortest possible 20ms) and the coarse ~1mm resolution does not allow continuously sliding pitch over several octaves and smooth vibrato. Resolution is not fine enough and latency is ways too high. The Moog Etherwave Pro theremin has 5 octaves on a linear 60cm pitch field. Five Octaves means 60 halftones à 1cm. Means that with 1mm resolution, pitch is in the best case quantized into clearly audible 10ct steps. Steps would have to be <= 2ct (50 steps per halftone) to give continuous impression. And the overall latency must be < 1ms for giving the player the impression of immediate reaction. Playing, teaching, fixing and designing Theremins for over 10 years. I know what I'm talking about.

Hello and thank you for your wise comments. It seems like a complicated sensor, I've read it's doing some hidden magic writing data to registers that are not documented by ST, instead given an API that's been ported to different mcu's, I thought that could have been an issue not getting it to work on the teensy 3.2 or 3.6. I'll try uncommenting the interrupt code at the top and see if I get any response from serial monitor.

In regards to point two I'm really glad you have mentioned all of this, I really appreciate you sharing your research. Stubborn as I am, I'd still like to sonify(?!) sonificate the data from the sensor to hear it's inaccuracies for myself. I think sonifying data could be a great way to understand the pros/cons/limitations of the sensor to have some sort of instantaneous feedback other than a stream of numbers in a serial monitor.

From your investigations I understand using a VL53L1X to replicate a theremin is a futile endeavour! Are there any other sensors you can mention that are not suited for this application?

This is what I've been prototyping lately :


It's a really simple instrument, simple to play. No wrong notes as it's quantised to a scale, root note can be set via midi and so can the scale, so what happens is you can just improvise to your hearts content without having any knowledge or understanding of music. I wanted to extend the concept to using either an Optical Flow sensor or this VL53, they are my two investigations in progressing this project.

I've used ultrasound sensors probably ten years ago now to achieve a similar thing, I would like to the modern alternatives now. Have tried the leap motion as well to great success, but it's not the most robust sensor in all lighting conditions. I looked to ToF because seemed a bit more robust in different conditions.
 
Thank you so much for saying it was the interrupts Theremingenieur as in the code they state "optional interrupts/shutdown pins"! The Sparkfun library works now, but have to use pins 7 8 for SDA/SCL, unfortunately couldn't get it working on pins 3/4 or 38/37:

Code:
#include <ComponentObject.h>
#include <RangeSensor.h>
#include <SparkFun_VL53L1X.h>
#include <vl53l1x_class.h>
#include <vl53l1_error_codes.h>

/*
  Reading distance from the laser based VL53L1X
  By: Nathan Seidle
  SparkFun Electronics
  Date: April 4th, 2018
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  SparkFun labored with love to create this code. Feel like supporting open source hardware?
  Buy a board from SparkFun! https://www.sparkfun.com/products/14667

  This example prints the distance to an object.

  Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h"

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 0
#define INTERRUPT_PIN 1

//SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
  Wire.begin();
  Wire.setSDA(8);
  Wire.setSCL(7);
  Serial.begin(9600);
  Serial.println("VL53L1X Qwiic Test");

  if (distanceSensor.begin() == true)
  {
    Serial.println("Sensor online!");
  }

  
}

void loop(void)
{
  distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
  int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
  distanceSensor.stopRanging();

  Serial.print("Distance(mm): ");
  Serial.print(distance);

  float distanceInches = distance * 0.0393701;
  float distanceFeet = distanceInches / 12.0;

  Serial.print("\tDistance(ft): ");
  Serial.print(distanceFeet, 2);

  Serial.println();
}
 
Damn it they really are that crap. Comparable to an ultrasound sensor unfortunately.
 
Nice work @propa. I haven't used the vl53l1x but used vl530lx and vl630lx's.

Why thank you! You must work in a very cool industry, as I can't find a trace of vl630lx's; I'm assuming you get to play around with these devices before they even come to market! Found something similar called VL6180XV0NR, proximity and gesture, is that the one?

Were you using it for LIDAR scanning purposes out of curiosity?

Could be fun to attach the sensor to a motor, spin it round and make a simple scanner. Although I can imagine taking my own eye out during that experiment!
 
@propa - oops - meant vl6180x. Too many distractions right now.

I use them for robotics to get distances to obstacles for obstacle avoidance :) Just a hobbyist. :)
 
Status
Not open for further replies.
Back
Top