APC1 Sensor Demo
APC1 Air Quality Sensor Bundle - Experience advanced air quality monitoring with our bundle solution, merging the ScioSense APC1 Air Quality sensor and the MIKROE Terminal Click boardâ„¢. This dynamic combination creates a compact and precise system that measures PM levels, VOCs, temperature, humidity, and more. Explore this bundle to build an effective monitoring solution perfect for ensuring healthy indoor spaces or contributing to broader air quality research efforts.
click Product page
Demo library
- Author : Stefan Filipovic
- Date : Sep 2023.
- Type : I2C/UART type
Software Support
We provide a library for the APC1 Sensor Demo 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 APC1 Sensor Demo driver.
Standard key functions :
apc1sensor_cfg_setup
Config Object Initialization function.
void apc1sensor_cfg_setup(apc1sensor_cfg_t *cfg)
APC1 Sensor configuration object setup function.
APC1 Sensor Demo configuration object.
Definition apc1sensor.h:204
apc1sensor_init
Initialization function.
err_t apc1sensor_init(apc1sensor_t *ctx, apc1sensor_cfg_t *cfg)
APC1 Sensor initialization function.
APC1 Sensor Demo context object.
Definition apc1sensor.h:181
apc1sensor_default_cfg
Demo Default Configuration function.
err_t apc1sensor_default_cfg(apc1sensor_t *ctx)
APC1 Sensor default configuration function.
Example key functions :
apc1sensor_start_measurement
This function starts measurement by setting the device to measurement mode.
err_t apc1sensor_start_measurement(apc1sensor_t *ctx)
APC1 Sensor start measurement function.
apc1sensor_read_info
This function reads the device name, serial number, and firmware version.
err_t apc1sensor_read_info(apc1sensor_t *ctx, apc1sensor_info_t *info)
APC1 Sensor read info function.
APC1 Sensor Demo module type, ID and firmware version object.
Definition apc1sensor.h:265
apc1sensor_read_measurement
This function reads the measurement 64-bytes output structure data.
err_t apc1sensor_read_measurement(apc1sensor_t *ctx, apc1sensor_measurement_t *measurement)
APC1 Sensor read measurement function.
APC1 Sensor Demo measurement data object.
Definition apc1sensor.h:231
Example Description
This example demonstrates the use of APC1 Air Quality Sensor Bundle by reading measurement results (PM1.0, PM2.5, PM10, TVOC, eCO2, AQI, temperature, relative humidity, etc.).
The demo application is composed of two sections :
Application Init
Initializes the driver, performs the sensor default configuration, and reads the sensor name, serial number, and firmware version.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
{
log_printf ( &logger,
" Module name: %s\r\n", info.
module_name );
log_printf ( &logger, " Serial number: " );
for ( uint8_t cnt = 0; cnt < 8; cnt++ )
{
log_printf ( &logger,
"%.2X", ( uint16_t ) info.
serial_num[ cnt ] );
}
log_printf ( &logger, "\r\n FW version: %.2X%.2X\r\n",
}
Delay_ms ( 1000 );
log_info( &logger, " Application Task " );
}
@ APC1SENSOR_OK
Definition apc1sensor.h:278
#define APC1SENSOR_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition apc1sensor.h:154
void application_init(void)
Definition main.c:37
uint8_t fw_version[2]
Definition apc1sensor.h:268
uint8_t serial_num[8]
Definition apc1sensor.h:267
uint8_t module_name[7]
Definition apc1sensor.h:266
Application Task
Reads the measurement results and displays all data on the USB UART once per second.
{
{
log_printf ( &logger, "--- MEASUREMENT RESULTS ---\r\n" );
log_printf ( &logger,
" PM1.0: %u ug/m3\r\n", meas.
pm1_0 );
log_printf ( &logger,
" PM2.5: %u ug/m3\r\n", meas.
pm2_5 );
log_printf ( &logger,
" PM10: %u ug/m3\r\n", meas.
pm10 );
log_printf ( &logger,
" PM1.0 in air: %u ug/m3\r\n", meas.
pm1_0_air );
log_printf ( &logger,
" PM2.5 in air: %u ug/m3\r\n", meas.
pm2_5_air );
log_printf ( &logger,
" PM10 in air: %u ug/m3\r\n", meas.
pm10_air );
log_printf ( &logger,
" # particles >0.3um: %u\r\n", meas.
part_over_0_3um );
log_printf ( &logger,
" # particles >0.5um: %u\r\n", meas.
part_over_0_5um );
log_printf ( &logger,
" # particles >1.0um: %u\r\n", meas.
part_over_1_0um );
log_printf ( &logger,
" # particles >2.5um: %u\r\n", meas.
part_over_2_5um );
log_printf ( &logger,
" # particles >5.0um: %u\r\n", meas.
part_over_5_0um );
log_printf ( &logger,
" # particles >10um: %u\r\n", meas.
part_over_10um );
log_printf ( &logger,
" TVOC: %u ppb\r\n", meas.
tvoc );
log_printf ( &logger,
" eCO2: %u ppm\r\n", meas.
eco2 );
log_printf ( &logger,
" T-comp: %.1f degC\r\n", meas.
t_comp );
log_printf ( &logger,
" RH-comp: %.1f %%\r\n", meas.
rh_comp );
log_printf ( &logger,
" T-raw: %.1f degC\r\n", meas.
t_raw );
log_printf ( &logger,
" RH-raw: %.1f %%\r\n", meas.
rh_raw );
log_printf ( &logger,
" RS0: %lu Ohm\r\n", meas.
rs0 );
log_printf ( &logger,
" RS2: %lu Ohm\r\n", meas.
rs2 );
log_printf ( &logger,
" RS3: %lu Ohm\r\n", meas.
rs3 );
log_printf ( &logger,
" AQI: %u\r\n", ( uint16_t ) meas.
aqi );
log_printf ( &logger,
" Version: 0x%.2X\r\n", ( uint16_t ) meas.
version );
log_printf ( &logger,
" Error code: 0x%.2X\r\n", ( uint16_t ) meas.
error_code );
log_printf ( &logger, "---------------------------\r\n" );
}
Delay_ms ( 1000 );
}
void application_task(void)
Definition main.c:86
uint16_t part_over_2_5um
Definition apc1sensor.h:241
uint16_t part_over_1_0um
Definition apc1sensor.h:240
uint16_t part_over_0_5um
Definition apc1sensor.h:239
uint16_t tvoc
Definition apc1sensor.h:244
uint8_t error_code
Definition apc1sensor.h:256
uint8_t aqi
Definition apc1sensor.h:254
uint16_t pm10
Definition apc1sensor.h:234
uint16_t eco2
Definition apc1sensor.h:245
float t_raw
Definition apc1sensor.h:248
float rh_raw
Definition apc1sensor.h:249
uint16_t part_over_0_3um
Definition apc1sensor.h:238
uint32_t rs0
Definition apc1sensor.h:250
float rh_comp
Definition apc1sensor.h:247
float t_comp
Definition apc1sensor.h:246
uint16_t pm1_0_air
Definition apc1sensor.h:235
uint8_t version
Definition apc1sensor.h:255
uint16_t pm2_5_air
Definition apc1sensor.h:236
uint16_t part_over_10um
Definition apc1sensor.h:243
uint16_t pm2_5
Definition apc1sensor.h:233
uint32_t rs3
Definition apc1sensor.h:253
uint16_t pm1_0
Definition apc1sensor.h:232
uint32_t rs2
Definition apc1sensor.h:252
uint16_t pm10_air
Definition apc1sensor.h:237
uint16_t part_over_5_0um
Definition apc1sensor.h:242
Note
By default, the I2C communication interface is selected in the library,
which is compatible with APC1001J sensor. If you are using an UART version of the sensor (APC1001U) refer to the apc1sensor_drv_interface_sel function description in order to properly change the interface selection in the library.
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.APC1Sensor
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.