|
| 1 | +/* |
| 2 | + Reading CO2, humidity and temperature from the SCD30 |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: May 22nd, 2018 |
| 6 | + License: MIT. See license file for more information but you can |
| 7 | + basically do whatever you want with this code. |
| 8 | +
|
| 9 | + Feel like supporting open source hardware? |
| 10 | + Buy a board from SparkFun! https://www.sparkfun.com/products/15112 |
| 11 | +
|
| 12 | + This example gets the SCD30's settings using the new getSettingValue function (thank you paulvha) |
| 13 | +
|
| 14 | + Hardware Connections: |
| 15 | + Attach RedBoard to computer using a USB cable. |
| 16 | + Connect SCD30 to RedBoard using Qwiic cable. |
| 17 | + Open Serial Monitor at 115200 baud. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include <Wire.h> |
| 21 | + |
| 22 | +#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30 |
| 23 | +SCD30 airSensor; |
| 24 | + |
| 25 | +void setup() |
| 26 | +{ |
| 27 | + Serial.begin(115200); |
| 28 | + Serial.println("SCD30 Example"); |
| 29 | + Wire.begin(); |
| 30 | + |
| 31 | + //Start sensor using the Wire port, but disable the auto-calibration |
| 32 | + if (airSensor.begin(Wire, false) == false) |
| 33 | + { |
| 34 | + Serial.println("Air sensor not detected. Please check wiring. Freezing..."); |
| 35 | + while (1) |
| 36 | + ; |
| 37 | + } |
| 38 | + |
| 39 | + uint16_t settingVal; // The settings will be returned in settingVal |
| 40 | + |
| 41 | + if (airSensor.getForcedRecalibration(&settingVal) == true) // Get the setting |
| 42 | + { |
| 43 | + Serial.print("Forced recalibration factor (ppm) is "); |
| 44 | + Serial.println(settingVal); |
| 45 | + } |
| 46 | + else |
| 47 | + { |
| 48 | + Serial.print("getForcedRecalibration failed! Freezing..."); |
| 49 | + while (1) |
| 50 | + ; // Do nothing more |
| 51 | + } |
| 52 | + |
| 53 | + if (airSensor.getMeasurementInterval(&settingVal) == true) // Get the setting |
| 54 | + { |
| 55 | + Serial.print("Measurement interval (s) is "); |
| 56 | + Serial.println(settingVal); |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + Serial.print("getMeasurementInterval failed! Freezing..."); |
| 61 | + while (1) |
| 62 | + ; // Do nothing more |
| 63 | + } |
| 64 | + |
| 65 | + if (airSensor.getTemperatureOffset(&settingVal) == true) // Get the setting |
| 66 | + { |
| 67 | + Serial.print("Temperature offfset (C) is "); |
| 68 | + Serial.println(((float)settingVal) / 100.0, 2); |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + Serial.print("getTemperatureOffset failed! Freezing..."); |
| 73 | + while (1) |
| 74 | + ; // Do nothing more |
| 75 | + } |
| 76 | + |
| 77 | + if (airSensor.getAltitudeCompensation(&settingVal) == true) // Get the setting |
| 78 | + { |
| 79 | + Serial.print("Altitude offset (m) is "); |
| 80 | + Serial.println(settingVal); |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + Serial.print("getAltitudeCompensation failed! Freezing..."); |
| 85 | + while (1) |
| 86 | + ; // Do nothing more |
| 87 | + } |
| 88 | + |
| 89 | + if (airSensor.getFirmwareVersion(&settingVal) == true) // Get the setting |
| 90 | + { |
| 91 | + Serial.print("Firmware version is 0x"); |
| 92 | + Serial.println(settingVal, HEX); |
| 93 | + } |
| 94 | + else |
| 95 | + { |
| 96 | + Serial.print("getFirmwareVersion! Freezing..."); |
| 97 | + while (1) |
| 98 | + ; // Do nothing more |
| 99 | + } |
| 100 | + |
| 101 | + Serial.print("Auto calibration set to "); |
| 102 | + if (airSensor.getAutoSelfCalibration() == true) |
| 103 | + Serial.println("true"); |
| 104 | + else |
| 105 | + Serial.println("false"); |
| 106 | + |
| 107 | + //The SCD30 has data ready every two seconds |
| 108 | +} |
| 109 | + |
| 110 | +void loop() |
| 111 | +{ |
| 112 | + if (airSensor.dataAvailable()) |
| 113 | + { |
| 114 | + Serial.print("co2(ppm):"); |
| 115 | + Serial.print(airSensor.getCO2()); |
| 116 | + |
| 117 | + Serial.print(" temp(C):"); |
| 118 | + Serial.print(airSensor.getTemperature(), 1); |
| 119 | + |
| 120 | + Serial.print(" humidity(%):"); |
| 121 | + Serial.print(airSensor.getHumidity(), 1); |
| 122 | + |
| 123 | + Serial.println(); |
| 124 | + } |
| 125 | + else |
| 126 | + Serial.println("Waiting for new data"); |
| 127 | + |
| 128 | + delay(500); |
| 129 | +} |
0 commit comments