Skip to content

Commit c650d5e

Browse files
author
Nathan Seidle
committed
Move examples to 115200. Add testing of .begin to see if sensor is detected.
1 parent ee27ac1 commit c650d5e

File tree

3 files changed

+48
-38
lines changed

3 files changed

+48
-38
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,35 @@
77
basically do whatever you want with this code.
88
99
Feel like supporting open source hardware?
10-
Buy a board from SparkFun! https://www.sparkfun.com/products/14751
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/15112
1111
1212
This example prints the current CO2 level, relative humidity, and temperature in C.
1313
1414
Hardware Connections:
15-
If needed, attach a Qwiic Shield to your Arduino/Photon/ESP32 or other
16-
Plug the device into an available Qwiic port
17-
Open the serial monitor at 9600 baud to see the output
15+
Attach RedBoard to computer using a USB cable.
16+
Connect SCD30 to RedBoard using Qwiic cable.
17+
Open Serial Monitor at 115200 baud.
1818
*/
1919

2020
#include <Wire.h>
2121

22-
//Click here to get the library: http://librarymanager/All#SparkFun_SCD30
23-
#include "SparkFun_SCD30_Arduino_Library.h"
24-
22+
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
2523
SCD30 airSensor;
2624

2725
void setup()
2826
{
27+
Serial.begin(115200);
28+
Serial.println("SCD30 Example");
2929
Wire.begin();
3030

31-
Serial.begin(9600);
32-
Serial.println("SCD30 Example");
31+
if (airSensor.begin() == false)
32+
{
33+
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
34+
while (1)
35+
;
36+
}
3337

34-
airSensor.begin(); //This will cause readings to occur every two seconds
38+
//The SCD30 has data ready every two seconds
3539
}
3640

3741
void loop()
@@ -50,7 +54,7 @@ void loop()
5054
Serial.println();
5155
}
5256
else
53-
Serial.println("No data");
57+
Serial.println("Waiting for new data");
5458

55-
delay(1000);
59+
delay(500);
5660
}

examples/Example2_SetOptions/Example2_SetOptions.ino

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
basically do whatever you want with this code.
88
99
Feel like supporting open source hardware?
10-
Buy a board from SparkFun! https://www.sparkfun.com/products/14751
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/15112
1111
12-
This example demonstrates the various settings available on the SCD30.
12+
This example prints the current CO2 level, relative humidity, and temperature in C.
1313
1414
Hardware Connections:
15-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
16-
Plug the sensor onto the shield
17-
Serial.print it out at 9600 baud to serial monitor.
15+
Attach RedBoard to computer using a USB cable.
16+
Connect SCD30 to RedBoard using Qwiic cable.
17+
Open Serial Monitor at 115200 baud.
1818
1919
Note: All settings (interval, altitude, etc) are saved to non-volatile memory and are
2020
loaded by the SCD30 at power on. There's no damage in sending that at each power on.
@@ -24,19 +24,21 @@
2424

2525
#include <Wire.h>
2626

27-
//Click here to get the library: http://librarymanager/All#SparkFun_SCD30
28-
#include "SparkFun_SCD30_Arduino_Library.h"
29-
27+
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
3028
SCD30 airSensor;
3129

3230
void setup()
3331
{
34-
Wire.begin();
35-
36-
Serial.begin(9600);
32+
Serial.begin(115200);
3733
Serial.println("SCD30 Example");
34+
Wire.begin();
3835

39-
airSensor.begin(); //This will cause readings to occur every two seconds
36+
if (airSensor.begin() == false)
37+
{
38+
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
39+
while (1)
40+
;
41+
}
4042

4143
airSensor.setMeasurementInterval(4); //Change number of seconds between measurements: 2 to 1800 (30 minutes)
4244

@@ -46,9 +48,12 @@ void setup()
4648
//Pressure in Boulder, CO is 24.65inHg or 834.74mBar
4749
airSensor.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200
4850

49-
float offset = airSensor.getTemperatureOffset(); //Get current temperature offset and save it in the variable "offset"
50-
51-
airSensor.setTemperatureOffset(5); //Set temperature offset to 5°C
51+
float offset = airSensor.getTemperatureOffset();
52+
Serial.print("Current temp offset: ");
53+
Serial.print(offset, 2);
54+
Serial.println("C");
55+
56+
//airSensor.setTemperatureOffset(5); //Optionally we can set temperature offset to 5°C
5257
}
5358

5459
void loop()

examples/Example3_WireOptions/Example3_WireOptions.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,35 @@
77
basically do whatever you want with this code.
88
99
Feel like supporting open source hardware?
10-
Buy a board from SparkFun! https://www.sparkfun.com/products/14751
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/15112
1111
12-
This example demonstrates how to start the library using other Wire ports.
12+
This example prints the current CO2 level, relative humidity, and temperature in C.
1313
1414
Hardware Connections:
15-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
16-
Plug the sensor onto the shield
17-
Serial.print it out at 9600 baud to serial monitor.
15+
This example requires a platform that has multiple I2C ports.
16+
It will not compile on an Uno. Try an Artemis RedBoard or ATP.
1817
1918
Note: 100kHz I2C is fine, but according to the datasheet 400kHz I2C is not supported by the SCD30
2019
*/
2120

2221
#include <Wire.h>
2322

24-
//Click here to get the library: http://librarymanager/All#SparkFun_SCD30
25-
#include "SparkFun_SCD30_Arduino_Library.h"
26-
23+
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
2724
SCD30 airSensor;
2825

2926
void setup()
3027
{
31-
Serial.begin(9600);
28+
Serial.begin(115200);
3229
Serial.println("SCD30 Example");
3330

3431
Wire1.begin(); //Start the wire hardware that may be supported by your platform
3532

36-
airSensor.begin(Wire1); //Pass the Wire port to the .begin() function
33+
if (airSensor.begin(Wire1) == false) //Pass the Wire port to the .begin() function
34+
{
35+
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
36+
while (1)
37+
;
38+
}
3739

3840
//The library will now use Wire1 for all communication
3941
}
@@ -58,4 +60,3 @@ void loop()
5860

5961
delay(1000);
6062
}
61-

0 commit comments

Comments
 (0)