Skip to content

gitpeut/SDS021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDS021

Arduino library for dust Sensor SDS011 and SDS021 (Nova Fitness Co.,Ltd)
This library uses SoftSerial to connect to the SDS021.

This library is based on the SDS011 library by ricki-z https://github.com/ricki-z/SDS011

It is an attempt to implement the full serial protocol specified by Nova Fitness.

** A much nicer library implementing this functionality is found here: https://github.com/lewapek/sds-dust-sensors-arduino-library **

Tested ok using an ESP8266 and both an SDS021 and an SDS011.

The class offers the following functions:

class SDS021 {
	public:
		SDS021(void);
		void begin(	uint8_t pin_rx, uint8_t pin_tx, uint8_t devid_one = 0xFF, uint8_t devid_two = 0xFF );
		bool workMode( 			uint8_t *result, 	uint8_t mode = SDS021_REPORTMODE,	uint8_t set = SDS021_ASK );
		bool queryData( float *ppm10, 		float *ppm25 );
		bool setDeviceId( 		uint8_t result[2], 	uint8_t new_one, uint8_t new_two );
		bool sleepWork( 		uint8_t *result, 	uint8_t awake = SDS021_WORKING,uint8_t set = SDS021_ASK);
		bool workPeriod(		uint8_t *result, 	uint8_t minutes = 0,uint8_t set = SDS021_ASK);
		bool firmwareVersion( 	uint8_t result[3]);
		void setDebug( 			bool onoff );
	private:
		uint8_t _pin_rx, _pin_tx;
		uint8_t _devid_one, _devid_two;
		bool _debug;
		bool txrCommand( uint8_t q[19], uint8_t b[10]);
		Stream *sds_data;		
};

SDS021::workMode() datasheet (1)

result will contain either SDS021_QUERYMODE or SDS021_REPORTMODE, depending on how it was set by this function ( by setting argument set to SDS021_SET), or how it was set before if argument set was set to SDS021_ASK.

SDS021::queryData() datasheet (2)

returns ppm10 and ppm2.5 values

SDS021::setDeviceId() datasheet (3)

Device id is two bytes, the factory sets each device to a unique id. New id will be returned in result. By default any device is addressed by address FF FF. This is the default for this library as not many people will connect more than one device to the same serial lines. If this default (FF FF) is used, class instance device id (_devid_one and _devid_two ) will not be updated with this new device address, and FF FF will continued to be used to address the device.

SDS021::sleepWork() datasheet (4)

result will contain either SDS021_WORKING or SDS021_SLEEPING, depending on how it was set by this function ( by setting argument set to SDS021_SET), or how it was set before if argument set was set to SDS021_ASK.

When the device is working it draws around 60 mA. When sleeping, laser and fan are turned off. Current drops to 1.8 mA. See also the example sketch.

SDS021::workPeriod() datasheet (5)

result will contain 0 ( for continuous mode) or the Interval time in minutes (for interval mode). According to the datasheet device will sleep during the interval and become active 30 seconds before the interval is reached.

See also the example. When device wakes up, one read is enough. Subsequent reads will return the same value until the next workperiod. Current draw in between workperiods is around 16 mA, which is much higher than after sending the device to sleep by calling sleepWork.

SDS021:firmwareVersion() datasheet (6)

result[3] contains firmware date as YY, MM, DD if succesful, else FF FF FF

SDS021::setDebug( bool onoff )

SDS021::txrCommand()

Executes and checks communication with the Nova SDS011 and SDS021 (maybe more) as documented in Laser Dust Sensor Control Protocol V1.3 which can (could?) be found here: Laser_Dust_Sensor_Control_Protocol_V1.3.pdf PC software ( which must be run in Windows 8 compatible mode on Windows 10 or else it will not find COM ports) was found here: on baidu

About

Arduino library that implements serial communication with the Nova SDS011 and SDS021 (maybe more) as documented in Laser Dust Sensor Control Protocol V1.3

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages