Skip to content

Commit 1a0ce21

Browse files
removing wire.begin from inside library, updating examples to match, changing Serial debug, adding simple example 1
1 parent 81e4af9 commit 1a0ce21

15 files changed

+205
-4066
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

+19-51
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,19 @@
1818

1919
#include "SparkFun_SHTC3.h" // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
2020

21-
#define SERIAL_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-
2321
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class
2422

2523
void setup() {
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();
3024

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
3230
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 ^^^");
4834

4935
delay(5000); // Give time to read the welcome message and device ID.
5036
}
@@ -64,45 +50,27 @@ void printInfo()
6450
{
6551
if(mySHTC3.lastStatus == SHTC3_Status_Nominal) // You can also assess the status of the last command by checking the ".lastStatus" member of the object
6652
{
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);
9058
}
9159
else
9260
{
93-
SERIAL_PORT.print("Update failed, error: ");
61+
Serial.print("Update failed, error: ");
9462
errorDecoder(mySHTC3.lastStatus);
95-
SERIAL_PORT.println();
63+
Serial.println();
9664
}
9765
}
9866
9967
void errorDecoder(SHTC3_Status_TypeDef message) // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
10068
{
10169
switch(message)
10270
{
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;
106-
default : SERIAL_PORT.print("Unknown return code"); break;
71+
case SHTC3_Status_Nominal : Serial.print("Nominal"); break;
72+
case SHTC3_Status_Error : Serial.print("Error"); break;
73+
case SHTC3_Status_CRC_Fail : Serial.print("CRC Fail"); break;
74+
default : Serial.print("Unknown return code"); break;
10775
}
10876
}

0 commit comments

Comments
 (0)