Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

New contribution: VL53L0X time-of-flight distance sensor driver

Hi.

I created a driver for ST's VL53L0X time-of-flight distance sensor.
https://github.com/dcato/arduino-pololu-vl53l0x

Simple Javascript example is available under examples directory.

This library is simple port of pololu's VL53L0X library for Arduino.
https://github.com/pololu/vl53l0x-arduino

By the way, It took some time before I noticed that I need to call underlying
Arduino's Wire.begin() at first. Otherwise mongoose os dumped core all the time.
I guess some people had encountered the same problem for example topic below.
I think it may be useful if arduino-wire shows some error message instead of dumping core.

https://forum.mongoose-os.com/discussion/1384/new-contribution-native-bme280-driver-and-data-logger-to-thingspeak/p1

Thank you.

Comments

  • Hi @dcato
    Thank you very much for this driver.

    I am building mos for esp8266:

    mos build --arch esp8266

    And I have added this line to mos_esp8266.yml

    libs:
    - origin: https://github.com/dcato/arduino-pololu-vl53l0x

    However I am getting a build error:

    CC /fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/libs/rpc-service-config/src/mgos_service_config.c -> /fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/build/objs/mgos_service_config.c.o
    /fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/libs/arduino-pololu-vl53l0x/src/mgos_arduino_pololu_VL53L0X.cpp:9:6: error: unused parameter 'vl53' [-Werror=unused-parameter]
    void mgos_VL53L0X_begin(VL53L0X *vl53) {
    ^
    /fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/libs/arduino-pololu-vl53l0x/src/mgos_arduino_pololu_VL53L0X.cpp:12:6: error: unused parameter 'vl53' [-Werror=unused-parameter]
    void mgos_VL53L0X_end(VL53L0X *vl53) {
    ^
    cc1plus: all warnings being treated as errors
    make: *** [/fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/build/objs/mgos_arduino_pololu_VL53L0X.cpp.o] Error 1
    make: *** Waiting for unfinished jobs....
    /mongoose-os/fw/platforms/esp8266/Makefile.build:469: recipe for target '/fwbuild-volumes/1.20.1/apps/firmware/esp8266/build_contexts/build_ctx_914187991/build/objs/mgos_arduino_pololu_VL53L0X.cpp.o' failed
    make: *** wait: No child processes. Stop.
    Error: exit status 2
    Error: build failed

    Is there anything that I could be missing?

    Thanks a lot!

    borrigan

  • Hi @borrigan
    Thank you for your feedback.

    This "unused-parameter" error is safely ignorable and actually ignored
    when I specified "--platform esp32". But when I specified "--platform esp8266",
    it stopped build process as you wrote. I think there are some difference in build options
    between esp32 and esp8366.

    Anyway, I committed some code to avoid this error, so please try it again.

    Thank you.

  • SergeySergey Dublin, Ireland

    @dcato please push your code to https://github.com/mongoose-os-libs/arduino-pololu-vl53l0x - you're an admin, thank you very much.

  • Hi @Sergey

    I committed my code to new location: https://github.com/mongoose-os-libs/arduino-pololu-vl53l0x
    I'm glad that I can contribute for such a cute OS.

    Thank you.

  • Hello @dcato, thank you very much! MOS is building ok now!

    I just have a couple of extra questions. Since I am not using ESP-32 but NodeMCU / ES8266, I am assigning the I2C connections like this:

    NodeMCU             I2C
    -----------------   -----
    GND                        GND
    Pin D1(GPIO05)      SCL
    Pin D2(GPIO04)      SDA
    

    mos.yml file:

    • ["i2c.enable", true]
    • ["i2c.sda_gpio", 04]
    • ["i2c.scl_gpio", 05]

    However, when adding this line in my init.js,

    vl53.setMeasurementTimingBudget(200000);

    The whole mos web interface freezes, and I need to reflash the device:

    If I do not specify the Timing Budget, script executes. Here is my code:

    // Initialize Pololu VL53L0X library
    let vl53 = Pololu_VL53L0X.create();
    vl53.begin();
    vl53.init_2v8();
    vl53.setTimeout(500);
    vl53.startContinuous(10);
    print (vl53.readRangeSingleMillimeters()); //within a timer every 5 seconds

    However I always get the same read from the sensor: Distance: 65535 . No matter how close or far I put a metal object on top of the sensor, the lecture is always the same.

    Any clues will be greatly appreciated, thank you very much!

  • Hi @borrigan
    Thank you for your feedback again.

    I don't have ESP8266 so it's just a guess but
    these i2c options below may be related and helpful.

    • ["i2c.debug", "b", false, {title: "Debug I2C bus activity"}]
    • ["i2c.freq", "i", 100000, {title: "Clock frequency"}]

    https://github.com/mongoose-os-libs/i2c/blob/master/mos.yml

    Thenk you.

Sign In or Register to comment.