MicroPython TCS3430 Library

tcs3430

MicroPython driver for the AMS TCS3430 Color and ALS sensor

  • Author(s): Jose D. Montoya

class micropython_tcs3430.tcs3430.TCS3430(i2c, address: int = 0x39)[source]

Driver for the TCS3430 Sensor connected over I2C. Ambient Light Sensing (ALS) and CIE 1931 Tristimulus Color Sensing (XYZ). These measurements can be used to calculate chromaticity,

Parameters:
i2c : I2C

The I2C bus the TCS3430 is connected to.

address : int

The I2C device address. Defaults to 0x39

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the TCS3430 class. First you will need to import the libraries to use the sensor

from machine import Pin, I2C
from micropython_tcs3430 import tcs3430

Once this is done you can define your machine.I2C object and define your sensor object

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
tcs = tcs3430.TCS3430(i2c)

Now you have access to the attributes

tcs = tcs.measurements
property als_gain : str

Sensor als_gain

Mode

Value

tcs3430.ALS_GAIN1

0b00

tcs3430.ALS_GAIN4

0b01

tcs3430.ALS_GAIN16

0b10

tcs3430.ALS_GAIN64

0b11

property als_wait_time : float

The wait timer is implemented with a down counter with 0x00 as the terminal count. Loading 0x00 will generate a 2.78ms wait time, loading 0x01 will generate a 5.56ms wait time, and so forth; By asserting wlong, in register 0x8D the wait time is given in multiples of 33.4ms (12x)

property integration_time : float

Integration time in 2.78ms intervals. 0x00 indicates 2.78ms, 0x01 indicates 5.56ms. The maximum ALS value depends on the integration time. For every 2.78ms, the maximum value increases by 1024. This means that to be able to reach ALS full scale, the integration time has to be at least 64*2.78ms.

property measurements

Return ALS values

property operation_mode : str

Sensor operation_mode

Mode

Value

tcs3430.DISABLED

0b00

tcs3430.ENABLED

0b11