#!/usr/bin/python # VEML6070 import smbus import time addrLow = 0x38 addrHight = 0x39 IT = 4 # RSET=270K, IT = 0...4T UV_c = [ 94, 184, 374, 747] COM = [0x02,0x06,0x0A,0x0E] # Get I2C bus bus = smbus.SMBus(1) # Command register, Write to 0x38 # 0x0E == 4T = 500ms bus.i2c_write_byte(addrLow, COM[IT]) time.sleep(0.6) # Read MSB data back from 0x39 data0 = bus.i2c_read_byte(addrHight) # Read LSB data back from 0x38 data1 = bus.i2c_read_byte(addrLow) # Convert the data uv = data0 * 256 + data1 uvi = uv / UV_c[IT] # Output data to screen print "UV : %d" %uv print "UV index: %d" %uvi