Skip to content

Commit 3085765

Browse files
committed
Add SDP8xx example
1 parent 5a48447 commit 3085765

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2020, 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+
#include <Wire.h>
33+
34+
// SDP810 500 Pa
35+
const int16_t SDP810_ADDRESS = 0x25;
36+
37+
void setup() {
38+
Serial.begin(115200);
39+
// wait for serial connection from PC
40+
// comment the following line if you'd like the output
41+
// without waiting for the interface being ready
42+
while(!Serial);
43+
44+
// output format
45+
Serial.println("DP\tT");
46+
47+
// init I2C
48+
Wire.begin();
49+
50+
// wait until sensors startup, > 25 ms according to datasheet
51+
delay(25);
52+
53+
// start up sensor, sensor will go to continuous measurement mode
54+
// differential pressure mode with averaging till read
55+
Wire.beginTransmission(SDP810_ADDRESS);
56+
Wire.write(0x36);
57+
Wire.write(0x15);
58+
Wire.endTransmission();
59+
60+
// wait until first data is ready, > 8 ms
61+
delay(10);
62+
}
63+
64+
void loop() {
65+
66+
uint16_t scaling;
67+
int16_t dp, temperature;
68+
uint8_t data[9], counter;
69+
70+
// read measurement data, after two bytes a CRC follows
71+
Wire.requestFrom(SDP810_ADDRESS, 9);
72+
counter = 0;
73+
while (Wire.available()) {
74+
data[counter++] = Wire.read();
75+
}
76+
77+
dp = (uint16_t)data[0] << 8 | data[1];
78+
temperature = (uint16_t)data[3] << 8 | data[4];
79+
scaling = (uint16_t)data[6] << 8 | data[7];
80+
81+
82+
Serial.print(String(float(dp) / scaling));
83+
Serial.print("\t");
84+
Serial.print(String(float(temperature) / 200));
85+
Serial.println();
86+
87+
// wait 100 ms for next measurement
88+
delay(100);
89+
}

0 commit comments

Comments
 (0)