diff --git a/README.md b/README.md index f320e44..b8efeb7 100644 --- a/README.md +++ b/README.md @@ -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-` if necessary) +3. Try out one of the examples from `File > Examples > arduino-sdp` (replace `arduino-sdp` with `arduino-sdp-` 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-` 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 diff --git a/examples/sdp_generic/sdp_generic.ino b/examples/sdp3x_default_address/sdp3x_default_address.ino similarity index 70% rename from examples/sdp_generic/sdp_generic.ino rename to examples/sdp3x_default_address/sdp3x_default_address.ino index b52be10..a176929 100644 --- a/examples/sdp_generic/sdp_generic.ino +++ b/examples/sdp3x_default_address/sdp3x_default_address.ino @@ -2,25 +2,16 @@ #include -// 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 = "); @@ -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 | "); diff --git a/examples/sdp3x_manual_address/sdp3x_manual_address.ino b/examples/sdp3x_manual_address/sdp3x_manual_address.ino new file mode 100644 index 0000000..f117f0a --- /dev/null +++ b/examples/sdp3x_manual_address/sdp3x_manual_address.ino @@ -0,0 +1,45 @@ +#include + +#include + +// 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); +} diff --git a/examples/sdp8xx/sdp8xx.ino b/examples/sdp8xx/sdp8xx.ino new file mode 100644 index 0000000..9ba39c4 --- /dev/null +++ b/examples/sdp8xx/sdp8xx.ino @@ -0,0 +1,40 @@ +#include + +#include + +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); +}