Feather S2, ALS-PT19, Converting Pin Value Lux

Hello all!

The Feather S2 has an on-board ALS-PT19 ambient light sensor that I'm reading using:

import board
import digitalio
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
import time

light_sensor = AnalogIn(board.AMB)
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

start_calibration_timestamp = time.monotonic()

led.value = True
initial_sensorvalue = 0.0
while True:

    if time.monotonic() - start_calibration_timestamp >= 2.0:
        print("Sensor Value: ", light_sensor.value, "Time: ", time.monotonic())
        start_calibration_timestamp = time.monotonic()
        led.value = not led.value  # Toggle the LED

With the board sitting on my desk, unobstructed, the Serial Monitor displays "Sensor Value: 50720". Putting the board under a coat, the output will drop as low as 119.

Reading the Feather's datasheet, the ALS-PT19 is connected to 3.3v with a 100k resistor. If I take the board outside or shine a cell phone camera light on the sensor, the same value of 50720 is displayed.

From ESPRESSIF, the ADC is 12bit, maximum value of 8192. This leads me to believe the ADC is upscaling to 16bit with a max value of 65535.

Following the ESPRESSIF's conversion formula of:

Vout = Dout * Vmax / Dmax

|Vout| = Digital output result, standing for the voltage.
|Dout| = ADC raw digital reading result.
|Vmax| = Maximum measurable input analog voltage, see ADC Attenuation.
|Dmax| = Maximum of the output ADC raw digital reading result, which is 8191 under Single Read mode, 4095 under Continuous Read mode.

So:

2.55v = 50720*(3.3v / 65535)

From adafruit's ALS-PT19 breakout datasheet, page 5, Figure 2: 2.55v is about 2100lux. Using a lux meter app while in my office, it measures 285lux.

Where have I gone wrong?
Thanks in advance!

Pretty much all the folks here program boards from the Arduino Ecosystem using C++. I'm guessing this is CircuitPython? Not sure how many people will chime in.

That's a good point.

I'm certain the sensor is being sampled, which is all the code really does. To your point, I'll also post on circuitpython's forum.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.