Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_isl29125 import isl29125
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
isl = isl29125.ISL29125(i2c)
while True:
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1)
Operation Mode¶
Example showing how to change the sensor operation mode
from machine import Pin, I2C
from micropython_isl29125 import isl29125
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
isl = isl29125.ISL29125(i2c)
print("Red Luminance: ", isl.red)
print("Current Operation Mode Value: ", bin(isl.operation_mode))
# Changing Operation Mode to Blue Only
isl.operation_mode = isl29125.BLUE_ONLY
print("Changed Operation mode to Blue Only:", bin(isl.operation_mode))
print("Red Luminance after change: ", isl.red)
RGB Sensing Range¶
Example showing how to change the sensor RGB sensing range
import time
from machine import Pin, I2C
from micropython_isl29125 import isl29125
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
isl = isl29125.ISL29125(i2c)
print("Current Sensing Range Value: ", bin(isl.sensing_range))
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1)
isl.sensing_range = isl29125.LUX_375
print("Changed Sensing Range to 375 lux:", bin(isl.sensing_range))
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1)
ADC Resolution¶
Example showing how to change the sensor ADC Resolution
import time
from machine import Pin, I2C
from micropython_isl29125 import isl29125
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
isl = isl29125.ISL29125(i2c)
print("Current Sensing Range Value: ", bin(isl.sensing_range))
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1)
isl.sensing_range = isl29125.LUX_375
print("Changed Sensing Range to 375 lux:", bin(isl.sensing_range))
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1)
Threshold Example¶
Example showing the threshold window setting
import time
from machine import Pin, I2C
from micropython_isl29125 import isl29125
switch_pin = Pin(5, Pin.IN)
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
isl = isl29125.ISL29125(i2c)
print("Current High Threshold: ", isl.high_threshold)
print("Current Low Threshold: ", isl.low_threshold)
isl.interrupt_threshold = isl29125.BLUE_INTERRUPT
print("Setting up Blue Threshold window to 100-300 Lux")
isl.high_threshold = 300
isl.low_threshold = 100
print("Current High Threshold: ", isl.high_threshold)
print("Current Low Threshold: ", isl.low_threshold)
while True:
print("INT Pin Value:", switch_pin.value)
isl.clear_register_flag()
red, green, blue = isl.colors
print("Red Luminance: ", red)
print("Green Luminance: ", green)
print("Blue Luminance:", blue)
time.sleep(1.5)