BreakoutLTR559(i2c) does not raise an error when LTR559 is not present

When running the LTR559 breakout example program ( pimoroni-pico/micropython/examples/breakout_ltr559/demo.py at main · pimoroni/pimoroni-pico · GitHub ) using pico_plus2-v1.29.0-2-pimoroni-micropython.uf2 on my Pico Plus 2 W (A4 stepping), without an LTR559 attached, it reports:

Found LTR559. Part ID: 0x01

Shouldn’t it raise an error, rather than claiming to have found a non-existent LTR559?

This problem also occurs with pico_plus2_rp2350-v0.0.9-pimoroni-micropython.uf2

Later I tried it on a Plasma 2040 W running picow-55ceb1fc3e50f14c1e1ea0be73c429e0ddb3a4e0-pimoroni-micropython.uf2 ( RV3028 BreakoutRTC - Pico 2W + Breakout Garden - device not recognised - #8 by hel ), and found that also claimed an LTR559 existed when it didn’t.

In all cases it works fine when the LTR559 breakout is plugged in.

I am trying to test whether an LTR559 is present or not. I have worked around this issue by leaving a short delay after initialisation, then calling get_reading() and checking for a None response, but surely this shouldn’t be necessary…

Has anyone else seen this behaviour?

Yeah, looks like that old example just prints “Found LTR559” either way, which is not ideal!

Try this instead - you don’t need to specify the default I2C pins these days either, as they’re baked into the MicroPython build :)

import time
import machine
from breakout_ltr559 import BreakoutLTR559

i2c = machine.I2C()

if 0x23 in i2c.scan():
    ltr = BreakoutLTR559(i2c)

    part_id = ltr.part_id()
    print("Found LTR559. Part ID: 0x", "{:02x}".format(part_id), sep="")

    while True:
        reading = ltr.get_reading()
        if reading is not None:
            print("Lux:", reading[BreakoutLTR559.LUX], "Prox:", reading[BreakoutLTR559.PROXIMITY])

        time.sleep(0.1)

else:
    print("LTR559 not found on I2C bus. Check wiring.")

Thanks hel, that’s great, I’ll update my program.

And thanks for the I2C tip, I hadn’t realised that.