Skip to content

Commit a6403e8

Browse files
committed
Merge branch 'main' of https://github.com/Sensirion/arduino-snippets into main
2 parents 9d4cbff + 2473eca commit a6403e8

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,66 @@ All samples in this directory share the same format; as such, you can follow the
2121
1. Save your project under a meaningful name
2222
1. Compile and flash the sketch
2323
1. Open the "Serial Monitor" from the "Tools" menu in the Arduino IDE to display the output data read from the sensor
24+
25+
# Examples by sensor
26+
27+
## SCD4x
28+
29+
|Name|Protocol|Description|
30+
|----|--------|-----------|
31+
|[SCD4x_I2C_minimal_example](/SCD4x_I2C_minimal_example)|I2C|Minimal example to get started|
32+
|[SCD4x_I2C_FRC_Forced_Recalibration_Example](SCD4x_I2C_FRC_Forced_Recalibration_Example)|I2C|Show forced recalibration|
33+
34+
## SEN44
35+
|Name|Protocol|Description|
36+
|----|--------|-----------|
37+
|[SEN44_I2C_minimal_example](/SEN44_I2C_minimal_example)|I2C|Basic example for I2C|
38+
|[SEN44_I2C_pm_values_floating_point](/SEN44_I2C_pm_values_floating_point)|I2C|Read out PM values as floating point|
39+
|[SEN44_I2C_change_T_offset_example](/SEN44_I2C_change_T_offset_example)|I2C|Change T offset over I2C|
40+
|[SEN44_I2C_change_VOC_parameters_example](/SEN44_I2C_change_VOC_parameters_example)|I2C|Change VOC parameters over I2C|
41+
|[SEN44_SCD40_I2C_example](/SEN44_SCD40_I2C_example)|I2C|Example using SEN44 with SCD4x|
42+
|[SEN44_UART_minimal_example](/SEN44_UART_minimal_example)|UART|Basic example for UART (Serial) interface|
43+
44+
## SFA30
45+
|Name|Protocol|Description|
46+
|----|--------|-----------|
47+
|[SFA30_I2C_minimal_example](/SFA30_I2C_minimal_example)|I2C|Minimal example to get started|
48+
49+
50+
## SGP40
51+
|Name|Protocol|Description|
52+
|----|--------|-----------|
53+
|[SGP40_SHTC3_I2C_voc_algo_minimal_example](/SGP40_SHTC3_I2C_voc_algo_minimal_example)|I2C|Minimal example to use SGP40 with VOC Index algorithm|
54+
55+
## SHT3x
56+
|Name|Protocol|Description|
57+
|----|--------|-----------|
58+
|[SHT3x_I2C_minimal_example](/SHT3x_I2C_minimal_example)|I2C|Minimal example to get started|
59+
60+
## SHT4x
61+
|Name|Protocol|Description|
62+
|----|--------|-----------|
63+
|[SHT4x_I2C_minimal_example](/SHT4x_I2C_minimal_example)|I2C|Minimal example to get started|
64+
65+
## SHTC3
66+
|Name|Protocol|Description|
67+
|----|--------|-----------|
68+
|[SHTC3_I2C_minimal_example](/SHTC3_I2C_minimal_example)|I2C|Minimal example to get started|
69+
70+
71+
## SVM40
72+
|Name|Protocol|Description|
73+
|----|--------|-----------|
74+
|[SVM40_I2C_minimal_example](/SVM40_I2C_minimal_example)|I2C|Minimal example to get started|
75+
|[SVM40_I2C_change_T_offset_example](/SVM40_I2C_change_T_offset_example)|I2C|Change T offset|
76+
|[SVM40_I2C_change_VOC_parameters_example](/SVM40_I2C_change_VOC_parameters_example)|I2C|Change VOC index algorithm parameters|
77+
78+
79+
## SDP8xx
80+
|Name|Protocol|Description|
81+
|----|--------|-----------|
82+
|[SDP8xx_I2C_minimal_example](/SDP8xx_I2C_minimal_example)|I2C|Minimal example to get started|
83+
84+
85+
86+

SFM3x00_I2C_minimal_example/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SFM3x00 Minimal Example
2+
3+
## Configuration
4+
5+
Please note that the model selection is done manually, line 55 of [SFM3x00_minimal_example.ino](SFM3x00_minimal_example.ino#55)
6+
7+
```c++
8+
54: // ACTION: select your component here from the enum above:
9+
55: const uint8_t MODEL = SFM3200;
10+
```
11+
12+
The available sensors can be found on line 36 of [SFM3x00_minimal_example.ino](SFM3x00_minimal_example.ino#36)
13+
14+
```c++
15+
35: // supported sensors
16+
36: enum SFM_MODEL {
17+
37: SFM3000 = 0,
18+
38: SFM3200,
19+
39: SFM3300,
20+
40: SFM3400,
21+
41: SFM_MODEL_LENGTH //< Note: this is not a valid value for 'MODEL' below
22+
42: };
23+
```
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2021, Sensirion AG
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* * Neither the name of Sensirion AG nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
33+
#include <Wire.h>
34+
35+
// supported sensors
36+
enum SFM_MODEL {
37+
SFM3000 = 0,
38+
SFM3200,
39+
SFM3300,
40+
SFM3400,
41+
SFM_MODEL_LENGTH //< Note: this is not a valid value for 'MODEL' below
42+
};
43+
44+
// from the datasheets:
45+
const int16_t SFM3X00_ADDRESS = 0x40;
46+
47+
const int16_t FLOW_OFFSET[SFM_MODEL_LENGTH] = { 32000, 32768, 32768, 32768 };
48+
const int16_t SCALE_FACTOR_AIR[SFM_MODEL_LENGTH] = { 140, 140, 120, 800 };
49+
50+
const byte CMD_START_MEASUREMENT[] = { 0x10, 0x00 };
51+
const byte CMD_SOFT_RESET[] = { 0x20, 0x00 };
52+
53+
54+
// ACTION: select your component here from the enum above:
55+
const uint8_t MODEL = SFM3200;
56+
57+
void setup()
58+
{
59+
Serial.begin(115200);
60+
while(!Serial);
61+
62+
Wire.begin();
63+
64+
/*
65+
// optional reset before use
66+
Wire.beginTransmission(SFM3X00_ADDRESS);
67+
Wire.write(CMD_SOFT_RESET, 2);
68+
Wire.endTransmission();
69+
delay(100);
70+
*/
71+
72+
Wire.beginTransmission(SFM3X00_ADDRESS);
73+
Wire.write(CMD_START_MEASUREMENT, 2);
74+
Wire.endTransmission();
75+
76+
delay(100);
77+
Serial.println("Flow rate [slm]");
78+
}
79+
80+
void loop()
81+
{
82+
Wire.requestFrom(SFM3X00_ADDRESS, 3);
83+
if (Wire.available() < 3) {
84+
Serial.println("No data received from sensor");
85+
} else {
86+
int16_t flow;
87+
flow = (int16_t)Wire.read() << 8;
88+
flow |= Wire.read();
89+
// CRC verification (third byte) left as an exercise for the reader
90+
91+
flow = (flow - FLOW_OFFSET[MODEL]) / SCALE_FACTOR_AIR[MODEL];
92+
Serial.println(flow);
93+
}
94+
95+
delay(100);
96+
}

0 commit comments

Comments
 (0)