-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 885e0fc
Showing
11 changed files
with
382 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
cmake-build-debug | ||
build | ||
deps | ||
_config.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2017 Brad Smith, [email protected], https://github.com/pedalPusher68 | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=Adafruit HTU21DF Library | ||
version=1.0.1 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
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=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
let Adafruit_HTU21DF = { | ||
|
||
_create: ffi('void *mgos_htu21df_create()'), | ||
_begin: ffi('int mgos_htu21df_begin(void *)'), | ||
_rdTp: ffi('double mgos_htu21df_readTemperature(void *)'), | ||
_rdHm: ffi('double mgos_htu21df_readHumidity(void *)'), | ||
_rst: ffi('void mgos_htu21df_reset(void *)'), | ||
|
||
_proto: { | ||
|
||
// functions | ||
begin: function () { | ||
return Adafruit_HTU21DF._begin(this.tsl); | ||
}, | ||
|
||
readTemperature: function () { | ||
return Adafruit_HTU21DF._rdTp(this.tsl); | ||
}, | ||
|
||
readHumidity: function () { | ||
return Adafruit_HTU21DF._rdHm(this.tsl); | ||
}, | ||
|
||
reset: function () { | ||
Adafruit_HTU21DF._rst(this.tsl); | ||
} | ||
|
||
}, | ||
|
||
create: function () { | ||
let obj = Object.create(Adafruit_HTU21DF._proto); | ||
// set default parameter values | ||
// Initialize Adafruit_HTU21DF library. | ||
// Return value: handle opaque pointer. | ||
obj.tsl = Adafruit_HTU21DF._create(); | ||
return obj; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
author: pedalPusher68 | ||
type: lib | ||
description: Arduino Adafruit HTU21D-F library converted for Mongoose OS | ||
version: 1.0 | ||
|
||
sources: | ||
- src | ||
|
||
includes: | ||
- src | ||
|
||
filesystem: | ||
- fs | ||
|
||
config_schema: | ||
|
||
libs: | ||
- origin: https://github.com/mongoose-os-libs/arduino-compat | ||
- origin: https://github.com/mongoose-os-libs/arduino-wire | ||
tags: | ||
- c | ||
- js | ||
- arduino | ||
- htu21d | ||
- HTU21D | ||
- htu21d-f | ||
- HTU21D-F | ||
- htu21d(f) | ||
- HTU21D(F) | ||
- i2c | ||
- sensor | ||
|
||
manifest_version: 2017-09-29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*************************************************** | ||
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; | ||
} | ||
|
||
|
||
|
||
/*********************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*************************************************** | ||
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 | ||
****************************************************/ | ||
|
||
#ifndef _ADAFRUIT_HTU21DF_H | ||
#define _ADAFRUIT_HTU21DF_H | ||
|
||
#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; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Created by Bradley Smith on 11/23/17. | ||
// | ||
#include "mgos_arduino_adafruit_htu21df.h" | ||
|
||
Adafruit_HTU21DF *mgos_htu21df_create() { | ||
return new Adafruit_HTU21DF(); | ||
} | ||
|
||
int mgos_htu21df_begin(Adafruit_HTU21DF *htu) { | ||
if (htu == nullptr) return 0; | ||
boolean r = htu->begin(); | ||
return (r) ? 1 : 0; | ||
} | ||
|
||
double mgos_htu21df_readTemperature(Adafruit_HTU21DF *htu) { | ||
double r = -999; | ||
if (htu != nullptr) { | ||
r = (double) htu->readTemperature(); | ||
} | ||
return r; | ||
} | ||
|
||
double mgos_htu21df_readHumidity(Adafruit_HTU21DF *htu) { | ||
double r = -999; | ||
if (htu != nullptr) { | ||
r = (double) htu->readHumidity(); | ||
} | ||
return r; | ||
|
||
} | ||
|
||
void mgos_htu21df_reset(Adafruit_HTU21DF *htu) { | ||
if (htu != nullptr) { | ||
htu->reset(); | ||
} | ||
} | ||
|
||
|
||
//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; | ||
//}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Created by Bradley Smith on 11/23/17. | ||
// | ||
|
||
#ifndef ARDUINO_ADAFRUIT_HTUD1DF_MGOS_ARDUINO_ADAFRUIT_HTU21D_C_H | ||
#define ARDUINO_ADAFRUIT_HTUD1DF_MGOS_ARDUINO_ADAFRUIT_HTU21D_C_H | ||
|
||
#include "Adafruit_HTU21DF.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
|
||
Adafruit_HTU21DF *mgos_htu21df_create(); | ||
|
||
int mgos_htu21df_begin(Adafruit_HTU21DF *htu); | ||
|
||
double mgos_htu21df_readTemperature(Adafruit_HTU21DF *htu); | ||
|
||
double mgos_htu21df_readHumidity(Adafruit_HTU21DF *htu); | ||
|
||
void mgos_htu21df_reset(Adafruit_HTU21DF *htu); | ||
|
||
|
||
//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; | ||
//}; | ||
|
||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //ARDUINO_ADAFRUIT_HTUD1DF_MGOS_ARDUINO_ADAFRUIT_HTU21D_C_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// Created by Bradley Smith on 11/23/17. | ||
// | ||
#include <stdbool.h> | ||
|
||
bool mgos_arduino_adafruit_htu21df_init(void) { | ||
return true; | ||
} |