Yohei Shimmyo / Mbed 2 deprecated CCS811_test

Dependencies:   mbed CCS811 DHT

Files at this revision

API Documentation at this revision

Comitter:
rollman
Date:
Mon Jan 03 02:41:25 2022 +0000
Parent:
0:fcddd87b788e
Commit message:
initial commit;

Changed in this revision

CCS811.lib Show annotated file Show diff for this revision Revisions of this file
DHT.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/CCS811.lib	Thu Mar 05 08:27:47 2020 +0000
+++ b/CCS811.lib	Mon Jan 03 02:41:25 2022 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/MtM/code/CCS811/#ec392b3a49f2
+https://os.mbed.com/users/rollman/code/CCS811/#423f2830684e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT.lib	Mon Jan 03 02:41:25 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/components/code/DHT/#6937e130feca
--- a/main.cpp	Thu Mar 05 08:27:47 2020 +0000
+++ b/main.cpp	Mon Jan 03 02:41:25 2022 +0000
@@ -1,11 +1,16 @@
 #include "mbed.h"
 #include "CCS811.h"
+#include "DHT.h"
 
+eType partname = DHT11;
+eScale tmp_fmt = CELCIUS;
+Serial m_pc(USBTX, USBRX);
 
 int main() {
-    Serial m_pc(USBTX, USBRX);
     m_pc.baud(9600);
     
+    DHT dht(p26, partname);
+    
     I2C i2c_ccs811(p28, p27);
     // i2c_ccs811.frequency(100000);
     CCS811 ccs(i2c_ccs811, m_pc);
@@ -26,9 +31,22 @@
     
     uint16_t co2, tvoc;
     while(1) {
+        wait(3);
+        int dhtres;
+        if ((dhtres = dht.readData()) != 0){
+            m_pc.printf("ERROR when reading DHT11: %d\r\n", dhtres);
+            continue;
+        }
+        float celsius = dht.ReadTemperature(tmp_fmt);
+        float humidity = dht.ReadHumidity();
+        m_pc.printf("DEBUG: celsius = %f, humidity = %f\r\n", celsius, humidity);
+        ccs.setEnvironment(celsius, humidity);
         while(!ccs.readStatus() & 0x08); // wait for DATA_READY
-        ccs.readData(&co2, &tvoc);
+        int err;
+        if((err = ccs.readData(&co2, &tvoc)) != 0){
+            printerr(m_pc, err);
+            continue;
+        }
         m_pc.printf("%d %d\r\n", co2, tvoc);
-        wait(0.5);
     }
 }