St VL53L0X Api esp Layer
St VL53L0X Api esp Layer
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?!
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: St VL53L0X Api esp Layer
I found this one a long time ago, perhaps it still works.
Re: St VL53L0X Api esp Layer
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
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
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);
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
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: St VL53L0X Api esp Layer
The way I have it is roughly this:
Hope that helps.
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);
Re: St VL53L0X Api esp Layer
Thanks for your help so far, but now i got another problem.
My setup code looks like following
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.
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);
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
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?
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
Ok it works now!
The problem why i dont got any data from vl53l0x was because it seams that my jumpers were damaged
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
The problem why i dont got any data from vl53l0x was because it seams that my jumpers were damaged
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
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: St VL53L0X Api esp Layer
Glad you got it working!
Re: St VL53L0X Api esp Layer
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: federicolonghin and 229 guests