Technical difficulties with the color sensor rgb VEML6040 with I2c interface

Hello i starting with arduino and i try to communicate with this sensor but the back informations is not correctly. so i think my software is not correct but i don’t know where if you know why the sensor don’t function can you explain my please ?
i join my code with datasheet of the sensor.

/* le capteur Veml6040 est une photodiode RGB qui communique en I2C et qui permet de donner les informations de chaque couleurs rouge vert bleu*/

my code

#define VEML6040Adress 16
#include <Wire.h>

void setup()
Serial.begin(9600); //initialisation du port série

void initSensor(int dataByteLow) //initialisation du capteur mise en route ou arret
writeVEML6040(0,dataByteLow,0); //envoi les données de configuration

void writeVEML6040(int commandOrder, int dataByteLow, int dataByteHigh) //sous programme permettant l’écriture du maitre vers l’esclave
Wire.beginTransmission(VEML6040Adress); //début de la communication et transmission de l’adresse esclave
Wire.write(commandOrder); //envoi du code commande
Wire.write(dataByteLow); //envoi du byte de poids faible
Wire.write(dataByteHigh); //envoie du byt de point fort
Wire.endTransmission(); //fin de transmission

int readVEML6040(int commandOrder) //sous programme permettant la lecture des donées
int data=0; //variable de transfert de l’information
Wire.beginTransmission(VEML6040Adress); //début de la communication
Wire.write(commandOrder); //envoi de l’adresse du registre
Wire.requestFrom(VEML6040Adress,2); //Attente de réponse de l’automate
while(Wire.available()) //lorsque les deux donnée sont disponible
{; //lecture du byte de poid faible
data|<<8; //lecture du byte de poid fort
return data; //retour de la valeur

void loop()
{ //programme principal
int Red,Green,Blue,White; //variable image des valeurs des couleurs
initSensor(80); //mise en route du capteur
delay(1300); //delays d’acqusition de la valeur
initSensor(81); //arret du capteur
Red=readVEML6040(8); //recherche de la valeur de la coueur rouge
Green=readVEML6040(9); //recherche de la valeur de la coueur verte
Blue=readVEML6040(10); //recherche de la valeur de la coueur bleu
White=readVEML6040(11); //recherche de la valeur de la coueur white
Serial.println(Red); //affichage de la valeur de la couleur rouge
Serial.println(Green); //affichage de la valeur de la couleur bleu
Serial.println(Blue); //affichage de la valeur de la couleur verte
Serial.println(White); //affichage de la valeur de la couleur blanche

link datasheet

Hi, welcome to the forum.

Please read this :,148850.0.html
Number 7 is about showing a sketch with code tags.

Manufacturers page about the VUML6040 :

How did you connect the sensor and which Arduino board do you use ?
The sensor is a 3.3V sensor and many Arduino boards are 5V.

Run the i2c_scanner :
The i2c_scanner should find the address, if it doesn't then the wiring is probably wrong.

Your function to read data is not okay.
The "Wire.write" should be encapsulated with "Wire.beginTransmission" and "Wire.endTransmission", but the "Wire.requestFrom" is on its own. Move the "Wire.endTransmisson" after the "Wire.write". Make that Wire.endTransmission(false) ;" for a repeated start, I think that is what the datasheet shows.

The while-loop has no use, just read two data bytes, since only two bytes are requested. You could do a check if something is received with : if ( Wire.available() == 2 )

Could you write the commands '80' and '81' as hex or binary ?
80 (decimal) = 0x50 (hexadecimal) = 0101 0000 = IT0 + IT2
81 (decimal) = 0x51 (hexadeciaml) = 0101 0001 = IT0 + IT2 + SD
The IT0 + IT2 is for 1280ms.
The "SD" is Chip Shutown and it disables the sensor. In the datasheet they say that the data in the registers can be read after that. So that is okay.

I think you can read all sensor data at once by reading 8 bytes.

Hello yes i connect in 3.3V on my board. i found the problem is it the repeat started for the read protocol so i miss the code Wire.endTransmission(false); which he permet to keep the line on mode.
thank you for your answers.