Version 0.0.1, +05:30 09:47:56 PM 23-12-2024, Monday
Since the library supports accepting both Hardware and Software serial ports, the library will be automatically configured to use either of them based on the platform you are compiling the code for. For example, targets with only one hardware serial ports can only use software serial port. The macro SOFTWARE_SERIAL_REQUIRED is automatically defined for such targets and the SoftwareSerial.h library is loaded. For all other targets with more than one hardware serial ports, the SOFTWARE_SERIAL_REQUIRED macro is not defined and therefore can use any of the hardware serial ports.
The number of hardware serial ports is defined using the _HAVE_HWSERIAL1 macro. You can override or expand this behaviour in the CSE_ZH06.h file. Following are the defaults for the most common targets.
- Software Serial
ARDUINO_AVR_UNOARDUINO_AVR_NANOESP8266
- Hardware Serial
ARDUINO_AVR_MEGA2560ARDUINO_ARCH_ESP32
CSE_ZH06- The main class for wrapping the data and functions of the library.
uint8_t rxData [32]: Buffer to receive the data from the sensor. Initializes to0.uint8_t txData [9]: Buffer to hold the data to send to the sensor. Initializes to0.uint16_t pm1: PM 1.0 concentration in micrograms per cubic meter (ug/m3). Initializes to0.uint16_t pm25: PM 2.5 concentration in micrograms per cubic meter (ug/m3). Initializes to0.uint16_t pm10: PM 10.0 concentration in micrograms per cubic meter (ug/m3). Initializes to0.
-
SoftwareSerial* _serial: A pointer to a software serial port. Initializes tonullptr. This will only be used if theSOFTWARE_SERIAL_REQUIREDmacro is defined. -
HardwareSerial* _serial: A pointer to a hardware serial port. Initializes tonullptr. This will only be used if theSOFTWARE_SERIAL_REQUIREDmacro is not defined.
This constructor creates a new CSE_ZH06 object. There are two overloads based on the parameter type. User can send a HardwareSerial or a SoftwareSerial port object. The type of constructor is determined by the macro SOFTWARE_SERIAL_REQUIRED. The supplied serial port is saved to the _serial variable.
Throughout this documentation, an example CSE_ZH06 object sensor will be used for examples.
CSE_ZH06 (SoftwareSerial& swSerial);swSerial: A software serial port of typeSoftwareSerial. Only allowed if theSOFTWARE_SERIAL_REQUIREDmacro is defined.
CSE_ZH06 object.
CSE_ZH06 (HardwareSerial& hwSerial);hwSerial: A hardware serial port of typeHardwareSerial. Only allowed if theSOFTWARE_SERIAL_REQUIREDmacro is not defined.
CSE_ZH06object.
Destroys the CSE_ZH06 object.
sensor.~CSE_ZH06();None
None
Does nothing for now. The user must initialize the serial port they want to use before interacting with the sensor.
sensor.begin();None
None
Reads the PM data from the sensor. It first sends the request for the PM data and reads back the response. The response contains the PM data for PM1.0, PM2.5 and PM10. These values are then stored to the pm1, pm25 and pm10 variables and the user can directly read them. Additionally, the user can also pass a pointer to an array to store the data. The array should be of type uint16_t and should have a length of 3. Sending the array is optional.
sensor.getPmData (uint16_t* data = NULL);uint16_t* data: A pointer to an array ofuint16_ttype. Optional. Defaults toNULL.
bool:trueif successful,falseotherwise.
Puts the sensor into sleep mode as specified in the datasheet. This function can actually put the sensor to sleep mode as well as wake it up from the sleep mode. Use the toSleep parameter to specify whether to put the sensor to sleep or wake it up. Sending the parameter is optional. By default, the value is true (sleep mode).
sensor.sleep (bool toSleep = true);bool toSleep:trueto put the sensor to sleep,falseto wake it up. Optional. Defaults totrue.
bool:trueif successful,falseotherwise.
Wakes up the sensor from the sleep mode.
sensor.wake();None
bool:trueif successful,falseotherwise.
Private function. Sends some data to the sensor. There are two overloads.
The first one expects a one way transfer and does not read back what the sensor sent.
sendData (uint8_t* txData, uint8_t txLength)uint8_t* txData: A pointer to an array ofuint8_ttype. This is the data you want to send.uint8_t txLength: The length of the data you want to send. Should be less than or equal totxDatalength.
None
This sends data to the sensor and the response is saved to the rxData array. Receiving does not work as expected for now. So don't use this.
sendData (uint8_t* txData, uint8_t txLength, uint8_t* rxData, uint8_t rxLength);uint8_t* txData: A pointer to an array ofuint8_ttype. This is the data you want to send.uint8_t txLength: The length of the data you want to send. Should be less than or equal totxDatalength.uint8_t* rxData: A pointer to an array ofuint8_ttype. This is the location to save the data you want to receive.uint8_t rxLength: The length of the data you want to receive. Should be less than or equal torxDatalength.