Asking for information based on VL6180X Sensor

Hello everyone,

Is there someone here who has already programmed on STM32 the VL6180X sensor?

first of all why are you interested in such my first thought is some type of self inflicated explosion but since you don’t already know me my second guess is some type of global revenge my last guess sounds terrible you don’t wanna hear it but I’ll help you anyway

technology is attractive to everyone including giant people if you mention a
numbers four digit sequence to him his demeanor will change to one of your friends when this happens mention only two digit number sequences 23, 22, 21, 2020 you ll probably need to get a software update don’t be afraid to use new software besides your pathway httlm
have all changed and with Firefox under new management you’ve gone green or your software and lingo have all changed
people are now using more of a launcher type system where playable games and things are now launched for example in order to launch motorcycle app you’ll need chicken fingers apps and the lingo
(that does the job) is a code for thank you
(spin that vinyl) is code for proceed if you use these codes tell me how you like it

What do you need to know maybe i can help. VL6180X is the TOF sensor, right!?

1 Like

I have some problem by implementing the code based on this sensor and the board that I have.
I want merely to display the distance value of any obstacle on the seven segment display wich is implemented on the board I am working with.

Can you maybe show me the code you have written so far and tell me wich board you are using? :slightly_smiling_face:

The board’s name is NucleoL476rg.
image

On this board is mounted another board in wich there are seven segment display and VL6180X sensor.
The aim is to put aN obstacle on the sensor and the seven segment display will display the distance between the sensor and the obstacle.

uint8_t I2C_adress[3] = {0x29, 0x52, 0x53};

//IDENTIFICATION REGISTERS 0x00 - 0x0F/
uint8_t DENTIFICATION__MODEL_ID[2] = {0x000, 0xB4}; //adress and reset value
uint8_t DENTIFICATION__MODEL_REV_MAJOR [2] = {0x001, 0x1}; //adress and reset value
uint8_t IDENTIFICATION__MODEL_REV_MINOR [2] = {0x002, 0x3}; //adress and reset value
uint8_t IDENTIFICATION__MODULE_REV_MAJOR [2] = {0x003, 0x1}; //adress and reset value
uint8_t IDENTIFICATION__MODULE_REV_MINOR[2] = {0x004, 0x2}; //adress and reset value
//const uint8_t IDENTIFICATION__DATE_HI[2] = {0x006, 0xYY}; //adress and reset value
//const uint8_t IDENTIFICATION__DATE_LO[2] = {0x004, 0xYY}; //adress and reset value
//const uint8_t IDENTIFICATION__TIME[2] = {0x008:0x009, 0xYYYY}; //adress and reset value

//System Setup Register 0x10 - 0x17
uint8_t SYSTEM__MODE_GPIO0[2] ={0x010,0x60}; //adress and reset value
uint8_t SYSTEM__MODE_GPIO1_Section [2] ={0x011,0x20}; //adress and reset value
uint8_t SYSTEM__HISTORY_CTRL [2] ={0x012,0x0};//adress and reset value
uint8_t SYSTEM__INTERRUPT_CONFIG_GPIO [2] ={0x014,0x0};//adress and reset value
uint8_t SYSTEM__INTERRUPT_CLEAR [2] ={0x015,0x0}; //adress and reset value
uint8_t SYSTEM__FRESH_OUT_OF_RESET [2] ={0x016,0x1};//adress and reset value
uint8_t SYSTEM__GROUPED_PARAMETER_HOLD [2] ={0x017,0x0};//adress and reset value

//RANGE SETUP Register 0x18 - 0x37
uint8_t SYSRANGE__START [2] ={0x018,0x0};//adress and reset value
uint8_t SYSRANGE__THRESH_HIGH [2] ={0x019,0xFF};//adress and reset value
uint8_t SYSRANGE__THRESH_LOW [2] ={0x01A,0x0};//adress and reset value};
uint8_t SYSRANGE__INTERMEASUREMENT_PERIOD [2] ={0x01B,0xFF};//adress and reset value
uint8_t SYSRANGE__MAX_CONVERGENCE_TIME [2] ={0x01C,0x31};//adress and reset value
uint16_t SYSRANGE__CROSSTALK_COMPENSATION_RATE [2] ={0x01E,0x0};//adress and reset value
uint8_t SYSRANGE__CROSSTALK_VALID_HEIGHT [2] ={0x021,0x14};//adress and reset value

uint16_t SYSRANGE__EARLY_CONVERGENCE_ESTIMATE [2]={0x022,0x0};//adress and reset value
//const uint8_t SYSRANGE__PART_TO_PART_RANGE_OFFSET [2]={0x024,0xYY};//adress and reset value
uint8_t SYSRANGE__RANGE_IGNORE_VALID_HEIGHT [2]={0x025,0x0};//adress and reset value
uint16_t SYSRANGE__RANGE_IGNORE_THRESHOLD [2]={0x026,0x00};//adress and reset value
uint8_t SYSRANGE__MAX_AMBIENT_LEVEL_MULT [2]={0x02C,0xA0};//adress and reset value
uint8_t SYSRANGE__RANGE_CHECK_ENABLES [2]={0x02D,0x11};//adress and reset value

uint8_t SYSRANGE__VHV_RECALIBRATE [2] ={0x02E,0x0};//adress and reset value
uint8_t SYSRANGE__VHV_REPEAT_RATE [2]={0x031,0x0};//adress and reset value

//ALS SETUP 0x38 - 0x40
uint8_t SYSALS__START [2] = {0x038, 0x0}; //adress and reset value
uint16_t SYSALS__THRESH_HIGH[2] = {0x03A, 0xFFFF}; //adress and reset value
uint16_t SYSALS__THRESH_LOW [2] = {0x03C, 0x0}; //adress and reset value
uint8_t SYSALS__INTERMEASUREMENT_PERIOD [2] = {0x03E, 0xFF}; //adress and reset value
uint8_t SYSALS__ANALOGUE_GAIN [2] = {0x03F, 0x06}; //adress and reset value
uint16_t SYSALS__INTEGRATION_PERIOD [2] = {0x040, 0x0}; //adress and reset value

//RESULTS 0x4D - 0x80
uint8_t RESULT__RANGE_STATUS [2]={0x04D,0x1};//adress and reset value
uint8_t RESULT__ALS_STATUS [2]={0x04E,0x1};//adress and reset value
uint8_t RESULT__INTERRUPT_STATUS_GPIO [2]={0x04F,0x0};//adress and reset value
uint16_t RESULT__ALS_VAL [2]={0x050,0x0};//adress and reset value
uint16_t RESULT__HISTORY_BUFFER_0 [2]={0x052 + 0 * 0x2,0x0};//adress and reset value
uint16_t RESULT__HISTORY_BUFFER_1 [2]={0x052 + 1 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_2 [2]={0x052 + 2 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_3 [2]={0x052 + 3 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_4 [2]={0x052 + 4 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_5 [2]={0x052 + 5 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_6 [2]={0x052 + 6 * 0x2 ,0x0};
uint16_t RESULT__HISTORY_BUFFER_7 [2]={0x052 + 7 * 0x2 ,0x0};

uint8_t RESULT__RANGE_VAL [2]={0x062,0x0};//adress and reset value
uint8_t RESULT__RANGE_RAW [2]={0x064,0x0};//for user
uint16_t RESULT__RANGE_RETURN_RATE [2]={0x066,0x0};//important
uint8_t RESULT__RANGE_REFERENCE_RATE [2]={0x068,0x0};//adress and reset value
uint32_t RESULT__RANGE_RETURN_SIGNAL_COUNT [2]={0x06C,0x0};//adress and reset value
uint32_t RESULT__RANGE_REFERENCE_SIGNAL_COUNT [2]={0x070,0x0};//adress and reset value
uint32_t RESULT__RANGE_RETURN_AMB_COUNT [2]={0x074,0x0};//adress and reset value
uint32_t RESULT__RANGE_REFERENCE_AMB_COUNT [2]={0x078,0x0};//adress and reset value
uint32_t RESULT__RANGE_RETURN_CONV_TIME [2]={0x07C,0x0};//adress and reset value
uint32_t RESULT__RANGE_REFERENCE_CONV_TIME [2]={0x080,0x0};//adress and reset value

uint16_t result;
float distance;

int main(void)
{
while(HAL_I2C_IsDeviceReady(&hi2c1, 0x52, 3, 100) != HAL_OK)
{}

HAL_I2C_Master_Transmit(&hi2c1, 0x52,(uint8_t *)&I2C_adress, 3, 100); //writing slave address register with
//desired value
HAL_Delay(10);
HAL_I2C_Master_Transmit(&hi2c1, 0x52,(uint8_t *)&SYSALS__START,2, 100); //writing the command to start conversion
HAL_Delay(10);

while (1)
{

 HAL_I2C_Master_Transmit(&hi2c1, 0x52, (uint16_t *)&RESULT__ALS_VAL, 2, 100);
 HAL_Delay(100);
 HAL_I2C_Master_Receive(&hi2c1, 0x53, (uint16_t *)&result, 2, 100);
 distance = result;

}

}

Before i go too deep into your code and everything just some last questions.

First of all, did you enabled pull up resisors on the SCL and SDA pins, while you where configuring your I2C interface? Because i2c needs pull ups otherwise there is no valid communication and I know that on the STM32 boards there are no pull ups enabled by default.

Second if pull ups are enabled and the application still does not work, is there a sequence where you do an initialization of the i2c ? Because by shortly scrolling through your code i did not see it. There are two initialization functions to call MX_I2C1_Init() and HAL_I2C_Init(&hi2c1).

If your code is still not working i will go a little bit deeper to find the problem. Just let me know.

Have a nice saturday.

1 Like

Hello @Nikolas sorry for the delay I have been working on another things. This subject is coming back since I haven’t completed it yet and I hope to do it as soon as possible.

Well, for the pull up resistor I do not see how I can handle with that since I2C pins (SDA & SCL) are directly connected to the shield of the sensor (you can see it on the screen above)

About the I2C initialisation functions, I need to implement it.

Thanks!!

Hi @Nysse

No problem about your time of response :wink: .

You can enable the pull up resitors on the corresponding pins (SCL & SDA) in the .ioc file like you can see in the image bellow.

Lets give it a try and as i said earlier, if this does not help i will try to dive deeper into that topic to help you.

Good night / morning / day :wink:

1 Like

Hello Dear Nikolas, thank you, I didn’t know that it was possible to set it from the STM IDE.
I will try and you know about.

Thanks!

Have a good night/morning/day too.

1 Like

Hello Dear Nikolas,
I hope you’re fine, I have added functions that you gave to me and set finctions that you show me in the configurations.
But I am still having nothing : no distance result from the screen of my stm32cubeIDE.

Since My sensor has been added as a shield on my microcontroller board, I wonder I need to seet something from the added pins so that I can have any access from the sensor because until now, I don’t know exactly in wich pins of my microcontroller board the shield of my sensor is truly connected

On the other hand, may be my code is not enough completed as far as the datasheet id concerned.

Hi @Nysse

Hmm it is not so easy for me to find out the issue because i do not have that TOF sensor board at home. But there are some things i see in your code which i am not sure that they are right. First i think that your receiving address is wrong. Because you are sending to the slave with address 0x52 so i truly belive that you also want to receive from this slave. Thus i think you need to put the address 0x52 instead of 0x53 into the receiving function.

Second you do not need cast like that (uint16_t *)&result. Because the name of an array is allready a pointer to the first element inside the arrays memory location so you only need to pass result to the function instead of that casting thing.

Maybe the thing with the address helps and if not i think i need to get one of these boards to find the issue or i should check all the commands a little bit better.

Have a nice what ever :wink:.

1 Like

Thanks for your feedback. Unfortunately I have to give back the TOF sensor on monday, that means I do not have many of time ahead of me now.
I chnaged the adress but nothing has happen. I think may I got wrong with some commands as far as the datasheet is concerned.

I got some trouble a lit a bit with the register values. As a matter of fact may be these adresses was not well configured.

Hello I changed my code to this but nothing happened unfortunately
uint8_t I2C_adress[3] = {0x29, 0x52, 0x53};

//IDENTIFICATION REGISTERS 0x00 - 0x0F/
uint8_t IDENTIFICATION__MODEL_ID[] = {0x000}; //adress
uint8_t IDENTIFICATION__MODEL_REV_MAJOR [] = {0x001}; //adress
uint8_t IDENTIFICATION__MODEL_REV_MINOR [] = {0x002}; //adress
uint8_t IDENTIFICATION__MODULE_REV_MAJOR[] = {0x003}; //adress
uint8_t IDENTIFICATION__MODULE_REV_MINOR[] = {0x004}; //adress
const uint8_t IDENTIFICATION__DATE_HI[] = {0x006}; //adress
const uint8_t IDENTIFICATION__DATE_LO[] = {0x007}; //adress
const uint8_t IDENTIFICATION__TIME[] = {0x008}; //adress

//System Setup Register 0x10 - 0x17
uint8_t SYSTEM__MODE_GPIO0[] = {0x010}; //adress
uint8_t SYSTEM__MODE_GPIO1_Section [] = {0x011}; //adress
uint8_t SYSTEM__HISTORY_CTRL [] = {0x012};//adress
uint8_t SYSTEM__INTERRUPT_CONFIG_GPIO [] = {0x014};//adress
uint8_t SYSTEM__INTERRUPT_CLEAR [] = {0x015}; //adress
uint8_t SYSTEM__FRESH_OUT_OF_RESET [] = {0x016};//adress
uint8_t SYSTEM__GROUPED_PARAMETER_HOLD [] = {0x017};//adress

//RANGE SETUP Register 0x18 - 0x37
uint8_t SYSRANGE__START [] = {0x018};//adress
uint8_t SYSRANGE__THRESH_HIGH [] = {0x019};//adress
uint8_t SYSRANGE__THRESH_LOW [] = {0x01A};//adress
uint8_t SYSRANGE__INTERMEASUREMENT_PERIOD [] = {0x01B};//adress
uint8_t SYSRANGE__MAX_CONVERGENCE_TIME [] = {0x01C};//adress
uint16_t SYSRANGE__CROSSTALK_COMPENSATION_RATE [] = {0x01E};//adress
uint8_t SYSRANGE__CROSSTALK_VALID_HEIGHT [] = {0x021};//adress

uint16_t SYSRANGE__EARLY_CONVERGENCE_ESTIMATE [] = {0x022};//adress
const uint8_t SYSRANGE__PART_TO_PART_RANGE_OFFSET [] = {0x024};//adress
uint8_t SYSRANGE__RANGE_IGNORE_VALID_HEIGHT [] = {0x025};//adress
uint16_t SYSRANGE__RANGE_IGNORE_THRESHOLD [] = {0x026};//adress
uint8_t SYSRANGE__MAX_AMBIENT_LEVEL_MULT [] = {0x02C};//adress
uint8_t SYSRANGE__RANGE_CHECK_ENABLES [] = {0x02D};//adress

uint8_t SYSRANGE__VHV_RECALIBRATE [] = {0x02E};//adress
uint8_t SYSRANGE__VHV_REPEAT_RATE [] = {0x031};//adress

//ALS SETUP 0x38 - 0x40
uint8_t SYSALS__START [] = {0x038}; //adress
uint16_t SYSALS__THRESH_HIGH[] = {0x03A}; //adress
uint16_t SYSALS__THRESH_LOW [] = {0x03C}; //adress
uint8_t SYSALS__INTERMEASUREMENT_PERIOD [] = {0x03E}; //adress
uint8_t SYSALS__ANALOGUE_GAIN [] = {0x03F}; //adress
uint16_t SYSALS__INTEGRATION_PERIOD [] = {0x040}; //adress

//RESULTS 0x4D - 0x80
uint8_t RESULT__RANGE_STATUS [] = {0x04D};//adress
uint8_t RESULT__ALS_STATUS [] = {0x04E};//adress
uint8_t RESULT__INTERRUPT_STATUS_GPIO [] = {0x04F};//adress
uint16_t RESULT__ALS_VAL [] = {0x050};//adress
uint16_t RESULT__HISTORY_BUFFER_0 []={(0x052 + 0x0)*0x2};//adress
uint16_t RESULT__HISTORY_BUFFER_1 [] = {(0x052 + 0x1)*0x2};
uint16_t RESULT__HISTORY_BUFFER_2 [] = {(0x052 + 0x2)*0x2};
uint16_t RESULT__HISTORY_BUFFER_3 [] = {(0x052 + 0x3)*0x2};
uint16_t RESULT__HISTORY_BUFFER_4 [] = {(0x052 + 0x4)*0x2};
uint16_t RESULT__HISTORY_BUFFER_5 [] = {(0x052 + 0x5)*0x2};
uint16_t RESULT__HISTORY_BUFFER_6 [] = {(0x052 + 0x6)*0x2};
uint16_t RESULT__HISTORY_BUFFER_7 [] = {(0x052 + 0x7)*0x2};

uint8_t RESULT__RANGE_VAL [] = {0x062};//adress
uint8_t RESULT__RANGE_RAW [] = {0x064};//for user
uint16_t RESULT__RANGE_RETURN_RATE[] = {0x066};//important
uint8_t RESULT__RANGE_REFERENCE_RATE[] = {0x068};//adress
uint32_t RESULT__RANGE_RETURN_SIGNAL_COUNT [] = {0x06C};//adress
uint32_t RESULT__RANGE_REFERENCE_SIGNAL_COUNT[] = {0x070};//adress
uint32_t RESULT__RANGE_RETURN_AMB_COUNT [] = {0x074};//adress
uint32_t RESULT__RANGE_REFERENCE_AMB_COUNT [] = {0x078};//adress
uint32_t RESULT__RANGE_RETURN_CONV_TIME [] = {0x07C};//adress
uint32_t RESULT__RANGE_REFERENCE_CONV_TIME [] = {0x080};//adress

uint16_t result;
float distance;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
/
USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------/
/
USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

  • @brief The application entry point.
  • @retval int
    /
    int main(void)
    {
    /
    USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals /
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
/
USER CODE BEGIN 2 */
while(HAL_I2C_IsDeviceReady(&hi2c1, 0x52, 3, 100) != HAL_OK)
{}

HAL_I2C_Master_Transmit(&hi2c1, 0x53,(uint8_t *)&I2C_adress, 2, 100); //writing slave address register with
//desired value
HAL_Delay(10);
HAL_I2C_Master_Transmit(&hi2c1, 0x53,(uint8_t )&SYSALS__START, 3, 100); //writing the command to start conversion
HAL_Delay(10);
/
USER CODE END 2 */

/* Infinite loop /
/
USER CODE BEGIN WHILE /
while (1)
{
/
USER CODE END WHILE */

/* USER CODE BEGIN 3 */
HAL_I2C_Master_Transmit(&hi2c1, 0x53, RESULT__ALS_VAL, 2, 100);
HAL_Delay(100);
HAL_I2C_Master_Receive(&hi2c1, 0x52,  result, 1, 100);
distance = result;

}
/* USER CODE END 3 */
}

Hello I definately found the solution. Thanks a lot :innocent: :innocent: :innocent: :innocent: :innocent: :innocent: