It’s a bit maddening to see the ltr-559 sensor linked from the plasma2040 sales page but not have any working code. This code /should/ work, as I can import the ltr559 library into Thonny:
import time
import plasma
from plasma import plasma2040
from ltr559 import LTR559
sensor = LTR559()
try:
while True:
sensor.update_sensor()
lux = sensor.get_lux()
prox = sensor.get_proximity()
print("Lux: {:06.2f}, Proximity: {:04d}".format(lux, prox))
time.sleep(0.05)
except KeyboardInterrupt:
pass
But it doesn’t. I get this error:
MPY: soft reboot
Traceback (most recent call last):
File “”, line 10, in
File “/lib/ltr559/init.py”, line 213, in init
File “/lib/i2cdevice/init.py”, line 165, in init
File “/lib/smbus2/init.py”, line 23, in
File “/lib/smbus2/smbus2.py”, line 25, in
ImportError: no module named ‘fcntl’
which seems to be a dead end.
It feels like pimoroni wants us to use this sensor with the plasma2040, but I’m at my wits end here. Thanks for any help you can provide.
import time
from plasma import plasma2040
from pimoroni_i2c import PimoroniI2C
from breakout_ltr559 import BreakoutLTR559
i2c = PimoroniI2C(plasma2040.SDA, plasma2040.SCL)
sensor = BreakoutLTR559(i2c)
try:
while True:
reading = sensor.get_reading()
lux = reading[BreakoutLTR559.LUX]
prox = reading[BreakoutLTR559.PROXIMITY]
print("Lux:", lux, "Prox:", prox)
time.sleep(0.05)
except KeyboardInterrupt:
pass
This code works if and only if I print out the variable “reading” in its entirety. If I try to access any of "reading"s components using the subscript in the example above, I get the error
Traceback (most recent call last):
File "<stdin>", line 14, in <module>
TypeError: 'NoneType' object isn't subscriptable
If I run the same code in the Thonny command line, it works just fine.
What’s the difference between running the code in the command line versus a program?
Yeah, you have to setup i2c to read the sensor.
I use an LTR-559 for auto brightness on my Interstate 75 W.
To get just the Lux, and ignore the Proximity I use the following.
Nice, I may give that a go on my Plasma setup. I tried to do something similar with a BH1745. That stalled and I never got back to it. I wanted to auto adjust the color and intensity. Right now I set the color with the buttons on an Encoder Wheel. Then adjust the brightness with the wheel (rotating ring). Want to use a BH1745 for Ambient Lighting - Support - Pimoroni Buccaneers