Posts: 2
Joined: Tue Mar 28, 2017 2:27 pm

[Solved] VEML-7700 I2c

Tue Mar 28, 2017 2:35 pm

I would like use VEML-7700 light ambient sensor with raspberryPI. I wrote the code above, but i can only read the 03h register. I use the i2cset and i2cget command with a same result.
What could be the problem?

Code: Select all

#include <iostream>
#include <errno.h>
#include <wiringPiI2C.h>

using namespace std;

int main(int argc, char **argv)
	unsigned int command = ALSSM_x18|ALSIT_200|ALSPERS_1|ALSINT_DI|ALSSD_ON; //0x1040
	int fd, result;
	fd = wiringPiI2CSetup(address);
	result = wiringPiI2CWriteReg16(fd,0x00,command);
	if(result == -1)
		cout << "Error.  Errno is: " << errno << endl;
		command = ALSPSM_1|ALSPSM_DI; //0x0000
		result = wiringPiI2CWriteReg16(fd,0x03,command);
		if(result == -1)
			cout << "Error.  Errno is: " << errno << endl;
				result = wiringPiI2CReadReg16 (fd, 0x04);
Last edited by hodlemil on Sat Apr 22, 2017 1:52 pm, edited 1 time in total.

Posts: 2
Joined: Tue Mar 28, 2017 2:27 pm

Re: VEML-7700 I2c

Tue Apr 18, 2017 9:07 pm

I solved the problem. I enabled the repeated start with this command:

Code: Select all

sudo sh -c 'echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined'
It works after reboot, with the aboved code:

Code: Select all

sudo sh -c 'echo options i2c_bcm2708 combined=1 > /etc/modprobe.d/i2c_repeated_start.conf'

Posts: 4
Joined: Thu Mar 22, 2018 5:05 pm

Re: [Solved] VEML-7700 I2c

Thu Mar 22, 2018 5:13 pm

I'm posting a reply here because I ran into similar problems trying to write python script for this component. This one of only two results I got google searching veml7700 and raspberry pi. I contacted Vishay and they were very helpful in working with this component.

Here is the sample python script I wrote for the VEML7700:

Code: Select all

import smbus
import time

bus = smbus.SMBus(1)

addr = 0x10

#Write registers
als_conf_0 = 0x00
als_WH = 0x01
als_WL = 0x02
pow_sav = 0x03

#Read registers
als = 0x04
white = 0x05
interrupt = 0x06

# These settings will provide the max range for the sensor (0-120Klx)
# but at the lowest precision:
#              LSB   MSB
confValues = [0x00, 0x13] # 1/8 gain, 25ms IT (Integration Time)
#Reference data sheet Table 1 for configuration settings

interrupt_high = [0x00, 0x00] # Clear values
#Reference data sheet Table 2 for High Threshold

interrupt_low = [0x00, 0x00] # Clear values
#Reference data sheet Table 3 for Low Threshold

power_save_mode = [0x00, 0x00] # Clear values
#Reference data sheet Table 4 for Power Saving Modes

bus.write_i2c_block_data(addr, als_conf_0, confValues)
bus.write_i2c_block_data(addr, als_WH, interrupt_high)
bus.write_i2c_block_data(addr, als_WL, interrupt_low)
bus.write_i2c_block_data(addr, pow_sav, power_save_mode)

while True:
	#The frequency to read the sensor should be set greater than
	# the integration time (and the power saving delay if set).
	# Reading at a faster frequency will not cause an error, but
	# will result in reading the previous data
	time.sleep(.04) # 40ms 

	word = bus.read_word_data(addr,als)
	gain = 1.8432 #Gain for 1/8 gain & 25ms IT
	#Reference www.vishay.com/docs/84323/designingveml7700.pdf
	# 'Calculating the LUX Level'
	val = word * gain
	val = round(val,1) #Round value for presentation
	print "Lux: " + str(val) + " lx"
I hope this helps the next pi user with trying to interface with this component. good luck.

Joe Robidoux

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 4 guests