Try to use a VEML7700 to get lux information but I can't get it to work.
It use I2C protocol and i have connected this to port 9/10.
The only response i got is 0 (zero)
What have I done wrong ?
/Leif
Code: Select all
#include "Wire.h"
#define VEML7700_I2CADDR 0x10 ///< I2C address
#define VEML7700_ALS_CONFIG 0x00 ///< Light configuration register
#define VEML7700_ALS_THREHOLD_HIGH 0x01 ///< Light high threshold for irq
#define VEML7700_ALS_THREHOLD_LOW 0x02 ///< Light low threshold for irq
#define VEML7700_ALS_POWER_SAVE 0x03 ///< Power save regiester
#define VEML7700_ALS_DATA 0x04 ///< The light data output
#define VEML7700_WHITE_DATA 0x05 ///< The white light data output
#define VEML7700_INTERRUPTSTATUS 0x06 ///< What IRQ (if any)
#define ALS_GAIN 0b10 // Gain = 1/8
#define ALS_IT 0b1000 // 50 ms
#define ALS_PERS 0b00
#define ALS_INT_EN 0b00
#define ALS_SD 0b00
#define cmd00 ( (ALS_GAIN << 11) | (ALS_IT << 6) |(ALS_PERS << 4) |(ALS_INT_EN << 1) | (ALS_SD << 0) )
void setup() {
Serial.begin(9600);
Wire.begin(); // wake up I2C bus
SendData(VEML7700_ALS_CONFIG,cmd00);
SendData(VEML7700_ALS_THREHOLD_HIGH,0x00);
SendData(VEML7700_ALS_THREHOLD_LOW,0x00);
SendData(VEML7700_ALS_POWER_SAVE,0x00);
}
void loop() {
readlux();
delay(1000);
}
void readlux() {
uint32_t data;
data = ReceiveData(VEML7700_ALS_DATA);
Serial.println(data,DEC);
}
void SendData(uint8_t command, uint32_t data)
{
Wire.beginTransmission(VEML7700_I2CADDR);
Wire.write(command);
Wire.write(uint8_t(data & 0xff));
Wire.write(uint8_t(data >> 8));
Wire.endTransmission();
}
uint32_t ReceiveData(uint8_t command)
{
uint32_t data;
Wire.beginTransmission(VEML7700_I2CADDR);
Wire.write(command);
Wire.endTransmission();
Wire.requestFrom(uint8_t(VEML7700_I2CADDR), uint8_t(2));
data = Wire.read();
data |= uint32_t(Wire.read()) << 8;
Wire.endTransmission();
return data;
}