Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Commit

Permalink
create separate examples for SDP3x and SDP8xx
Browse files Browse the repository at this point in the history
  • Loading branch information
winkj committed Jun 15, 2018
1 parent 423a5aa commit 6e0ebba
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ and 125Pa sensor types are supported.

## Installation

1. Download the latest ZIP version from the [github releases page](https://github.com/winkj/arduino-sdp/releases).
1. Download the latest ZIP version from the [github releases page](https://github.com/winkj/arduino-sdp/releases).
2. Open Arduino IDE, and select `Sketch > Include Library > Add .ZIP Library`, and select the ZIP file you downloaded in step 2
3. Try out the example from `File > Examples > arduino-sdp > sdp_generic` (replace `arduino-sdp` with `arduino-sdp-<version>` if necessary)
3. Try out one of the examples from `File > Examples > arduino-sdp` (replace `arduino-sdp` with `arduino-sdp-<version>` if necessary)

## Getting started

To get started, have a look at the `sdp_generic` example from the "Examples" menu.
Follow the steps below to initialize for your sensor:
To get started, have a look at the examples from `File > Examples > arduino-sdp` (replace `arduino-sdp` with `arduino-sdp-<version>` if necessary):

- For SDP3x on its default I2C address 0x21, use example `sdp3x_default_address`
- For SDP3x on I2C address 0x22 or 0x23, use example `sdp3x_manual_address`
- For the SDP8xx series, use example `sdp8xx`

### Initializing for SDP3x on I2C address 0x21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

#include <sdpsensor.h>

// use this for an SDP3x on the default I2C address of 0x21:
// SDP3x on the default I2C address of 0x21:
SDP3XSensor sdp;

// If your SDP3x is not using the default I2C address of 0x21, uncomment the
// line below:
// SDP3XSensor sdp(SDP3X_I2C_ADDR_22);


// If you're using an SDP8xx, uncomment the line below instead:
// SDP8XXSensor sdp;


void setup() {
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle

int ret = sdp.init();
if (!ret) {
if (ret == 0) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed, ret = ");
Expand All @@ -33,7 +24,7 @@ void setup() {

void loop() {
int ret = sdp.readSample();
if (!ret) {
if (ret == 0) {
Serial.print("Differential pressure: ");
Serial.print(sdp.getDifferentialPressure());
Serial.print("Pa | ");
Expand Down
45 changes: 45 additions & 0 deletions examples/sdp3x_manual_address/sdp3x_manual_address.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <Wire.h>

#include <sdpsensor.h>

// To configure the I2C address manually, choose one of the three calls below;
// make sure you comment out the other two, otherwise the sketch won't build!

SDP3XSensor sdp(SDP3X_I2C_ADDR_21); // Address 0x21
// SDP3XSensor sdp(SDP3X_I2C_ADDR_22); // Address 0x22
// SDP3XSensor sdp(SDP3X_I2C_ADDR_23); // Address 0x23

void setup() {
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle

int ret = sdp.init();
if (ret == 0) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed, ret = ");
Serial.println(ret);
while (true) {
delay(1000);
}
}
}

void loop() {
int ret = sdp.readSample();
if (ret == 0) {
Serial.print("Differential pressure: ");
Serial.print(sdp.getDifferentialPressure());
Serial.print("Pa | ");

Serial.print("Temp: ");
Serial.print(sdp.getTemperature());
Serial.print("C\n");
} else {
Serial.print("Error in readSample(), ret = ");
Serial.println(ret);
}

delay(500);
}
40 changes: 40 additions & 0 deletions examples/sdp8xx/sdp8xx.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Wire.h>

#include <sdpsensor.h>

SDP8XXSensor sdp;

void setup() {
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle

int ret = sdp.init();
if (ret == 0) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed, ret = ");
Serial.println(ret);
while (true) {
delay(1000);
}
}
}

void loop() {
int ret = sdp.readSample();
if (ret == 0) {
Serial.print("Differential pressure: ");
Serial.print(sdp.getDifferentialPressure());
Serial.print("Pa | ");

Serial.print("Temp: ");
Serial.print(sdp.getTemperature());
Serial.print("C\n");
} else {
Serial.print("Error in readSample(), ret = ");
Serial.println(ret);
}

delay(500);
}

0 comments on commit 6e0ebba

Please sign in to comment.