cancel
Showing results for 
Search instead for 
Did you mean: 

Compile VL6180X API in c

SCADE
Associate III

Hello,
I'm trying to get a VL6180X sensor to work.
I've downloaded the latest API: en.VL6180_API_V1.3.0.zip
My goal is to make the sensor work in I2c on a Raspberry PI in the c or c++ language.
But I can't compile my code, or rather compile the api into a library.
Where can I find an example of a makefile or command to do this?

Thanks for your help.

7 REPLIES 7
Andrew Neil
Evangelist III

Did you mean to ask a question?

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

EDIT:  OP has now been updated to include a question

 

Andrew Neil
Evangelist III

@SCADE wrote:

But I can't compile my code, or rather compile the api into a library.


What problem(s), exactly, are you facing?

What have you tried so far?

Again, please see:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Ok so here is my test.cpp file :

#include <iostream>
#include <unistd.h>
#include "vl6180_api.h"

int main()
{
  VL6180Dev_t tof = 0x29;

  VL6180_WaitDeviceBooted(tof);
  VL6180_InitData(tof);
  VL6180_Prepare(tof);

  for (size_t i = 0; i < 10; i++)
  {

    VL6180_RangeData_t rangeData;
    VL6180_RangePollMeasurement(tof, &rangeData);

    printf("Range: %d\n", rangeData.range_mm);
  }

  VL6180_FilterSetState(tof, 1);

  return 0;
}

file structure : 
api_vl6180x_1.4.0/
api_vl6180x_1.4.0/config
api_vl6180x_1.4.0/config/vl6180_cfg.h
api_vl6180x_1.4.0/core
api_vl6180x_1.4.0/core/inc
api_vl6180x_1.4.0/core/inc/vl6180_def.h
api_vl6180x_1.4.0/core/inc/vl6180_api.h
api_vl6180x_1.4.0/core/src
api_vl6180x_1.4.0/core/src/vl6180_api.c
api_vl6180x_1.4.0/platform
api_vl6180x_1.4.0/platform/template
api_vl6180x_1.4.0/platform/template/vl6180_platform.h
api_vl6180x_1.4.0/platform/template/vl6180_types.h
api_vl6180x_1.4.0/platform/cci-i2c
api_vl6180x_1.4.0/platform/cci-i2c/vl6180_i2c.c
api_vl6180x_1.4.0/platform/cci-i2c/vl6180_i2c.h

and finally compile command :
g++ -o test test.cpp api_vl6180x_1.4.0/core/src/*.c api_vl6180x_1.4.0/platform/cci-i2c/*.c -I api_vl6180x_1.4.0/core/inc/ -I api_vl6180x_1.4.0/platform/template/ -I api_vl6180x_1.4.0/config/ -lwiringPi

Error :
/usr/bin/ld: /tmp/ccnVF5wY.o: in function `VL6180_WaitDeviceBooted':
vl6180_api.c:(.text+0x6c): undefined reference to `VL6180_RdByte' ...................................... 


@SCADE wrote:

Error :
/usr/bin/ld: /tmp/ccnVF5wY.o: in function `VL6180_WaitDeviceBooted':
vl6180_api.c:(.text+0x6c): undefined reference to `VL6180_RdByte' ...................................... 


"undefined reference" is a linker error.

It means that you have omitted to provide a definition of that function - either as source code, or as a pre-built binary library.

Probably, you have #included a header which just declares that function (ie, just provides a prototype) - hence the compiler is happy - but haven't added the necessary source or pre-built binary library to your project - so the link fails.

 

#UdefinedReference

 

EDIT:

Looks like these are the docs you need:

AndrewNeil_0-1718704772243.png

 

This is also what I understand the definition seems to be missing, however it is present in

for VL6180_RdByte :
Function declaration: vl6180_api.h
Function definition: vl6180_i2c.c
Function usage: vl6180_api.c

And I seem to be integrating them all correctly in my compile command

When we write the code you are using, we don't know what MCU ( or CPU) you have.

So, we write the code all the way to RdByte() and WrByte() and then WE STOP.

It's up to you to populate those functions.

Have a look at the platform.c function and Platform.h

Notice they are basically empty?

There are examples of VL6180 projects on Linux - on GitHub.

Download one of those and borrow the Platform.c file. 

You basically have to insert a IOCTL I2C write function into RdByte(). 

- john


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.

Thanks for your reply,

The API documentation recommends using cci-i2c (should work on raspberry??)
In the files of the cci-i2c folder there are the functions you say are missing but that I can't get to work ;(

And on Github I couldn't find anything relevant.