|
| 1 | +/****************************************************************************** |
| 2 | + SparkFun Si7021 Breakout Example |
| 3 | + Joel Bartlett @ SparkFun Electronics |
| 4 | + Original Creation Date: May 18, 2015 |
| 5 | + Updated May 4, 2016 |
| 6 | + This sketch prints the temperature and humidity the Serial port. |
| 7 | +
|
| 8 | + The library used in this example can be found here: |
| 9 | + https://github.com/sparkfun/Si7021_Breakout/tree/master/Libraries |
| 10 | +
|
| 11 | + Hardware Connections: |
| 12 | + HTU21D ------------- Photon |
| 13 | + (-) ------------------- GND |
| 14 | + (+) ------------------- 3.3V (VCC) |
| 15 | + CL ------------------- D1/SCL |
| 16 | + DA ------------------- D0/SDA |
| 17 | +
|
| 18 | + Development environment specifics: |
| 19 | + IDE: Particle Dev |
| 20 | + Hardware Platform: SparkFun RedBoard |
| 21 | + Arduino IDE 1.6.5 |
| 22 | +
|
| 23 | + This code is beerware; if you see me (or any other SparkFun |
| 24 | + employee) at the local, and you've found our code helpful, |
| 25 | + please buy us a round! |
| 26 | + Distributed as-is; no warranty is given. |
| 27 | +*******************************************************************************/ |
| 28 | +#include "SparkFun_Si7021_Breakout_Library.h" |
| 29 | +#include <Wire.h> |
| 30 | + |
| 31 | +float humidity = 0; |
| 32 | +float tempf = 0; |
| 33 | + |
| 34 | + |
| 35 | +int power = A3; |
| 36 | +int GND = A2; |
| 37 | + |
| 38 | +//Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor |
| 39 | +Weather sensor; |
| 40 | + |
| 41 | +//--------------------------------------------------------------- |
| 42 | +void setup() |
| 43 | +{ |
| 44 | + Serial.begin(9600); // open serial over USB at 9600 baud |
| 45 | + |
| 46 | + pinMode(power, OUTPUT); |
| 47 | + pinMode(GND, OUTPUT); |
| 48 | + |
| 49 | + digitalWrite(power, HIGH); |
| 50 | + digitalWrite(GND, LOW); |
| 51 | + |
| 52 | + //Initialize the I2C sensors and ping them |
| 53 | + sensor.begin(); |
| 54 | + |
| 55 | +} |
| 56 | +//--------------------------------------------------------------- |
| 57 | +void loop() |
| 58 | +{ |
| 59 | + //Get readings from all sensors |
| 60 | + getWeather(); |
| 61 | + printInfo(); |
| 62 | + delay(1000); |
| 63 | + |
| 64 | +} |
| 65 | +//--------------------------------------------------------------- |
| 66 | +void getWeather() |
| 67 | +{ |
| 68 | + // Measure Relative Humidity from the HTU21D or Si7021 |
| 69 | + humidity = sensor.getRH(); |
| 70 | + |
| 71 | + // Measure Temperature from the HTU21D or Si7021 |
| 72 | + tempf = sensor.getTempF(); |
| 73 | + // Temperature is measured every time RH is requested. |
| 74 | + // It is faster, therefore, to read it from previous RH |
| 75 | + // measurement with getTemp() instead with readTemp() |
| 76 | +} |
| 77 | +//--------------------------------------------------------------- |
| 78 | +void printInfo() |
| 79 | +{ |
| 80 | +//This function prints the weather data out to the default Serial Port |
| 81 | + |
| 82 | + Serial.print("Temp:"); |
| 83 | + Serial.print(tempf); |
| 84 | + Serial.print("F, "); |
| 85 | + |
| 86 | + Serial.print("Humidity:"); |
| 87 | + Serial.print(humidity); |
| 88 | + Serial.println("%"); |
| 89 | +} |
0 commit comments