Skip to content

PaddeK/espruino-tsl2591

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

espruino-tsl2591

Usage example

const TSL2591 = require('https://raw.githubusercontent.com/PaddeK/espruino-tsl2591/master/tsl2591.js');

// Setup I2C
I2C1.setup({scl: B8, sda: B9, bitrate: 400000});

// Get sensor object
let sensor = new TSL2591(I2C1);

// Log sensor value
sensor.getLuminosity(TSL2591.LIGHT.FULLSPECTRUM, console.log);

.

Value reference

  • ENABLE

    Name Value (hex) Description
    PON 0x01 Power on/off TSL2591 internal oscillator.
    AEN 0x02 Enable/disable TSL2591 ambient light sensor functions.
    AIEN 0x10 Enable/disable TSL2591 persist interrupt capabilities.
    SAI 0x40 Enable/disable TSL2591 sleep after interrupt capability.
    NPIEN 0x80 Enable/disable TSL2591 no persist interrupt capabilities.

.

  • GAIN

    Name Value (hex) Description
    LOW 0x00 Sets the gain of the internal amplifiers to 1 (both channels).
    MED 0x10 Sets the gain of the internal amplifiers to 24.5 (both channels).
    HIGH 0x20 Sets the gain of the internal amplifiers to 400 (both channels).
    MAX 0x30 Sets the gain of the internal amplifiers to 9200 (channel 0) and 9900 (channel 1).

.

  • INTEGRATIONTIME

    Name Value (hex) Description
    MS100 0x00 Sets the internal integration time to 100ms (both channels).
    MS200 0x01 Sets the internal integration time to 200ms (both channels).
    MS300 0x02 Sets the internal integration time to 300ms (both channels).
    MS400 0x03 Sets the internal integration time to 400ms (both channels).
    MS500 0x04 Sets the internal integration time to 500ms (both channels).
    MS600 0x05 Sets the internal integration time to 600ms (both channels).

.

  • LIGHT

    Name Value (hex) Description
    FULLSPECTRUM 0x00 Calculate luminosity of the full spectrum (visible and infrared).
    VISIBLE 0x01 Calculate luminosity for visible light only.
    INFRARED 0x02 Calculate luminosity for infrared light only.

.

Function reference

  • constructor ( I2C )

    Parameters Type Description
    I2C object Must be instanceof I2C with a bitrate of 1Hz to 400KHz.
    Return type Description
    object A instance of the TSL2591 class.

.

  • clearAllInterrupts ()

    Return type Description
    boolean Clears all pending interrupts (persist and no persist).

.

  • clearInterrupt ()

    Return type Description
    boolean Clear only pending no persist interrupts.

.

  • clearPersistInterrupt ()

    Return type Description
    boolean Clear only pending persist interrupts.

.

  • disable ( disable )

    Parameters Type Description
    disable number Disable capabilities of the TSL2591. See ENABLE value reference for valid values (pass sum to disable multiple capabilities at once).
    Return type Description
    void Technically returns always true, but do not use it or rely on it.

.

  • enable ( enable )

    Parameters Type Description
    enable number Enable capabilities of the TSL2591. See ENABLE values reference for valid values (pass sum to disable multiple capabilities at once). Enforces PON and AEN to be enabled!
    Return type Description
    void Technically returns always true, but do not use it or rely on it.

.

  • getGain ()

    Return type Description
    number Returns the current active gain value. See GAIN value reference for valid values.

.

  • getIntegration ()

    Return type Description
    number Returns the current active integration value. See INTEGRATIONTIME value reference for valid values.

.

  • getLuminosity ( LIGHT, callback )

    Parameters Type Description
    LIGHT number Light spectrum to get luminosity of. See LIGHT values reference for valid values.
    callback function A callback function which gets called with the resulting luminosity value as parameter. If the TSL2591 is oversaturated the luminosity is fixed at -1.
    Return type Description
    void Returns undefined.

    Note: This function takes care of enabling the TSL2591 beforehand and disabling it afterwards (Respects enabled interrupt capabilities).

.

  • hasIntOccured ()

    Return type Description
    boolean Returns true if a no persist interrupt has occured.Returns false otherwise.

.

  • hasPersistIntOccured ()

    Return type Description
    boolean Returns true if a persist interrupt has occured. Returns false otherwise.

.

  • isAlsEnabled ()

    Return type Description
    boolean Returns true if AEN is currently active. Returns false otherwise.

.

  • isAlsValid ()

    Return type Description
    boolean Returns true if at least one integration cycle is completed since AEN was enabled and valid values can be red from the TSL2591. Returns false otherwise. Note: getLuminosity takes care of this internally.

.

  • isIntEnabled ()

    Return type Description
    boolean Returns true if no persist interrupt capabilities are enabled. Returns false otherwise.

.

  • isPersistIntEnabled ()

    Return type Description
    boolean Returns true if persist interrupt capabilities are enabled. Returns false otherwise.

.

  • isSaiEnabled ()

    Return type Description
    boolean Returns true if SAI capability is enabled. Returns false otherwise.

.

  • registerInterrupt ( low, high, persist )

    Parameters Type Description
    low number Lower threshold value (Max. 65535). If luminosity crosses below this value an interrupt is triggered on the interrupt pin.
    high number Upper threshold value (Max. 65535). If luminosity crosses above this value an interrupt is triggered on the interrupt pin.
    persist number Optional value which specifies how many consecutive out-of-range luminosity values have to be measured before a interrupt is triggered. If not set a interrupt is triggered immediately after a out-of-range measurement. See Note for valid values.
    Return type Description
    boolean Returns true if set interrupt was a persist interrupt. Returns false otherwise.

    Note:

    Value Description
    0 Every measurement generates an interrupt.
    1 Any out-of-range measurement generates an interrupt.
    2 2 consecutive out-of-range measurements generate an interrupt.
    3 3 consecutive out-of-range measurements generate an interrupt.
    4 5 consecutive out-of-range measurements generate an interrupt.
    5 10 consecutive out-of-range measurements generate an interrupt.
    6 15 consecutive out-of-range measurements generate an interrupt.
    7 20 consecutive out-of-range measurements generate an interrupt.
    8 25 consecutive out-of-range measurements generate an interrupt.
    9 30 consecutive out-of-range measurements generate an interrupt.
    10 35 consecutive out-of-range measurements generate an interrupt.
    11 40 consecutive out-of-range measurements generate an interrupt.
    12 45 consecutive out-of-range measurements generate an interrupt.
    13 50 consecutive out-of-range measurements generate an interrupt.
    14 55 consecutive out-of-range measurements generate an interrupt.
    15 60 consecutive out-of-range measurements generate an interrupt.

.

  • setGain ( gain )

    Parameters Type Description
    gain number Sets the gain value effective after the current integration cycle. See GAIN value reference for valid values.
    Return type Description
    void Technically returns always true, but do not use it or rely on it.

    Note: This function takes care of disabling AEN beforehand and enabling it afterwards if necessary. This is done to prevent irregular spikes in measurements while changing gain values.
    .

  • setIntegration ( int )

    Parameters Type Description
    int number Sets the integration time value effective after the current integration cycle. See INTEGRATIONTIME value reference for valid values.
    Return type Description
    void Technically returns always true, but do not use it or rely on it.

.

  • setToSleep ()

    Return type Description
    void Technically returns always true, but do not use it or rely on it.

    Note: Short hand for disable(ENABLE.NPIEN | ENABLE.SAI | ENABLE.AIEN | ENABLE.AEN | ENABLE.PON)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published