Skip to content

Commit d512ec9

Browse files
committed
Initial commit
0 parents  commit d512ec9

19 files changed

+5153
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

ISSUE_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Subject of the issue
2+
Describe your issue here.
3+
4+
### Your workbench
5+
* What platform are you using?
6+
* What version of the device are you using? Is there a firmware version?
7+
* How is the device wired to your platform?
8+
* How is everything being powered?
9+
* Are there any additional details that may help us help you?
10+
11+
### Steps to reproduce
12+
Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue to a gist.
13+
14+
### Expected behaviour
15+
Tell us what should happen
16+
17+
### Actual behaviour
18+
Tell us what happens instead

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HyperDisplay Arduino Library
2+
========================================
3+
4+
Providing uniform drawing and printing functions for a wide range of displays in the Arduino environment
5+
6+
7+
Repository Contents
8+
-------------------
9+
10+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
11+
* **/src** - Source files for the library (.cpp, .h).
12+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
13+
* **library.properties** - General library properties for the Arduino package manager.
14+
15+
Documentation
16+
--------------
17+
18+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
19+
20+
Products that use this Library
21+
---------------------------------
22+
23+
24+
Version History
25+
---------------
26+
27+
28+
License Information
29+
-------------------
30+
31+
This product is _**open source**_!
32+
33+
The **code** is released under the GPL v3 license. See the included LICENSE.md for more information.
34+
35+
Distributed as-is; no warranty is given.
36+
37+
- Your friends at SparkFun.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Take humidity and temperature readings with the SHTC3 using I2C
3+
By: Owen Lyke
4+
SparkFun Electronics
5+
Date: August 24 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
Example1_BasicReadings
8+
To connect the sensor to an Arduino:
9+
This library supports the sensor using the I2C protocol
10+
On Qwiic enabled boards simply connnect the sensor with a Qwiic cable and it is set to go
11+
On non-qwiic boards you will need to connect 4 wires between the sensor and the host board
12+
(Arduino pin) = (Display pin)
13+
SCL = SCL on display carrier
14+
SDA = SDA
15+
GND = GND
16+
3.3V = 3.3V
17+
*/
18+
19+
#include "SparkFun_SHTC3.h" // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
20+
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+
23+
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class
24+
25+
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();
30+
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
32+
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the defualt settings use Wire (default Arduino I2C port) at 400 kHz clock speed
33+
SERIAL_PORT.println();
34+
35+
if(mySHTC3.passIDcrc) // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true
36+
{ // The checksum pass indicators are: passIDcrc, passRHcrc, and passTcrc for the ID, RH, and T readings respectively
37+
SERIAL_PORT.print("ID Passed Checksum. ");
38+
SERIAL_PORT.print("Device ID: 0b");
39+
SERIAL_PORT.print(mySHTC3.ID, BIN); // The 16-bit device ID can be accessed as a member variable of the object
40+
}
41+
else
42+
{
43+
SERIAL_PORT.print("ID Checksum Failed. ");
44+
}
45+
SERIAL_PORT.println("\n\n");
46+
SERIAL_PORT.println("Waiting for 5 seconds so you can read this info ^^^");
47+
48+
delay(5000); // Give time to read the welcome message and device ID.
49+
}
50+
51+
void loop() {
52+
SHTC3_Status_TypeDef result = mySHTC3.update(); // Call "update()" to command a measurement, wait for measurement to complete, and update the RH and T members of the object
53+
printInfo(); // This function is used to print a nice little line of info to the serial port
54+
delay(190); // Delay for the data rate you want - note that measurements take ~10 ms so the fastest data rate is 100 Hz (when no delay is used)
55+
}
56+
57+
58+
59+
///////////////////////
60+
// Utility Functions //
61+
///////////////////////
62+
void printInfo()
63+
{
64+
if(mySHTC3.lastStatus == SHTC3_Status_Nominal) // You can also assess the status of the last command by checking the ".lastStatus" member of the object
65+
{
66+
SERIAL_PORT.print("RH = ");
67+
SERIAL_PORT.print(mySHTC3.toPercent()); // "toPercent" returns the percent humidity as a floating point number
68+
SERIAL_PORT.print("% (checksum: ");
69+
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)
70+
{
71+
SERIAL_PORT.print("pass");
72+
}
73+
else
74+
{
75+
SERIAL_PORT.print("fail");
76+
}
77+
SERIAL_PORT.print("), T = ");
78+
SERIAL_PORT.print(mySHTC3.toDegF()); // "toDegF" and "toDegC" return the temperature as a flaoting point number in deg F and deg C respectively
79+
SERIAL_PORT.print(" deg F (checksum: ");
80+
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)
81+
{
82+
SERIAL_PORT.print("pass");
83+
}
84+
else
85+
{
86+
SERIAL_PORT.print("fail");
87+
}
88+
SERIAL_PORT.println(")");
89+
}
90+
else
91+
{
92+
SERIAL_PORT.print("Update failed, error: ");
93+
errorDecoder(mySHTC3.lastStatus);
94+
SERIAL_PORT.println();
95+
}
96+
}
97+
98+
void errorDecoder(SHTC3_Status_TypeDef message) // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
99+
{
100+
switch(message)
101+
{
102+
case SHTC3_Status_Nominal : SERIAL_PORT.print("Nominal"); break;
103+
case SHTC3_Status_Error : SERIAL_PORT.print("Error"); break;
104+
case SHTC3_Status_CRC_Fail : SERIAL_PORT.print("CRC Fail"); break;
105+
default : SERIAL_PORT.print("Unknown return code"); break;
106+
}
107+
}

0 commit comments

Comments
 (0)