I'm looking to program a nodemcu (esp8266) with an external component that is the veml7700.
here is the datasheet: http://www.vishay.com/docs/84323/designingveml7700.pdf
here is the tutorial for arduino.
https://www.dfrobot.com/wiki/index.php/ ... U:_SEN0228
a solution made of pure python.
I try to adapt it but I block completely on the byte reader.
if a nice person could guide me through how the functions work:
I2C.readfrom_memem(addr, memaddr, nbytes, *, addrsize=8)
and
I2C.readfrom_mem_into(addr, memaddr, buf, *, addrsize=8)
the same for their equivalent in writing mode.
here is my program start
Code: Select all
#station meteo
#import standard library
import machine
import time
from ustruct import unpack, unpack_from
from array import array
# import special library
import bme280
import bh1750 # librairie capteur BH1750
#start configuration machine
machine.freq(160000000) # set the CPU frequency to 160 MHz
#end of configurartion machine
# address of external captor
bme280_addr = 0x76
vmle7700_addr = 0x10
# activate i2c port
i2c = machine.I2C(scl=machine.Pin(5),sda=machine.Pin(4))
#create BJ1750 "object"
capteur_lumiere = bh1750.BH1750(i2c)
#start software
#start scan i2c buss
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
#end scan i2c bus
print("debut calcul")
i=0
while i<2:
word=i2c.readfrom_mem(vmle7700_addr,6,2)
print(word)
tempo = unpack('<h',word)
print("tempo 1 : ",tempo)
tempo = unpack('>h',word)
print("tempo => ",tempo)
gain = 1.8432 #Gain for 1/8 gain & 25ms IT
if (capteur_lumiere.detect()):
mesure_lux = capteur_lumiere.lecture_lumiere(bh1750.MODE_CONTINU_HAUTE_RESOLUTION)
print("Valeur BH1750 : ")
print("la mesure est de ", mesure_lux, " lux")
time.sleep(1)
else :
print("Capteur BH1750 non")
print("Fin boucle")
i=i+1