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]
Rating:
Author: MIKROE
Last Updated: 2020-07-20
Package Version: 1.0.0.0
mikroSDK Library: 1.0.0.0
Category: Optical
Downloaded: 2392 times
Not followed.
License: MIT license
Spectrometer Click features an 11-channel spectrometer for spectral identification and color matching applications. The spectral response is defined in the wavelengths from approximately 350nm to 1000nm. Control and Spectral data access are implemented through a serial I²C interface with very a low power consumption.
Do you want to subscribe in order to receive notifications regarding "Spectrometer click" changes.
Do you want to unsubscribe in order to stop receiving notifications regarding "Spectrometer click" changes.
Do you want to report abuse regarding "Spectrometer click".
Library Description
The library covers necessary functions that enables the usage of the Spectrometer click board. User can read or write data in and from registers, check interrupt state, set diferent configuration and read data from all channels available.
Key functions:
void spectrometer_raw_rd_val_mode_1 ( uint8_t *adc_data );
- Function is used to read out channels with SMUX configration 1; F1-F4, Clear.void spectrometer_raw_rd_val_mode_2 ( uint8_t *adc_data );
- Function is used to read out channels with SMUX configration 2; F5-F8, Clear.uint8_t spectrometer_flicker_detection ( );
- Function is used to detect flicker for 100 and 120 Hz.Examples description
The application is composed of three sections :
void application_task ( )
{
spectrometer_def_cfg( );
spectrometer_raw_rd_val_mode_1( adc_buf );
ch_0 = adc_buf[ 1 ];
ch_0 <<= 8;
ch_0 |= adc_buf[ 0 ];
WordToStr( ch_0, log_txt );
mikrobus_logWrite( " ADC0/F1 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_1 = adc_buf[ 3 ];
ch_1 <<= 8;
ch_1 |= adc_buf[ 2 ];
WordToStr( ch_1, log_txt );
mikrobus_logWrite( " ADC1/F2 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_2 = adc_buf[ 5 ];
ch_2 <<= 8;
ch_2 |= adc_buf[ 4 ];
WordToStr( ch_2, log_txt );
mikrobus_logWrite( " ADC2/F3 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_3 = adc_buf[ 7 ];
ch_3 <<= 8;
ch_3 |= adc_buf[ 6 ];
WordToStr( ch_3, log_txt );
mikrobus_logWrite( " ADC3/F4 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_4 = adc_buf[ 9 ];
ch_4 <<= 8;
ch_4 |= adc_buf[ 8 ];
WordToStr( ch_4, log_txt );
mikrobus_logWrite( " ADC4/Clear : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
spectrometer_raw_rd_val_mode_2( adc_buf );
ch_0 = adc_buf[ 1 ];
ch_0 <<= 8;
ch_0 |= adc_buf[ 0 ];
WordToStr( ch_0, log_txt );
mikrobus_logWrite( " ADC0/F5 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_1 = adc_buf[ 3 ];
ch_1 <<= 8;
ch_1 |= adc_buf[ 2 ];
WordToStr( ch_1, log_txt );
mikrobus_logWrite( " ADC1/F6 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_2 = adc_buf[ 5 ];
ch_2 <<= 8;
ch_2 |= adc_buf[ 4 ];
WordToStr( ch_2, log_txt );
mikrobus_logWrite( " ADC2/F7 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_3 = adc_buf[ 7 ];
ch_3 <<= 8;
ch_3 |= adc_buf[ 6 ];
WordToStr( ch_3, log_txt );
mikrobus_logWrite( " ADC3/F8 : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
ch_4 = adc_buf[ 9 ];
ch_4 <<= 8;
ch_4 |= adc_buf[ 8 ];
WordToStr( ch_4, log_txt );
mikrobus_logWrite( " ADC4/Clear : ", _LOG_TEXT );
Ltrim( log_txt );
mikrobus_logWrite( log_txt, _LOG_LINE );
f_val = spectrometer_flicker_detection( );
if ( f_val == SPECTROMETER_UNKNOWN_FREQ )
{
mikrobus_logWrite( "Unknown frequency", _LOG_LINE );
}
else if ( f_val == SPECTROMETER_DETECTED_100_HZ )
{
mikrobus_logWrite( "100 Hz detected", _LOG_LINE );
}
else if ( f_val == SPECTROMETER_DETECTED_120_HZ )
{
mikrobus_logWrite( "120 Hz detected", _LOG_LINE );
}
else
{
mikrobus_logWrite( "Error in reading", _LOG_LINE );
}
mikrobus_logWrite( "-----------------", _LOG_LINE );
Delay_ms( 1000 );
}
Other mikroE Libraries used in the example:
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. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.