Page 1 of 1

St VL53L0X Api esp Layer

Posted: Sat May 22, 2021 10:55 am
by Reibers
Hi i want to use the Api from St for the vl53l0x laser sensor. The documentation says that you have to write the platform specific part to use the Api for example for esp32. Did someone already do that?!

Re: St VL53L0X Api esp Layer

Posted: Sun May 23, 2021 1:36 am
by ESP_Sprite
I found this one a long time ago, perhaps it still works.

Re: St VL53L0X Api esp Layer

Posted: Wed Jun 02, 2021 5:38 pm
by Reibers
Ah thanks! I included the component into my Project but cant figure out how to use it correctly.
Do i have to initialize the i2c driver by myself? Could not found any initialization code in the Api Layer.

My first step is to init the sensor like so

Code: Select all

VL53L0X_Dev_t dev = {0x00};

dev.i2c_address = 0x52;
dev.i2c_port_num = 21;

error = VL53L0X_StaticInit(&dev);
But it gives me following error:

E (2468) i2c: C:/esp-idf/components/driver/i2c.c:1110 (i2c_master_cmd_begin):i2c number error

I am not really sure which address to set. I found 0x52 in the St Api example. As Port number i choose the SDA Pin. I use the ESP-WROOM-32 38 PIN Develeopment Board so my SDA standard pin is GPIO 21.

Appreciate your help

Re: St VL53L0X Api esp Layer

Posted: Thu Jun 03, 2021 2:53 am
by ESP_Sprite
The way I have it is roughly this:

Code: Select all

static VL53L0X_Dev_t vl_dev;

[...]
i2c_port_t i2c_master_port = I2C_NUM_1;
i2c_config_t conf={0};
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = PIN_NUM_SDA;
conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
conf.scl_io_num = PIN_NUM_SCL;
conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
conf.master.clk_speed = 400000;

ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &conf));
ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0));
[...]

vl_dev.i2c_port_num = I2C_NUM_1;
vl_dev.i2c_address = 0x29;
status = init_vl53l0x(&vl_dev);
assert(status == VL53L0X_ERROR_NONE);
Hope that helps.

Re: St VL53L0X Api esp Layer

Posted: Fri Jun 04, 2021 6:40 am
by Reibers
Thanks for your help so far, but now i got another problem.

My setup code looks like following

Code: Select all

    i2c_port_t i2c_master_port = I2C_NUM_1;
    i2c_config_t conf={0};
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = 21;
    conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
    conf.scl_io_num = 22;
    conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
    conf.master.clk_speed = 400000;

    ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &conf));
    ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0));

    dev.i2c_address = 0x29;
    dev.i2c_port_num = I2C_NUM_1;
    
    printf ("Call of VL53L0X_DataInit\n");
    error = VL53L0X_DataInit(&dev); // Data initialization
    print_pal_error(error);
print_pal_error() gives me the following error:

API Status: -20 : Control Interface Error

I looked the error up and i think it comes from VL53L0X_WriteMulti() function within i2c_master_cmd_begin() is invoked and which returns the esp error ESP_ERR_INVALID_STATE.

Is something wrong with my i2c setup?

Thanks for your help.

Re: St VL53L0X Api esp Layer

Posted: Fri Jun 04, 2021 2:25 pm
by Reibers
Hi,

now i am a bit confused. I tried a lot but could not get the vl53l0x to run.
i tried to scan the i2c port to verify that the hardware and the pinout is right and dont got it to detect the vl53l0x.

Next i tried to use Arduino IDE because all examples i have found are with Arduino IDE.
Wow with Arduino it somehow works!

Dont know why and i am a bit confused.

I think the i2c Interface is not working correct.
Always when i invoke the i2c interface functions i get an Interface -20 error from the vl53l0x API.
From the config_param and driver_install functions i always get 0 as return so all good.

Any clue what i am doing wrong?

Re: St VL53L0X Api esp Layer

Posted: Sat Jun 05, 2021 8:02 am
by Reibers
Ok it works now!

The problem why i dont got any data from vl53l0x was because it seams that my jumpers were damaged :x
I changed the wiring befor testing with Arduino IDE. Now i check with esp-idf and it works and i get data from the sensor.

Thx for your help!

Cya

Re: St VL53L0X Api esp Layer

Posted: Sun Jun 06, 2021 2:22 am
by ESP_Sprite
Glad you got it working!

Re: St VL53L0X Api esp Layer

Posted: Tue Apr 19, 2022 12:53 pm
by VadimCr
Got the same issue with my jumpers, I've spend a lot of time trying to build a project base on Arduino and a database api and I wasn't able to do anything because of jumpers. I don't know why and how I decided to play a little with the wirings but in the end it worked just perfectly