Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calibration #1

Open
riccardolardi opened this issue Sep 25, 2019 · 3 comments
Open

Calibration #1

riccardolardi opened this issue Sep 25, 2019 · 3 comments

Comments

@riccardolardi
Copy link

Hi, thanks for this JS port, I'm very keen on this since one of my projects is highly dependent on it. Also glad to contribute if anyhow possible. I'm wondering if it's possible to use the calibration functions through this library? I have the sensor behind a cover window and it would benefit if it could go through "crosstalk calibration" as well as "offset distance calibration" as described in here https://sensordots.org/mappydotcalibration thanks a lot!

@williamkapke
Copy link
Owner

williamkapke commented Sep 25, 2019

That's a great resource! I hadn't seen that before.

I found this device to be a bit tricky to understand at times... such as the calibration routine! So it would be great to have help/contributions.

I see on that page:

Once cross-talk calibration has been completed, be sure to write the current settings as the default startup settings.

I suspected that would need to be the case- but I haven't done that yet. The code should have a way of overriding the const tuning = [...] data. Maybe just an option that can be passed in? Seems easy enough.

I'm wondering if it's possible to use the calibration functions through this library?

I exposed some of the functions for reading/writing in hope that this will keep folks from being limited. Looks like I didn't expose all of them though 😊. I just pushed a new version with them exposed.


I see in the API docs:

These functions can be called after VL53L0X_StaticInit(). It has to be done before Ref
Calibration, VL53L0X_PerformRefCalibration().

That's a problem in the current code since they're both done in init() with no way to prevent the 'VL53L0X_PerformRefCalibration()' code from running.

Anyhow, I converted the code on that page and it runs... not sure if it worked? what to do next? LMK what you figure out. Thanks!

const i2c = require('i2c-bus-promise')
const VL53L0X = require('./')
const CALIBRATE_DISTANCE_OFFSET                   = (0x61)
const CALIBRATE_SPAD                              = (0x75)
const TEMPERATURE_CALIBRATION                     = (0x55)
const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t));

i2c.open(1).then(async (bus) => {
  const vl53l0x = VL53L0X(bus, 0x29)

  console.log('CALIBRATE_SPAD')
  await vl53l0x.io.write(Buffer.alloc(1, CALIBRATE_SPAD))
  await sleep(1000)

  console.log('TEMPERATURE_CALIBRATION')
  await vl53l0x.io.write(Buffer.alloc(1, TEMPERATURE_CALIBRATION))
  await sleep(1000)

  console.log('CALIBRATE_DISTANCE_OFFSET')
  await vl53l0x.io.writeReg16(CALIBRATE_DISTANCE_OFFSET, 100)

  console.log('sleeping for 10 seconds...')
  await sleep(10000)
  console.log("Calibration Complete");
})
.catch(console.error)

@williamkapke
Copy link
Owner

That code didn't really make sense to me...

This it appears to just be setting the write index:

await vl53l0x.io.write(Buffer.alloc(1, CALIBRATE_SPAD))

... and not writing anything there. So, I figured there must be some magic going on I wasn't understanding. Indeed, after investigating these MappyDots- I now understand (I don't have one of these). They added a ATmega328PB to help simplify some things. Pretty neat-o.

So, when you just write some special values- they're intercepted and then issue the more complicated steps...
https://github.com/SensorDots/MappyDotFirmware/blob/18b61a91e582485cadf4867003b68b8aa2685a92/MappyDot/main.c#L772

nice!

@rip3rs
Copy link

rip3rs commented May 24, 2021

I'm very new to this type of programming. (low level) and I to have a project that I am working on and did a "refactor" fork on my side from your project (Thank you!! for this package!)

Alas, I tried to do:

  console.log('CALIBRATE_DISTANCE_OFFSET')
  await vl53l0x.io.writeReg16(CALIBRATE_DISTANCE_OFFSET, 100)

and I believe it is doing nothing. :/

and what is the SPAD calibration? I have read what spad is but cannot for the life of me understand what it is here.

Thank you again for this project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants