SDS011 Laser Dust Sensor

Driver SDS011 Laser Dust Sensor. More...

Detailed Description

Driver SDS011 Laser Dust Sensor.

Files

file  sds011.h
 Interface for controlling SDS011 Laser Dust Sensor.
 
file  sds011_internal.h
 Internal constants etc. for the SDS011 laser dust sensor.
 
file  sds011_params.h
 SDS011 sensor specific configuration.
 

Data Structures

struct  sds011_params_t
 Configuration parameters for SDS011 Laser Dust Sensor. More...
 
struct  sds011_data_t
 Data type for storing SDS011 sensor readings. More...
 
struct  sds011_t
 Device descriptor definition for SDS011 Laser Dust Sensor. More...
 

Macros

#define SDS011_DEVID_WILDCARD   (0xFFFF)
 SDS011 wildcard address to address all devices.
 

Typedefs

typedef enum sds011_reporting_mode sds011_reporting_mode_t
 Report mode of the SDS011 sensor.
 
typedef enum sds011_working_mode sds011_working_mode_t
 Work/sleep mode of the SDS011 sensor.
 
typedef void(* sds011_callback_t) (sds011_data_t *data, void *ctx)
 callback for measurements actively reported by the SDS011 sensor
 

Enumerations

enum  { SDS011_OK, SDS011_INVALID_RESPONSE, SDS011_INVALID_CHKSUM, SDS011_ERROR }
 Named return values. More...
 
enum  sds011_reporting_mode { SDS011_RMODE_ACTIVE = 0, SDS011_RMODE_QUERY = 1 }
 Report mode of the SDS011 sensor. More...
 
enum  sds011_working_mode { SDS011_WMODE_SLEEP = 0, SDS011_WMODE_WORK = 1 }
 Work/sleep mode of the SDS011 sensor. More...
 

Functions

int sds011_init (sds011_t *dev, const sds011_params_t *params)
 Initialize SDS011 Laser Dust Sensor. More...
 
void sds011_power_on (const sds011_t *dev)
 Enable power supply of SDS011 laser dust sensor. More...
 
void sds011_power_off (const sds011_t *dev)
 Disable power supply of SDS011 laser dust sensor. More...
 
int sds011_read (sds011_t *dev, sds011_data_t *data)
 Read measurement values from SDS011 laser dust sensor. More...
 
int sds011_register_callback (sds011_t *dev, sds011_callback_t cb, void *ctx)
 Register measurement callback. More...
 
int sds011_get_reporting_mode (sds011_t *dev, sds011_reporting_mode_t *mode)
 Get the current reporting mode of the sensor. More...
 
int sds011_set_reporting_mode (sds011_t *dev, sds011_reporting_mode_t mode)
 Set the reporting mode of the sensor. More...
 
int sds011_get_working_mode (sds011_t *dev, sds011_working_mode_t *mode)
 Get current working mode of the sensor. More...
 
int sds011_set_working_mode (sds011_t *dev, sds011_working_mode_t mode)
 Set working mode of the sensor. More...
 
int sds011_get_working_period (sds011_t *dev, uint8_t *minutes)
 Get current working period of the sensor. More...
 
int sds011_set_working_period (sds011_t *dev, uint8_t minutes)
 Set working period of the sensor. More...
 
int sds011_get_fw_version (sds011_t *dev, uint8_t *year, uint8_t *mon, uint8_t *day)
 Get firmware version of the sensor. More...
 
int sds011_set_dev_id (sds011_t *dev, uint16_t sens_dev_id)
 Set device ID of the sensor. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Named return values.

Enumerator
SDS011_OK 

all good

SDS011_INVALID_RESPONSE 

invalid response

SDS011_INVALID_CHKSUM 

invalid checksum

SDS011_ERROR 

internal error

Definition at line 43 of file sds011.h.

◆ sds011_reporting_mode

Report mode of the SDS011 sensor.

Enumerator
SDS011_RMODE_ACTIVE 

continuously reporting values

SDS011_RMODE_QUERY 

sensor needs to be queried

Definition at line 53 of file sds011.h.

◆ sds011_working_mode

Work/sleep mode of the SDS011 sensor.

Enumerator
SDS011_WMODE_SLEEP 

laser & fan are disabled

SDS011_WMODE_WORK 

laser & fan are enabled

Definition at line 61 of file sds011.h.

Function Documentation

◆ sds011_get_fw_version()

int sds011_get_fw_version ( sds011_t dev,
uint8_t *  year,
uint8_t *  mon,
uint8_t *  day 
)

Get firmware version of the sensor.

Parameters
[in]devdevice descriptor
[out]yearyear of the firmware version
[out]monmonth of the firmware version
[out]dayday of the firmware version
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL
year != NULL
mon != NULL
day != NULL

◆ sds011_get_reporting_mode()

int sds011_get_reporting_mode ( sds011_t dev,
sds011_reporting_mode_t mode 
)

Get the current reporting mode of the sensor.

Parameters
[in]devdevice descriptor
[out]modeSDS011_RMODE_ACTIVE: continuously report new values SDS011_RMODE_QUERY: new values need to be requested
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_get_working_mode()

int sds011_get_working_mode ( sds011_t dev,
sds011_working_mode_t mode 
)

Get current working mode of the sensor.

Parameters
[in]devdevice descriptor
[out]modeSDS011_WMODE_SLEEP: sensor is in sleep mode (~3 mA) SDS011_WMODE_WORK: sensor is in working mode (~65 mA)
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_get_working_period()

int sds011_get_working_period ( sds011_t dev,
uint8_t *  minutes 
)

Get current working period of the sensor.

Parameters
[in]devdevice descriptor
[out]minutesworking period of the sensor in minutes
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_init()

int sds011_init ( sds011_t dev,
const sds011_params_t params 
)

Initialize SDS011 Laser Dust Sensor.

Parameters
[out]devdevice descriptor
[in]paramsdevice configuration
Precondition
dev != NULL
params != NULL
Returns
SDS011_OK on success
SDS011_ERROR on error

◆ sds011_power_off()

void sds011_power_off ( const sds011_t dev)

Disable power supply of SDS011 laser dust sensor.

Parameters
[in]devdevice descriptor
Precondition
dev != NULL

◆ sds011_power_on()

void sds011_power_on ( const sds011_t dev)

Enable power supply of SDS011 laser dust sensor.

Parameters
[in]devdevice descriptor
Precondition
dev != NULL

◆ sds011_read()

int sds011_read ( sds011_t dev,
sds011_data_t data 
)

Read measurement values from SDS011 laser dust sensor.

Parameters
[in]devdevice descriptor
[out]datapointer for storing the values
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL
data != NULL

◆ sds011_register_callback()

int sds011_register_callback ( sds011_t dev,
sds011_callback_t  cb,
void *  ctx 
)

Register measurement callback.

     The registered callback is executed when new measurements were
     received by the sensor. This function should be used together with
     active reporting mode of the sensor that automatically sends new
     measurements periodically (factory default setting of the sensor).
Parameters
[in]devdevice descriptor
[in]cbfunction to be called for new values (NULL for disable)
[in]ctxcontext pointer that will be handed to the callback
Returns
SDS011_OK on success
SDS011_ERROR when error occurred
Precondition
dev != NULL

◆ sds011_set_dev_id()

int sds011_set_dev_id ( sds011_t dev,
uint16_t  sens_dev_id 
)

Set device ID of the sensor.

Parameters
[in]devdevice descriptor
[in]sens_dev_idID as one number (ID byte 1 MSB, ID byte 2 LSB)
Note
This setting is persistent even after a full power-cycle! Factory default is an individual ID which is printed next to the serial number barcode. For the number xxxx-abab the ID is 0xabab.
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_set_reporting_mode()

int sds011_set_reporting_mode ( sds011_t dev,
sds011_reporting_mode_t  mode 
)

Set the reporting mode of the sensor.

Parameters
[in]devdevice descriptor
[in]modeSDS011_RMODE_ACTIVE: continuously report new values SDS011_RMODE_QUERY: new values need to be requested
Note
This setting is persistent even after a full power-cycle! Factory default is SDS011_RMODE_ACTIVE
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_set_working_mode()

int sds011_set_working_mode ( sds011_t dev,
sds011_working_mode_t  mode 
)

Set working mode of the sensor.

Parameters
[in]devdevice descriptor
[in]modeSDS011_WMODE_SLEEP: put to sleep mode (~3 mA) SDS011_WMODE_WORK: put to working mode (~65 mA)
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL

◆ sds011_set_working_period()

int sds011_set_working_period ( sds011_t dev,
uint8_t  minutes 
)

Set working period of the sensor.

Parameters
[in]devdevice descriptor
[in]minutes0 - 30 new working period of the sensor in minutes 0 for continuous reporting mode 1 - 30 for a period of minutes
Note
For values greater than 0, the active duration (fan, laser enabled) is always fixed to 30 seconds, while the sleep duration is adjusted to give an overall period of minutes.
Returns
SDS011_OK on success
SDS011_INVALID_RESPONSE when response doesn't match the request
SDS011_INVALID_CHKSUM when response checksum is invalid
SDS011_ERROR when other error occurred
Precondition
dev != NULL