I'm using the tsl2561.py module on an ESP8266-12E with 4 MByte.
As docu I used this
http://micropython-tsl2561.readthedocs. ... l2561.html
and this
https://media.readthedocs.org/pdf/micro ... sl2561.pdf
This is my code:
Code: Select all
import micropython
import machine
from time import sleep
import sys
import tsl2561
from machine import I2C, Pin
i2c = I2C(-1,Pin(5), Pin(4))
sensor = tsl2561.TSL2561(i2c)
sensor.active(True)
sleep(1)
sensor.threshold(-1,0,0)
micropython.alloc_emergency_exception_buf(100)
def my_Interrupt_Handler(pin):
global stopLoop
if stopLoop == False:
stopLoop = True
print("interrupt")
#global sensor
#sensor.threshold(-1,0,0)
#sensor.interrupt(False)
# 0 == D3
pin = Pin(0, Pin.IN, Pin.PULL_UP)
pin.irq(trigger = machine.Pin.IRQ_FALLING, handler = my_Interrupt_Handler)
print("Pin val=" + str(pin.value()))
stopLoop = False
def IRQ_demo(sensor,pin,stopLoop):
# activate interrupt
sensor.threshold(0,10,20)
sleep(1)
loop = 0
while 1:
loop = loop + 1
val = pin.value()
print("loop = " + str(loop) + " light = " + str(sensor.read()) + " pin val=" + str(val))
sleep(1)
if stopLoop == True:
print('got interrupt from TLS2561')
stopLoop = False
# reset and set threshold again
sensor.threshold(-1,0,0)
sensor.interrupt(False)
sensor.threshold(0,10,20)
IRQ_demo(sensor,pin,stopLoop)
After I got an interrupt I try to reset interrupt by calling sensor.threshold(-1,0,0,). Then the pin has the value 1 again.
But in the moment when I set threshold to 0,10,20 the pin value changes directly to 0 again.
Furthermore I'm not sure if the interrupt should arise when the light value is between min and max or if it is lower than min and higher than max.
But I tried both scenarios.
What am I doing wrong?
Also the short example code from the second document mentioned above does not work for me.
Hope that anybody can help me.
Thanks a lot in advance.
Best regards, Uwe