St VL53L0X Api esp Layer

Reibers
Posts: 6
Joined: Sat May 22, 2021 10:49 am

St VL53L0X Api esp Layer

Postby Reibers » Sat May 22, 2021 10:55 am

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?!

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: St VL53L0X Api esp Layer

Postby ESP_Sprite » Sun May 23, 2021 1:36 am

I found this one a long time ago, perhaps it still works.

Reibers
Posts: 6
Joined: Sat May 22, 2021 10:49 am

Re: St VL53L0X Api esp Layer

Postby Reibers » Wed Jun 02, 2021 5:38 pm

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

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: St VL53L0X Api esp Layer

Postby ESP_Sprite » Thu Jun 03, 2021 2:53 am

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.

Reibers
Posts: 6
Joined: Sat May 22, 2021 10:49 am

Re: St VL53L0X Api esp Layer

Postby Reibers » Fri Jun 04, 2021 6:40 am

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.

Reibers
Posts: 6
Joined: Sat May 22, 2021 10:49 am

Re: St VL53L0X Api esp Layer

Postby Reibers » Fri Jun 04, 2021 2:25 pm

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?

Reibers
Posts: 6
Joined: Sat May 22, 2021 10:49 am

Re: St VL53L0X Api esp Layer

Postby Reibers » Sat Jun 05, 2021 8:02 am

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

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: St VL53L0X Api esp Layer

Postby ESP_Sprite » Sun Jun 06, 2021 2:22 am

Glad you got it working!

VadimCr
Posts: 1
Joined: Tue Apr 19, 2022 7:04 am

Re: St VL53L0X Api esp Layer

Postby VadimCr » Tue Apr 19, 2022 12:53 pm

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

Who is online

Users browsing this forum: No registered users and 136 guests