Skip to content

Commit fc14808

Browse files
Merge pull request #2 from sparkfun/development-2
Development 2 Branch merge to Main post Code Review
2 parents 6ac9c42 + fb1cdc3 commit fc14808

File tree

14 files changed

+734
-626
lines changed

14 files changed

+734
-626
lines changed

Examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 0 additions & 57 deletions
This file was deleted.

README.md

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
SparkFun <PRODUCT NAME>
1+
SparkFun STHS34PF80 Arduino Library
22
========================================
33

4-
[![SparkFun Part Name](URL for picture of part)](URL for product on Sparkfun.com)
54

6-
[*SparkFun Part Name (SKU)*](URL for product on Sparkfun.com)
7-
8-
<Basic description of the part.>
5+
This is the SparkFun library for the STMicroelectronics STHS34PF80 IR sensor with an operating wavelength between 5 µm and 20 µm with I<sup>2</sup>C and SPI interface. (https://www.sparkfun.com/products/22494).
96

107
Repository Contents
118
-------------------
129

13-
* **/Documentation** - Data sheets, additional product information
14-
* **/Enclosure** - Enclosure files
15-
* **/Firmware** - Example code
16-
* **/Hardware** - Eagle design files (.brd, .sch)
17-
* **/Libraries** - Libraries for use with the <PRODUCT NAME>
18-
* **/Production** - Production panel files (.brd)
19-
* **/Software** - Related software for the <PRODUCT NAME>
10+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
11+
* **/src** - Source files for the library (.cpp, .h).
12+
* **/Documentation** - Datasheet and application note for the STHS34PF80.
13+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
14+
* **library.properties** - General library properties for the Arduino package manager.
15+
* **[CONTRIBUTING.md](./CONTRIBUTING.md)** - guidance on how to contribute to this library.
16+
2017

2118
Documentation
2219
--------------
23-
* **[Library](GitHub library URL)** - <LANGUAGE> library for the <PRODUCT NAME>.
24-
* **[Hookup Guide](Learn.SparkFun URL)** - Basic hookup guide for the <PRODUCT NAME>.
25-
* **[SparkFun Fritzing repo](https://github.com/sparkfun/Fritzing_Parts)** - Fritzing diagrams for SparkFun products.
26-
* **[SparkFun 3D Model repo](https://github.com/sparkfun/3D_Models)** - 3D models of SparkFun products.
27-
* **[SparkFun Graphical Datasheets](https://github.com/sparkfun/Graphical_Datasheets)** -Graphical Datasheets for various SparkFun products.
28-
29-
Product Versions
30-
----------------
31-
* [Part SKU](part URL) - Basic part and short description here
32-
* [Retail part SKU](retail URL) - Retail packaging of standard description here
33-
* [Any other parts this repo covers](any other URLs) - Description of said parts
34-
35-
Version History
36-
---------------
37-
* [vExxFxxZxxHxxLxxSxx](URL for tag specific to this version) - Description
38-
* [vEyyFyyZyyHyyLyySyy](URL for tag specific to this version) - Description
20+
21+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
22+
* **[Hookup Guide](https://docs.sparkfun.com/SparkFun_IoT_Brushless_Motor_Driver)** - Basic hookup guide for the SparkFun IoT Motor Driver Breakout (ESP32, TMC6300).
23+
* **[Product Repository](https://github.com/sparkfun/SparkFun_IoT_Brushless_Motor_Driver)** - Main repository for the IoT Motor Driver (including hardware files)
24+
25+
26+
Products that use this Library
27+
---------------------------------
28+
29+
* [*SEN-22494*](https://www.sparkfun.com/products/22494)
30+
* [*SEN-23253*](https://www.sparkfun.com/products/23253)
31+
3932

4033
License Information
4134
-------------------
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "SparkFun_STHS34PF80_Arduino_Library.h"
2+
#include <Wire.h>
3+
4+
STHS34PF80_I2C mySensor;
5+
6+
// Values to fill with presence and motion data
7+
int16_t presenceVal = 0;
8+
int16_t motionVal = 0;
9+
float temperatureVal = 0;
10+
11+
12+
void setup()
13+
{
14+
Serial.begin(115200);
15+
Serial.println("STHS34PF80 Example 1: Basic Readings");
16+
17+
// Begin I2C
18+
if(Wire.begin() == 0)
19+
{
20+
Serial.println("I2C Error - check I2C Address");
21+
while(1);
22+
}
23+
24+
// Establish communication with device
25+
if(mySensor.begin() != 0)
26+
{
27+
Serial.println("Error setting up device - please check wiring.");
28+
while(1);
29+
}
30+
31+
delay(1000);
32+
}
33+
34+
void loop()
35+
{
36+
sths34pf80_tmos_drdy_status_t dataReady;
37+
mySensor.getDataReady(&dataReady);
38+
39+
// Check whether sensor has new data - run through loop if data is ready
40+
if(dataReady.drdy == 1)
41+
{
42+
sths34pf80_tmos_func_status_t status;
43+
mySensor.getStatus(&status);
44+
45+
// If presence flag is high, then print data
46+
if(status.pres_flag == 1)
47+
{
48+
// Presence Units: cm^-1
49+
mySensor.getPresenceValue(&presenceVal);
50+
Serial.print("Presence: ");
51+
Serial.print(presenceVal);
52+
Serial.println(" cm^-1");
53+
}
54+
55+
if(status.mot_flag == 1)
56+
{
57+
Serial.println("Motion Detected!");
58+
}
59+
60+
if(status.tamb_shock_flag == 1)
61+
{
62+
mySensor.getTemperatureData(&temperatureVal);
63+
Serial.print("Temperature: ");
64+
Serial.print(temperatureVal);
65+
Serial.println(" °C");
66+
}
67+
}
68+
69+
}
70+

examples/Example2_Interrupts/Example2_Interrupts.ino

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,80 @@
22
#include <Wire.h>
33

44
STHS34PF80_I2C mySensor;
5-
// STHS34PF80_SPI mySensor;
65

7-
// Values to fill with presence and motion data
6+
// Values to fill with presence data
87
int16_t presenceVal = 0;
9-
int16_t motionVal = 0;
108

119
// Change the pin number to the pin that has been chosen for your setup
1210
int intPin = 12;
1311

14-
sths34pf80_tmos_route_int_t interruptRoute = STHS34PF80_TMOS_INT_DRDY;
12+
// Star the flag as false
13+
bool volatile interruptFlag = false;
1514

15+
// ISR to set the triggered interrupt
16+
void isr1()
17+
{
18+
interruptFlag = true;
19+
}
1620

1721
void setup()
1822
{
1923
Serial.begin(115200);
2024
Serial.println("STHS34PF80 Example 2: Interrupts");
2125

22-
// Begin I2C transactions
23-
Wire.begin();
24-
25-
// Checks established connection
26-
if(mySensor.begin() == false)
26+
// Begin I2C
27+
if(Wire.begin() == 0)
2728
{
28-
Serial.println("Error"); // fix this print message
29+
Serial.println("I2C Error - check I2C Address");
2930
while(1);
3031
}
3132

32-
// Data Ready signal routed to the INT pin
33-
mySensor.setTmosRouteInterrupt(interruptRoute);
34-
35-
// **FINISH READING INTERRUPT SECTION TO MAKE SURE NO MORE IS NEEDED**
33+
// Establish communication with device
34+
if(mySensor.begin() != 0)
35+
{
36+
Serial.println("Error setting up device - please check wiring.");
37+
while(1);
38+
}
3639

3740
// Set INT pin to be triggered on rising and falling edges of INT pin
3841
pinMode(intPin, INPUT);
42+
// Attach interrupt to the pin as a digital pin that triggers on a change
43+
attachInterrupt(digitalPinToInterrupt(intPin), isr1, CHANGE);
44+
45+
// Route all interrupts from device to interrupt pin
46+
mySensor.setTmosRouteInterrupt(STHS34PF80_TMOS_INT_OR);
47+
48+
// Enable the presence interrupt source
49+
// (see page 17 of application note AN5867 for more information)
50+
mySensor.setTmosInterruptOR(STHS34PF80_TMOS_INT_PRESENCE);
51+
52+
// Set interrupt value to pulsed on the INT pin
53+
mySensor.setInterruptPulsed(0);
3954

40-
delay(1000);
55+
delay(500);
4156
}
4257

4358
void loop()
4459
{
45-
46-
// Value to read interrupt pin status
47-
int interruptVal = digitalRead(intPin);
48-
49-
if(interruptVal == HIGH)
60+
// If interrupt is triggered
61+
if(interruptFlag == true)
5062
{
51-
sths34pf80_tmos_func_status_t status = mySensor.getStatus();
63+
interruptFlag = false;
64+
65+
sths34pf80_tmos_func_status_t status;
66+
mySensor.getStatus(&status);
67+
68+
Serial.println("Data ready!");
69+
5270

5371
// If the flag is high, then read out the information
5472
if(status.pres_flag == 1)
5573
{
5674
// Presence Units: cm^-1
5775
mySensor.getPresenceValue(&presenceVal);
5876
Serial.print("Presence: ");
59-
Serial.println(presenceVal);
60-
}
61-
62-
if(status.mot_flag == 1)
63-
{
64-
mySensor.getMotionValue(&motionVal);
65-
Serial.print("Motion: ");
66-
Serial.println(motionVal);
77+
Serial.print(presenceVal);
78+
Serial.println("cm^-1");
6779
}
6880
}
69-
70-
}
81+
}

0 commit comments

Comments
 (0)