Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Mongoose OS + VL53L0X ToF sensor

shoelessoneshoelessone Kashihara, Japan

I am interested in using the VL53L0X sensor with an Mongoose OS and ESP32.

I am aware there is a library for that, https://github.com/mongoose-os-libs/arduino-pololu-vl53l0x

I would like to use this library, but as sad as this is I'm not actually entirely certain how to do this. There is a simple JS example, however . The compatibility layer on top of the Arduino library while probably not complicated isn't something I understand enough to understand the correct way to use this library.

Simply including #include "VL53L0X.h" (and nothing else) causes build issues:

In file included from /fwbuild-volumes/2.12.1/apps/button-box-iot-mongoose-os-firmware/esp32/build_contexts/build_ctx_679887065/src/main.c:4:0:
/fwbuild-volumes/2.12.1/apps/button-box-iot-mongoose-os-firmware/esp32/build_contexts/build_ctx_679887065/deps/arduino-pololu-vl53l0x/src/VL53L0X.h:6:1: error: unknown type name 'class'
 class VL53L0X
 ^
/fwbuild-volumes/2.12.1/apps/button-box-iot-mongoose-os-firmware/esp32/build_contexts/build_ctx_679887065/deps/arduino-pololu-vl53l0x/src/VL53L0X.h:7:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^

This makes me think that perhaps I'm just not including the correct header file... or something along those lines?

The JS example looks simple enough, but again I'm not actually quite sure how to work backwards from that to how to do this in C:

load('api_vl53l0x.js');
load('api_timer.js');

// Initialize Pololu VL53L0X library
let vl53 = Pololu_VL53L0X.create();
vl53.begin();

vl53.init_2v8();
vl53.setTimeout(500);

// reduce timing budget to 20 ms (default is about 33 ms, High Speed)
// vl53.setMeasurementTimingBudget(20000);
// increase timing budget to 200 ms (High Accuracy)
vl53.setMeasurementTimingBudget(200000);

Timer.set(1000 /* milliseconds */, true /* repeat */, function() {
  print('Distance: ', vl53.readRangeSingleMillimeters());
}, null);

I'm wondering if somebody here might be able to either point me in the correct direction or just give me an example of a project they're working on with some examples on github?

Thank you very much for your time!

Comments

  • edited February 27

    Hi,

    Try to rename your main.c to main.cpp. And maybe you should rather include mgos_arduino_pololu_VL53L0X.h?

    For reference you can also check https://forum.mongoose-os.com/discussion/1990/use-c-classes.

    I am not expert in mixing C and C++ buy maybe it will help.

  • This library is not compatible with C compilation.
    Use it in a cpp file.

  • shoelessoneshoelessone Kashihara, Japan

    Thank you both for your reply! Sure enough, swapping my main.c to main.cpp fixed the issue!

    That said, it raises another (probably stupid!) question from me: Given C++ is a more "modern" language to work with, is there a reason that the default examples aren't just written in C++ to begin with? I'm guessing compilation adds additional overhead (disc space + memory) and that's likely the reason?

    My ultimate goal with my current project is to end up with a reliable device (it's just a Christmas present for my family, so nothing mission critical exactly, but I've been working on it for a year so I want it to be reliable!), if compiling this as C++ firmware is going to cost me anything in reliability (etc) and I need to spend a month rewriting the VL53L0X stuff I'll do it. I'd just prefer not to ;).

    Thanks again for your help!

  • I think C++ is much more complex and harder to master than C and I see no need for such complexity for SoC embedded devices. Also for example Linux kernel is written in C and it is million times bigger project than mongoose os :-)

  • shoelessoneshoelessone Kashihara, Japan

    Fair points @UserMartin :) - I'm coming from a mainly "higher order" language world (Java, JavaScript, PHP, etc) so for me things like uses classes are nice.

    But the real point / question I have I guess is whether I'm going to be hurting my project in terms of reliability by using C++ instead of C?

    Thanks again!

  • Me too - before I coded 10 years Java. Now React and Nodejs not missing classes at all. I think that classes are often overrated or misused and are mostly not necessary. Moreover classes in C++ are imho more difficult than in languages you mentioned :).
Sign In or Register to comment.