TOP Contributors

  1. MIKROE (2659 codes)
  2. Alcides Ramos (356 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (136990 times)
  2. FAT32 Library (70101 times)
  3. Network Ethernet Library (56025 times)
  4. USB Device Library (46345 times)
  5. Network WiFi Library (41962 times)
  6. FT800 Library (41275 times)
  7. GSM click (29051 times)
  8. mikroSDK (26489 times)
  9. PID Library (26447 times)
  10. microSD click (25412 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

LightHz click

Rating:

0

Author: MIKROE

Last Updated: 2024-04-03

Package Version: 2.1.0.2

mikroSDK Library: 2.0.0.0

Category: Optical

Downloaded: 8 times

Not followed.

License: MIT license  

LightHz Click is a compact add-on board that effectively measures ambient light intensity. This board features the TL2L30BR, a programmable light-to-frequency converter from ams. The sensor outputs either a pulse train or a square wave (50% duty cycle) with a frequency directly proportional to light intensity (irradiance). It has programmable sensitivity and full-scale output frequency and could be used as a rough color detector with a selectable frequency range.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "LightHz click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "LightHz click" changes.

Do you want to report abuse regarding "LightHz click".

  • Example 1.0.0.0
  • Comments (0)

mikroSDK Library Blog


LightHz click

LightHz Click is a compact add-on board that effectively measures ambient light intensity. This board features the TL2L30BR, a programmable light-to-frequency converter from ams. The sensor outputs either a pulse train or a square wave (50% duty cycle) with a frequency directly proportional to light intensity (irradiance). It has programmable sensitivity and full-scale output frequency and could be used as a rough color detector with a selectable frequency range.

lighthz_click.png

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Feb 2024.
  • Type : GPIO type

Software Support

We provide a library for the LightHz Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for LightHz Click driver.

Standard key functions :

  • lighthz_cfg_setup Config Object Initialization function.

    void lighthz_cfg_setup ( lighthz_cfg_t *cfg );
  • lighthz_init Initialization function.

    err_t lighthz_init ( lighthz_t *ctx, lighthz_cfg_t *cfg );

Example key functions :

  • lighthz_set_sensitivity This function sets the sensor sensitivity.

    void lighthz_set_sensitivity ( lighthz_t *ctx, uint8_t mode );
  • lighthz_set_frequency_scaling This function sets the sensor frequency scaling.

    void lighthz_set_frequency_scaling ( lighthz_t *ctx, uint8_t mode );
  • lighthz_get_freq_pin This function returns the freq pin logic state.

    uint8_t lighthz_get_freq_pin ( lighthz_t *ctx );

Example Description

This example demonstrates the use of LightHz click board by measuring and displaying the frequency of clock output signal. The higher the light intensity the higher the frequency.

The demo application is composed of two sections :

Application Init

Initializes the driver and sets the sensitivity mode and frequency scaling in case the onboard jumpers are set to MCU instead to ON-BRD.


void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lighthz_cfg_t lighthz_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    lighthz_cfg_setup( &lighthz_cfg );
    LIGHTHZ_MAP_MIKROBUS( lighthz_cfg, MIKROBUS_1 );
    if ( DIGITAL_OUT_UNSUPPORTED_PIN == lighthz_init( &lighthz, &lighthz_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

    lighthz_set_sensitivity ( &lighthz, LIGHTHZ_SENS_100X );
    lighthz_set_frequency_scaling ( &lighthz, LIGHTHZ_FSCALE_100 );

    log_info( &logger, " Application Task " );
}

Application Task

Measures the clock output frequency using the polling method and delays. The results are being sent to the USB UART.

void application_task ( void )
{
    uint32_t freq_cnt = 0;
    uint16_t sample_cnt = 0;

    // Wait for the clock rising edge signal
    while ( !hal_ll_gpio_read_pin_input( &lighthz.freq.pin ) );

    // A loop for measuring the clock frequency counts. It's not an ideal implementation.
    // Here we should use an external interrupt on the clock pin rising edge and a timer interrupt
    // for the best accuracy, however, those interrupt features have not yet been implemented in the SDK. 
    while ( ( sample_cnt < LIGHTHZ_SAMPLE_COUNTS ) && ( freq_cnt < LIGHTHZ_MAX_COUNTS_PER_S ) )
    {
        // A single iteration in the loops below should take as close to 10us as possible
        // So to improve the measurement accuracy adjust the delay below for your system
        while ( hal_ll_gpio_read_pin_input( &lighthz.freq.pin ) )
        {
            freq_cnt++;
            Delay_us ( LIGHTHZ_DELAY_US );
        }
        while ( !hal_ll_gpio_read_pin_input( &lighthz.freq.pin ) )
        {
            freq_cnt++;
            Delay_us ( LIGHTHZ_DELAY_US );
        }
        sample_cnt++;
    }
    freq_cnt /= sample_cnt;

    // The higher the light intensity the higher the frequency.
    log_printf( &logger, " Frequency: %.1f Hz\r\n\n", ( float ) LIGHTHZ_MAX_COUNTS_PER_S / freq_cnt );

    Delay_ms ( 1000 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.LightHz

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


ALSO FROM THIS AUTHOR

XBEE 2 click

0

Xbee 2 Click is a compact add-on board providing wireless end-point connectivity to other devices. This board features the XB3-24Z8UM, a Digi XBee® 3 transceiver module offering a fully interoperable ecosystem covering all vertical markets from Digi International. Building on industry-leading technology, the pre-certified Digi XBee® 3 module delivers the flexibility to switch between multiple frequencies and wireless protocols as needed (Zigbee, 802.15.4, DigiMesh® and BLE). It can be easily configured and controlled from a simple, central platform and comes with built-in Digi TrustFence® security, identity, and data privacy features which use more than 175 controls to protect against new and evolving cyber threats.

[Learn More]

FTDI click

0

FTDI Click is a compact add-on board that provides a high-speed USB to a serial interface converter. This board features the FT2232H, a 5th-generation high-speed USB 2.0 to a serial UART/I2C/SPI interface converter from FTDI. The entire USB protocol is handled on the chip (FTDI USB drivers required), making this board ideal for various USB applications. Besides a selectable interface and a standalone operation possibility, it also includes an EEPROM which contains the USB configuration descriptors for the FT2232H and one DA converter for additional reference in user-configurable applications.

[Learn More]

Magnetic rotary click

6

Magnetic rotary click is a very accurate position sensing Click board which utilizes the HMC1512, a magnetic field displacement sensor IC.

[Learn More]