Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable compile for all platforms #1

Merged
merged 1 commit into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 15 additions & 22 deletions firmware/Adafruit_AM2315.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/***************************************************
/***************************************************
This is a library for the AM2315 Humidity & Temp Sensor

Designed specifically to work with the AM2315 sensor from Adafruit
----> https://www.adafruit.com/products/1293

These displays use I2C to communicate, 2 pins are required to
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

Expand All @@ -19,28 +19,21 @@
#include <util/delay.h>
#endif

#if (PLATFORM_ID == 6)
#define PHOTON
#endif

#ifdef PHOTON
#include "application.h"
#endif

Adafruit_AM2315::Adafruit_AM2315() {
}


bool Adafruit_AM2315::begin(void) {
Wire.begin();

// try to read data, as a test
return readData();
}

bool Adafruit_AM2315::readData(void) {
uint8_t reply[10];

// Wake up the sensor
Wire.beginTransmission(AM2315_I2CADDR);
delay(2);
Expand All @@ -52,18 +45,18 @@ bool Adafruit_AM2315::readData(void) {
Wire.write(0x00); // start at address 0x0
Wire.write(4); // request 4 bytes data
Wire.endTransmission();

delay(10); // add delay between request and actual read!

Wire.requestFrom(AM2315_I2CADDR, 8);
for (uint8_t i=0; i<8; i++) {
reply[i] = Wire.read();
//Serial.println(reply[i], HEX);
}

if (reply[0] != AM2315_READREG) return false;
if (reply[1] != 4) return false; // bytes req'd

humidity = reply[2];
humidity *= 256;
humidity += reply[3];
Expand Down Expand Up @@ -95,19 +88,19 @@ float Adafruit_AM2315::readHumidity(void) {


/*
* This method returns both temperature and humidity in a single call and using a single I2C request.
* This method returns both temperature and humidity in a single call and using a single I2C request.
*
* If you want to obtain both temperature and humidity when you sample the sensor, be aware that calling
* readTemperature() and readHumidity() in rapid succession may swamp the sensor and result in invalid
* If you want to obtain both temperature and humidity when you sample the sensor, be aware that calling
* readTemperature() and readHumidity() in rapid succession may swamp the sensor and result in invalid
* readingings (the AM2315 manual advisess that continuous samples must be at least 2 seconds apart).
* Calling this method avoids the double I2C request.
*/
bool Adafruit_AM2315::readTemperatureAndHumidity(float &t, float &h) {
if (!readData()) return false;

t = temp;
h = humidity;

return true;
}

Expand Down
20 changes: 12 additions & 8 deletions firmware/Adafruit_AM2315.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
/***************************************************
/***************************************************
This is a library for the AM2315 Humidity Pressure & Temp Sensor

Designed specifically to work with the AM2315 sensor from Adafruit
----> https://www.adafruit.com/products/1293

These displays use I2C to communicate, 2 pins are required to
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#else
//#include "WProgram.h"
#endif

#ifdef PARTICLE
#include "application.h"
#endif


#define AM2315_I2CADDR 0x5C
#define AM2315_READREG 0x03

Expand All @@ -30,9 +35,8 @@ class Adafruit_AM2315 {
float readTemperature(void);
float readHumidity(void);
bool readTemperatureAndHumidity(float&, float&);

private:
bool readData(void);
float humidity, temp;
};

4 changes: 2 additions & 2 deletions spark.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "Adafruit_AM2315",
"author": "Limor Fried/Ladyada",
"license": "BSD",
"version": "1.0.0",
"version": "1.0.1",
"description": "Advanced Looping library with timeouts and stuff"
}
}