initial upload

This commit is contained in:
Harald Pichler 2015-11-29 22:34:24 +01:00
parent ba9d4ed578
commit c493bc6618
28 changed files with 3146 additions and 0 deletions

View file

@ -0,0 +1,100 @@
/***************************************************
This is a library for the HTU21DF Humidity & Temp Sensor
Designed specifically to work with the HTU21DF sensor from Adafruit
----> https://www.adafruit.com/products/1899
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
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include "Adafruit_HTU21DF.h"
#if defined(__AVR__)
#include <util/delay.h>
#endif
Adafruit_HTU21DF::Adafruit_HTU21DF() {
}
boolean Adafruit_HTU21DF::begin(void) {
Wire.begin();
reset();
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READREG);
Wire.endTransmission();
Wire.requestFrom(HTU21DF_I2CADDR, 1);
return (Wire.read() == 0x2); // after reset should be 0x2
}
void Adafruit_HTU21DF::reset(void) {
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_RESET);
Wire.endTransmission();
delay(15);
}
float Adafruit_HTU21DF::readTemperature(void) {
// OK lets ready!
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READTEMP);
Wire.endTransmission();
delay(50); // add delay between request and actual read!
Wire.requestFrom(HTU21DF_I2CADDR, 3);
while (!Wire.available()) {}
uint16_t t = Wire.read();
t <<= 8;
t |= Wire.read();
uint8_t crc = Wire.read();
float temp = t;
temp *= 175.72;
temp /= 65536;
temp -= 46.85;
return temp;
}
float Adafruit_HTU21DF::readHumidity(void) {
// OK lets ready!
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READHUM);
Wire.endTransmission();
delay(50); // add delay between request and actual read!
Wire.requestFrom(HTU21DF_I2CADDR, 3);
while (!Wire.available()) {}
uint16_t h = Wire.read();
h <<= 8;
h |= Wire.read();
uint8_t crc = Wire.read();
float hum = h;
hum *= 125;
hum /= 65536;
hum -= 6;
return hum;
}
/*********************************************************************/

View file

@ -0,0 +1,44 @@
/***************************************************
This is a library for the HTU21D-F Humidity & Temp Sensor
Designed specifically to work with the HTU21D-F sensor from Adafruit
----> https://www.adafruit.com/products/1899
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
products from Adafruit!
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
#include "WProgram.h"
#endif
#include "Wire.h"
#define HTU21DF_I2CADDR 0x40
#define HTU21DF_READTEMP 0xE3
#define HTU21DF_READHUM 0xE5
#define HTU21DF_WRITEREG 0xE6
#define HTU21DF_READREG 0xE7
#define HTU21DF_RESET 0xFE
class Adafruit_HTU21DF {
public:
Adafruit_HTU21DF();
boolean begin(void);
float readTemperature(void);
float readHumidity(void);
void reset(void);
private:
boolean readData(void);
float humidity, temp;
};

View file

@ -0,0 +1,24 @@
This is a library for the HTU21D-F Humidity + Temp sensor
Designed specifically to work with the HTU21D-F in the Adafruit shop
----> https://www.adafruit.com/products/1899
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
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
Check out the links above for our tutorials and wiring diagrams
To download. click the ZIP button in the top-middle navbar,
rename the uncompressed folder Adafruit_HTU21DF.
Check that the Adafruit_HTU21DF folder contains Adafruit_HTU21DF.cpp and Adafruit_HTU21DF.h
Place the Adafruit_HTU21DF library folder your arduinosketchfolder/libraries/ folder.
You may need to create the libraries subfolder if its your first library. Restart the IDE.
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

View file

@ -0,0 +1,36 @@
/***************************************************
This is an example for the HTU21D-F Humidity & Temp Sensor
Designed specifically to work with the HTU21D-F sensor from Adafruit
----> https://www.adafruit.com/products/1899
These displays use I2C to communicate, 2 pins are required to
interface
****************************************************/
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
// Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
void setup() {
Serial.begin(9600);
Serial.println("HTU21D-F test");
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
}
void loop() {
Serial.print("Temp: "); Serial.print(htu.readTemperature());
Serial.print("\t\tHum: "); Serial.println(htu.readHumidity());
delay(500);
}

View file

@ -0,0 +1,9 @@
name=Adafruit HTU21DF Library
version=1.0.0
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the HTU21D-F sensors in the Adafruit shop
paragraph=Arduino library for the HTU21D-F sensors in the Adafruit shop
category=Sensors
url=https://github.com/adafruit/Adafruit_HTU21DF_Library
architectures=*