9 years, 6 months ago.

VL6180X Explorer Shield & Nucleo F401RE - Register write app

Is there an app to allow me to write to the VL6180 registers? I want to set the 'cross talk' to compensate for a glass cover.

2 Answers

9 years, 6 months ago.

Here is a simple program that will read the Device ID and print it to a PC terminal program like Tera Term.

  1. include "mbed.h"

-------- Hyperterminal configuration 9600 bauds, 8-bit data, no parity --------

VL6180X defines

  1. define VL6180X_DEF_ADDR 0x52
  2. define IDENTIFICATIONMODEL_ID 0x0000

Serial pc(SERIAL_TX, SERIAL_RX); I2C i2c(I2C_SDA, I2C_SCL);

DigitalOut myled(LED1);

int main() {

char data_write[3]; char data_read[2];

data_write[0] = VL6180X_DEF_ADDR; data_write[0] = ( (IDENTIFICATIONMODEL_ID &0xff00 ) >> 8); data_write[1] = (IDENTIFICATIONMODEL_ID &0x00ff ) ;

while(1) {

i2c.write(VL6180X_DEF_ADDR, data_write, 2, 1); no stop i2c.read(VL6180X_DEF_ADDR, data_read, 1, 0); wait(1); pc.printf("The attached part Model ID is: 0x%x /n/r", data_read[0]); wait(2.0); if ( data_read[0] == 0xB4 ) { myled = !myled; }if } }

To write to a register add the data to the 3rd byte of data_write and write all 3 bytes with;

i2c.write(VL6180X_DEF_ADDR, data_write, 3, 0); changing the 1 to will add the I2C stop bit

you can put that in the function like this :

/***************

  • Function Name: writeByte()
  • description: Writes a byte to a register. Wrapper for other code.
  • Parameters:
  • reg: VL6180X Register address for the 1st byte
  • data: Data byte to write to
  • Return: 0 = I2C write success
    • / int writeByte(wchar_t reg, char data) { char data_write[3];

data_write[0] = (reg >> 8) & 0xFF;; MSB of register address data_write[1] = reg & 0xFF; LSB of register address data_write[2] = data & 0xFF; return i2c.write(addr, data_write, 3); }

If you are writing your own app you will need to initialize and configure the device before starting any ranging function see the data sheet and app notes available on www.st.com/VL6180X

Accepted Answer

I didn't get the code formatted correctly and the editing didn't seem to take. So here it is again:

Here is a simple program that will read the Device ID and print it to a PC terminal program like Tera Term.

Read_VL6180_ID

include "mbed.h"
//Hyperterminal configuration 
//9600 bauds, 8-bit data, no parity 

//VL6180X defines

#define VL6180X_DEF_ADDR 0x52
#define IDENTIFICATIONMODEL_ID 0x0000


Serial pc(SERIAL_TX, SERIAL_RX); 
 I2C i2c(I2C_SDA, I2C_SCL);

DigitalOut myled(LED1);

int main() {

char data_write[3]; char data_read[2];

data_write[0] = ( (IDENTIFICATIONMODEL_ID &0xff00 ) >> 8); 
data_write[1] = (IDENTIFICATIONMODEL_ID &0x00ff ) ;

  while(1) {

    i2c.write(VL6180X_DEF_ADDR, data_write, 2, 1); //no stop 
    i2c.read(VL6180X_DEF_ADDR, data_read, 1, 0); 
    wait(1); 
    pc.printf("The attached part Model ID is: 0x%x /n/r", data_read[0]); 
    wait(2.0); 
    if ( data_read[0] == 0xB4 ) 
    { 
         myled = !myled; 
    }//if 
  }//while 
}

To write to a register add the data to the 3rd byte of data_write and write all 3 bytes with;

i2c.write(VL6180X_DEF_ADDR, data_write, 3, 0); changing the 1 to will add the I2C stop bit

you can put that in the function like this :

writeByte Function

//****************************************
//Function        Name: writeByte()
//description:   Writes a byte to a register. Wrapper for other code.
//Parameters:
//       reg: VL6180X Register address for the 1st byte
//       data: Data byte to write to
//  Return:     0 = I2C write success
//************************************** 
int writeByte(wchar_t reg, char data) 
{ 
    char data_write[3];
    data_write[0] = (reg >> 8) & 0xFF; //MSB of register address 
    data_write[1] = reg & 0xFF; //LSB of register address 
    data_write[2] = data & 0xFF; 
    return i2c.write(addr, data_write, 3); 
}

If you are writing your own app you will need to initialize and configure the device before starting any ranging function see the data sheet and app notes available on www.st.com/VL6180X

posted by Ken Weiner 06 Oct 2014

Thanks Ken for information, I will be trying this. I also put this to ST and have included the reply (minus the images unfortunately) :-

Dear Peter,

Sorry for the long time we needed to get the answer.

The NUCLEA shield today does not provide a facility to do Xcross compensation with access to registers. This is today only possible with our PREMIUM eval kit + V2Wreg SW supporting register access. The shield is a pure demonstrator of the VL6180X performance. In any case the PREMIUM kit is able to be ordered at your ST distributor.

Nevertheless we opened a ticket to get register access into the GUI SW of the shield but needs to be developed.

Another quick solution with the EXPLORER shield is to write into the device through the USB com by TERATERM. We knew Teraterm to printf on my PC, but it can do much more.

Please follow the instructions and help info

If you want to use two application with the same Real com port you can do the following:

1. Install com0com : The homepage for com0com project is http://com0com.sourceforge.net/ 2. Download hub4com.exe 3. From com0com install area run setupg.exe 4. Create 2 pair of port com, change the name to COM17 and COM19:

5. Wait that all the driver have been installed. a. Note that this take long time and the system ask you if you want to wait… please wait :-) 6. Open a console with admin right 7. Run the following command: a. hub4com bi-route=0:1,2
.\COM33
.\CNCB0
.\CNCB1 b. this will rout all the request of COM33 to COM17 and COM19 but also all the request from COM17 to COM33 and all the request COM19 to COM33 c. Note that you can customize this command to avoid to have all the Application1 to Application2 input and vice versa. For that please see the readme in hub4com

This can be used to spy Serial communication

We hope that we could solve your problems

Best regards

posted by Peter Redmond 09 Oct 2014
9 years, 6 months ago.

Interesting chip. I think you have to ask ST. The user manual speak about a sample project, but it is not here.

Thank you for the article!

But I had some problem. I installed com0com for virtual serial port. It worked in Win 7 but not in Win 8.1 because the driver are not signed. But I found other software Null Modem Emulator. It works in the same way as com0com and totally supports Windows http://www.eltima.com/products/virtual-null-modem/

posted by Helen Reynolds 21 Feb 2017