The demo code for the LTR-329 (and LTR-303?) is for the Arduino. I needed code for CircuitPython on the RP2040 microcontroller. This is what I have come up with. The while True() or False statement shows the two methods of extracting the data.
Code: Select all
# CircuitPython example for the LTR-329
# It has only been tested on the RP2040 microcontroller
# Probably will work for the LTR-303
# Written by B.Blake 9/5/2022
import time
import board
import busio
import adafruit_ltr329_ltr303 as LTR_329
i2c = busio.I2C(board.GP7, board.GP6)
address = 0x29
ltr = LTR_329.LTR329(i2c, address)
#ALS Gain can be set to: 1, 2, 4, 8, None, None, 48 or 96 times
ltr.als_gain = 1 # Default=1
# ALS Intigration Time can be set to: 50, 100, 150, 200, 250, 300, 350, or 400 millisec
ltr.integration_time = 50 # Default=100
# ALS Measurment Rate can be set to: 50, 100, 200, 500, 1000, 2000 millisec
ltr.measurement_rate = 500 # Default=500
LTR_Flag = True # ltr_329() True shows additional info)
#import Adafruit_LTR329_LTR303
#Adafruit_LTR329 ltr = Adafruit_LTR329()
if LTR_Flag:
print("\f *LTR-329*\t\bALS gain:", ltr.als_gain)
print("\t\bIntegration Time:", ltr.integration_time, "ms")
print("\t\bMeasurement Rate:", ltr.measurement_rate, "ms")
print("")
print("\tManufacturer ID:", ltr.manufacturer_id)
print("\t\tPart ID:", ltr.part_id)
print("\t\t\bNew Data:", ltr.new_als_data_available)
print("\t Invalid Data:", ltr.als_data_invalid)
print("")
while True:
if ltr.new_als_data_available and not ltr.als_data_invalid:
if True: # Two ways to get the light values
VpIR_, IR_ = ltr.light_channels
V_ = VpIR_ - IR_
else:
VpIR_ = ltr.visible_plus_ir_light
IR_ = ltr.ir_light
V_ = ltr.visible_light
print("\t Visible Light: %d, IR Light: %d, Visible+IR Light: %d\r" % (V_, IR_, VpIR_), end='')
time.sleep(1)
Bruce