Ambient 18 Click
Ambient 18 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Stefan Filipovic
- Date : Dec 2021.
- Type : ADC/I2C type
Software Support
Example Description
This example demonstrates the use of Ambient 18 Click board by measuring and displaying the illuminance value in Lux.
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.Ambient18
Example Key Functions
- ambient18_cfg_setup Config Object Initialization function.
void ambient18_cfg_setup(ambient18_cfg_t *cfg)
Ambient 18 configuration object setup function.
Ambient 18 Click configuration object.
Definition ambient18.h:166
- ambient18_init Initialization function.
err_t ambient18_init(ambient18_t *ctx, ambient18_cfg_t *cfg)
Ambient 18 initialization function.
Ambient 18 Click context object.
Definition ambient18.h:146
- ambient18_set_gain_mode This function sets the gain mode.
void ambient18_set_gain_mode(ambient18_t *ctx, uint8_t mode)
Ambient 18 set gain mode function.
- ambient18_read_voltage This function reads raw ADC value and converts it to proportional voltage level.
err_t ambient18_read_voltage(ambient18_t *ctx, float *voltage)
Ambient 18 read voltage level function.
- ambient18_voltage_to_lux This function calculates illuminance (lux) based on the voltage input.
int32_t ambient18_voltage_to_lux(ambient18_t *ctx, float voltage)
Ambient 18 voltage to illuminance function.
Application Init
Initializes the driver and sets the gain mode to M-Gain which can detect the illuminance of up to 1000 lux.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( ( ADC_ERROR == init_flag ) || ( I2C_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_printf( &logger, " M-Gain mode selected.\r\n Up to 1000 lux can be measured.\r\n" );
log_info( &logger, " Application Task " );
}
#define AMBIENT18_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition ambient18.h:120
#define AMBIENT18_MODE_M_GAIN
Definition ambient18.h:76
void application_init(void)
Definition main.c:31
Application Task
Reads the ADC voltage and then calculates the illuminance from it. The calculated value of illuminance in lux is being displayed on the USB UART approximately once per second.
{
float voltage = 0;
{
Delay_ms ( 1000 );
}
}
@ AMBIENT18_OK
Definition ambient18.h:189
void application_task(void)
Definition main.c:65
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.