You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/Example1_BasicReadings/Example1_BasicReadings.ino
+19-51
Original file line number
Diff line number
Diff line change
@@ -18,33 +18,19 @@
18
18
19
19
#include"SparkFun_SHTC3.h"// Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
20
20
21
-
#defineSERIAL_PORT Serial // #define-ing the SERIAL_PORT allows you to easily change your target port - for example if you are using a SAMD21 board you can change "Serial" to "SerialUSB"
22
-
23
21
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class
24
22
25
23
voidsetup() {
26
-
SERIAL_PORT.begin(115200); // Begin Serial
27
-
while(SERIAL_PORT == false){}; // Wait for the serial connection to start up
28
-
SERIAL_PORT.println("SHTC3 Example 1 - Basic Readings"); // Title
29
-
SERIAL_PORT.println();
30
24
31
-
SERIAL_PORT.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
25
+
Serial.begin(115200); // Begin Serial
26
+
while(Serial == false){}; // Wait for the serial connection to start up
27
+
Serial.println("SHTC3 Example 1 - Basic Readings"); // Title
28
+
Wire.begin();
29
+
Serial.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
32
30
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the default settings use Wire (default Arduino I2C port)
33
-
Wire.setClock(400000); // The sensor is listed to work up to 1 MHz I2C speed, but the I2C clock speed is global for all sensors on that bus so using 400kHz or 100kHz is recommended
34
-
SERIAL_PORT.println();
35
-
36
-
if(mySHTC3.passIDcrc) // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true
37
-
{ // The checksum pass indicators are: passIDcrc, passRHcrc, and passTcrc for the ID, RH, and T readings respectively
38
-
SERIAL_PORT.print("ID Passed Checksum. ");
39
-
SERIAL_PORT.print("Device ID: 0b");
40
-
SERIAL_PORT.print(mySHTC3.ID, BIN); // The 16-bit device ID can be accessed as a member variable of the object
41
-
}
42
-
else
43
-
{
44
-
SERIAL_PORT.print("ID Checksum Failed. ");
45
-
}
46
-
SERIAL_PORT.println("\n\n");
47
-
SERIAL_PORT.println("Waiting for 5 seconds so you can read this info ^^^");
31
+
Serial.println();
32
+
Serial.println("\n\n");
33
+
Serial.println("Waiting for 5 seconds so you can read this info ^^^");
48
34
49
35
delay(5000); // Give time to read the welcome message and device ID.
50
36
}
@@ -64,45 +50,27 @@ void printInfo()
64
50
{
65
51
if(mySHTC3.lastStatus == SHTC3_Status_Nominal) // You can also assess the status of the last command by checking the ".lastStatus" member of the object
66
52
{
67
-
SERIAL_PORT.print("RH = ");
68
-
SERIAL_PORT.print(mySHTC3.toPercent()); // "toPercent" returns the percent humidity as a floating point number
69
-
SERIAL_PORT.print("% (checksum: ");
70
-
if(mySHTC3.passRHcrc) // Like "passIDcrc" this is true when the RH value is valid from the sensor (but not necessarily up-to-date in terms of time)
71
-
{
72
-
SERIAL_PORT.print("pass");
73
-
}
74
-
else
75
-
{
76
-
SERIAL_PORT.print("fail");
77
-
}
78
-
SERIAL_PORT.print("), T = ");
79
-
SERIAL_PORT.print(mySHTC3.toDegF()); // "toDegF" and "toDegC" return the temperature as a flaoting point number in deg F and deg C respectively
80
-
SERIAL_PORT.print(" deg F (checksum: ");
81
-
if(mySHTC3.passTcrc) // Like "passIDcrc" this is true when the T value is valid from the sensor (but not necessarily up-to-date in terms of time)
82
-
{
83
-
SERIAL_PORT.print("pass");
84
-
}
85
-
else
86
-
{
87
-
SERIAL_PORT.print("fail");
88
-
}
89
-
SERIAL_PORT.println(")");
53
+
Serial.print("RH = ");
54
+
Serial.print(mySHTC3.toPercent()); // "toPercent" returns the percent humidity as a floating point number
55
+
Serial.print("%, T = ");
56
+
Serial.print(mySHTC3.toDegF()); // "toDegF" and "toDegC" return the temperature as a flaoting point number in deg F and deg C respectively
57
+
Serial.println(" deg F);
90
58
}
91
59
else
92
60
{
93
-
SERIAL_PORT.print("Update failed, error: ");
61
+
Serial.print("Update failed, error: ");
94
62
errorDecoder(mySHTC3.lastStatus);
95
-
SERIAL_PORT.println();
63
+
Serial.println();
96
64
}
97
65
}
98
66
99
67
void errorDecoder(SHTC3_Status_TypeDef message) // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
100
68
{
101
69
switch(message)
102
70
{
103
-
case SHTC3_Status_Nominal : SERIAL_PORT.print("Nominal"); break;
104
-
case SHTC3_Status_Error : SERIAL_PORT.print("Error"); break;
105
-
case SHTC3_Status_CRC_Fail : SERIAL_PORT.print("CRC Fail"); break;
0 commit comments