I don't work change address - VL53L1X sensor

Hi,
I have 4 VL53L1X sensor ( POLOLU board ), but i can’t change the address the a VL53L1X sensor setting the register.If i use the default address the sensor response correctly. To avoid the problems i development a only sensor. Can you help me ? It’s urgent ! Thanks you.

This my code:

#define AddressDefault 0x29

// Indirizzi 4 sensori di distanza
#define ADDRESS_VL1 0x29
#define ADDRESS_VL2 0x33
#define ADDRESS_VL3 0x35
#define ADDRESS_VL4 0x37

bool VL53L1X_init ( bool io_2v8 , uint8_t tmp_addr )
{
	writeReg ( SOFT_RESET, 0x00 ) ;
	nrf_delay_ms ( 1 ) ;
	writeReg ( SOFT_RESET, 0x01 ) ;
	
	nrf_delay_ms ( 1000 ) ;

        // check model ID and module type registers (values specified in datasheet)
	if ( readReg16Bit ( IDENTIFICATION__MODEL_ID ) != 0xEACC )
	     return false ;
	
	// Setto il nuovo address
	setAddress ( tmp_addr ) ;

	nrf_delay_ms ( 100 ) ;
	
	// check model ID and module type registers (values specified in datasheet)
	if ( readReg16Bit ( IDENTIFICATION__MODEL_ID ) != 0xEACC )
	return false ;

	return true ;

}

//////////////////////////////////////////////////////////////
// Setto il nuovo indirizzo
void setAddress ( uint8_t new_addr )
{
writeReg ( I2C_SLAVE__DEVICE_ADDRESS , new_addr & 0x7F ) ;

address = new_addr ;

}

//////////////////////////////////////////////////////////////
void main ( )
{
      ....
     nrf_delay_ms ( 100 ) ;
      VL53L1X_init( false , ADDRESS_VL2  ) 
     ....
}

I understand that the address is not change because the sensor when i request the MODEL ID, after change the address, it not response.

Regards,

Hello.

It does not look like you are controlling the XSHUT pins for your VL53L1X sensors in your program. ST provides an application note that describes how to use multiple VL53L0X sensors on the same I2C bus. That approach can be adapted to apply to the VL53L1X sensors. You can find more details on how to assign multiple VL53L1X sensors their unique addresses and a link to the application note under the “I2C communication” heading on the VL53L1X carrier’s product page.

- Amanda

Hi,

At first i using only one sensor for the development. But i can’t to change the address at one sensor. How you see in the my code, first i request the model ID (0x010F) and the sensor responds correctly (0xEACC), after that i tried to change the address, when i request again the model id the sensor don’t response. Why ?

Thanks you,

Regards,

Can you confirm that you are using the new address in your address variable? Can you post the code for your readReg16Bit() and writeReg() functions, as well as the scope and declaration of the address variable?

- Amanda

Hi,
Yes, i confirm that i used a new address. In fact, in my code i pass at the function VL53L1X_init the parameters ADDRESS_VL2 (0x33). The address the default is 0x29.

void main ( )
{
      ....
     nrf_delay_ms ( 100 ) ;
     address = AddressDefault ;
      VL53L1X_init( false , ADDRESS_VL2 ) ;
     ....
}
/////////////////////////////////////////////
uint16_t	readReg16Bit ( uint16_t reg )
{
  uint16_t value ;
	
	uint8_t buff_reg [ 2 ] = "" ;
	
	buff_reg [ 0 ] = ( reg >> 8 ) & 0xFF ;
	buff_reg [ 1 ] = reg          & 0xFF ;
 	
	nrf_drv_twi_tx ( &m_twi , address , buff_reg , 2 , false ) ;

	// Leggo la risposta
	uint8_t buff_res [ 2 ] = "" ;
	
	nrf_drv_twi_rx ( &m_twi , address , buff_res , 2 ) ;

  value  = ( uint16_t ) buff_res [ 0 ] << 8 ; // value high byte
  value |=              buff_res [ 1 ] ;      // value low byte

	return value ;
	
}

// Write an 8-bit register
void			writeReg ( uint16_t reg , uint8_t value )
{	
	uint8_t buff_reg [ 2 ] = "" ;
	
	buff_reg [ 0 ] = ( reg >> 8 ) & 0xFF ;	// reg high byte
	buff_reg [ 1 ] = reg          & 0xFF ;	// reg low byte
 	
	nrf_drv_twi_tx ( &m_twi , address , buff_reg , 2 , false ) ;
	
}

I am developing the sensor in the nordic nrf52840 board. The nrf_drv_twi_tx and nrf_drv_twi_tx are functions default provided by Nordic, it used for communication in I2C .

In fact using the address 0x29 the sensor responde at the firt request MODEL ID. After i change the adress, at the second request MODEL ID using the new address (0x33) the sensor not response.

Regards,

Hi, GianmarcoUtech.

It looks like your writeReg() function is not actually sending the value over I2C:

// Write an 8-bit register
void			writeReg ( uint16_t reg , uint8_t value )
{	
	uint8_t buff_reg [ 2 ] = "" ;
	
	buff_reg [ 0 ] = ( reg >> 8 ) & 0xFF ;	// reg high byte
	buff_reg [ 1 ] = reg          & 0xFF ;	// reg low byte
 	
	nrf_drv_twi_tx ( &m_twi , address , buff_reg , 2 , false ) ;
	
}

You are only sending two bytes (both bytes of reg) and you’re not doing anything with value. Compare what our Arduino library does:

// Write an 8-bit register
void VL53L1X::writeReg(uint16_t reg, uint8_t value)
{
  Wire.beginTransmission(address);
  Wire.write((reg >> 8) & 0xFF); // reg high byte
  Wire.write( reg       & 0xFF); // reg low byte
  Wire.write(value);
  last_status = Wire.endTransmission();
}

Note that it sends a total of 3 bytes: the 2-byte reg and the 1-byte value.

Kevin

Hi,

Thanks you ! I have resolved my problem.

Hi everyone, a question, is there any way to memorize the changed address in Vl53L1x? When I hang up, it returns to the default 0x29.

Hello.

These sensors revert to the default address when power cycled. If you did not already know (and for those following this thread) that information is documented under the “I2C communication” section on the VL53L1X’s product page. Depending on your application, you can change the address of the sensor at the start of your program when power is reestablished using setAddress() in the VL53L1X library for Arduino.

- Amanda