CO2, humidity, and temperature sensor

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Mon May 10 14:13:38 2021 +0000
Parent:
2:0d0174b46fd3
Commit message:
This driver was completed and tested (NUCLEO-L053R8), it works as expected.

Changed in this revision

SCD30.h Show annotated file Show diff for this revision Revisions of this file
--- a/SCD30.h	Fri May 07 13:06:14 2021 +0000
+++ b/SCD30.h	Mon May 10 14:13:38 2021 +0000
@@ -23,7 +23,112 @@
     Example:
 
 @code
+#include "mbed.h"
+#include "SCD30.h"
 
+SCD30 mySCD30 ( I2C_SDA, I2C_SCL, SCD30::SCD30_ADDRESS, 100000 );               // I2C_SDA | I2C_SCL
+Serial pc     ( USBTX, USBRX );                                                 // tx, rx
+
+DigitalOut  myled   ( LED1 );
+Ticker      newAction;
+
+
+//@brief Constants.
+
+
+//@brief Variables.
+volatile uint32_t myState;                                                      // State that indicates when to perform a new sample
+
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    SCD30::SCD30_status_t aux;
+    SCD30::SCD30_data_t   mySCD30_Data;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // It performs a software reset
+    aux  =   mySCD30.SCD30_SoftReset ();
+    wait_ms (2000);
+
+    // It gets the firmware version
+    aux  =   mySCD30.SCD30_GetFirmwareVersion ( &mySCD30_Data.firmware );
+    pc.printf ( "Version Major: %d, Version Minor: %d\r\n", mySCD30_Data.firmware.version_major, mySCD30_Data.firmware.version_minor );
+
+    // It sets two mesurement interval
+    mySCD30_Data.measurement_interval  =   2U;
+    aux  =   mySCD30.SCD30_SetMeasurementInterval ( mySCD30_Data.measurement_interval );
+
+    // It configures the continuous automatic self-calibration
+    mySCD30_Data.asc  =   SCD30::CONTINUOUS_AUTOMATIC_SELF_CALIBRATION_ASC_ACTIVATE;
+    aux  =   mySCD30.SCD30_SetContinuousASC ( mySCD30_Data.asc );
+    wait_ms(2000);
+
+    // It sets the trigger without pressure compensation
+    mySCD30_Data.pressure_compensation  =   0U;
+    aux  =   mySCD30.SCD30_TriggerContinuousMeasurement ( mySCD30_Data.pressure_compensation );
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 5U );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 5s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            // Trigger to get a new data set
+            aux  =   mySCD30.SCD30_TriggerContinuousMeasurement ( mySCD30_Data.pressure_compensation );
+
+            // Wait for a new data value
+            do {
+                aux  =   mySCD30.SCD30_GetDataReadyStatus ( &mySCD30_Data.status );
+                wait_ms (100);
+            } while( mySCD30_Data.status == SCD30::GET_READY_STATUS_BIT_DATA_NO_READY );
+
+            // Get all the values
+            aux  =   mySCD30.SCD30_ReadMeasurement ( &mySCD30_Data.data );
+
+            // Send data through the UART
+            pc.printf ( "CO2: %d ppm, T: %d C, RH: %d %%\r\n", (uint32_t)mySCD30_Data.data.processed.co2, (uint32_t)mySCD30_Data.data.processed.temperature, (uint32_t)mySCD30_Data.data.processed.humidity );
+
+            // Reset the variables
+            myState  =   0UL;
+            myled    =   0U;
+        }
+    }
+}
+
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+// @return       N/A.
+//
+// @author      Manuel Caballero
+// @date        07/May/2021
+// @version     07/May/2021   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */
 
@@ -297,7 +402,7 @@
     /** It calculates the I2C checksum calculation (CRC-8).
       */
     uint8_t         SCD30_CalculateI2C_CRC8             ( uint16_t seed                         );
-    
+
     I2C      _i2c;
     uint32_t _SCD30_Addr;
 };