Skip to content

Commit 773a73a

Browse files
authored
Merge pull request #2 from cparata/master
Final PR with source code for Discovery IoT Node and X-NUCLEO boards
2 parents c07bfd5 + b645af3 commit 773a73a

10 files changed

Lines changed: 2289 additions & 0 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# HTS221
22
Arduino library to support the HTS221 capacitive digital sensor for relative humidity and temperature
3+
4+
## API
5+
6+
This sensor uses I2C to communicate. It is then required to create a TwoWire interface before accessing to the sensors:
7+
8+
dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL);
9+
dev_i2c->begin();
10+
11+
An instance can be created and enbaled following the procedure below:
12+
13+
For the humidity sensor:
14+
15+
HumTemp = new HTS221Sensor (dev_i2c);
16+
HumTemp->Enable();
17+
18+
The access to the sensor values is done as explained below:
19+
20+
Read humidity and temperature.
21+
22+
HumTemp->GetHumidity(&humidity);
23+
HumTemp->GetTemperature(&temperature);
24+
25+
## Documentation
26+
27+
You can find the source files at
28+
https://github.com/stm32duino/HTS221
29+
30+
The HTS221 datasheet is available at
31+
http://www.st.com/content/st_com/en/products/mems-and-sensors/humidity-sensors/hts221.html
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
******************************************************************************
3+
* @file DISCO_IOT_HTS221_DataLog_Terminal.ino
4+
* @author WI6LABS from AST
5+
* @version V1.0.0
6+
* @date 7 September 2017
7+
* @brief Arduino test application for the STMicrolectronics STM32 DISCO_IOT
8+
* MEMS Inertial and Environmental sensor expansion board.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
41+
42+
// Includes.
43+
#include <HTS221Sensor.h>
44+
45+
#define I2C2_SCL D33
46+
#define I2C2_SDA D34
47+
48+
// Components.
49+
HTS221Sensor *HumTemp;
50+
TwoWire *dev_i2c;
51+
52+
void setup() {
53+
// Led.
54+
pinMode(LED_BUILTIN, OUTPUT);
55+
// Initialize serial for output.
56+
Serial.begin(9600);
57+
58+
// Initialize I2C bus.
59+
dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL);
60+
dev_i2c->begin();
61+
62+
// Initlialize components.
63+
HumTemp = new HTS221Sensor (dev_i2c);
64+
HumTemp->Enable();
65+
}
66+
67+
void loop() {
68+
// Led blinking.
69+
digitalWrite(LED_BUILTIN, HIGH);
70+
delay(250);
71+
digitalWrite(LED_BUILTIN, LOW);
72+
delay(250);
73+
74+
// Read humidity and temperature.
75+
float humidity, temperature;
76+
HumTemp->GetHumidity(&humidity);
77+
HumTemp->GetTemperature(&temperature);
78+
79+
// Output data.
80+
Serial.print("Hum[%]: ");
81+
Serial.print(humidity, 2);
82+
Serial.print(" | Temp[C]: ");
83+
Serial.println(temperature, 2);
84+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
******************************************************************************
3+
* @file X_NUCLEO_IKS01A1_HTS221_DataLog_Terminal.ino
4+
* @author AST
5+
* @version V1.0.0
6+
* @date 7 September 2017
7+
* @brief Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A1
8+
* MEMS Inertial and Environmental sensor expansion board.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
41+
42+
// Includes.
43+
#include <HTS221Sensor.h>
44+
45+
#if defined(ARDUINO_SAM_DUE)
46+
#define DEV_I2C Wire1 //Define which I2C bus is used. Wire1 for the Arduino Due
47+
#define SerialPort Serial
48+
#else
49+
#define DEV_I2C Wire //Or Wire
50+
#define SerialPort Serial
51+
#endif
52+
53+
// Components.
54+
HTS221Sensor *HumTemp;
55+
56+
void setup() {
57+
// Led.
58+
pinMode(13, OUTPUT);
59+
60+
// Initialize serial for output.
61+
SerialPort.begin(9600);
62+
63+
// Initialize I2C bus.
64+
DEV_I2C.begin();
65+
66+
// Initlialize components.
67+
HumTemp = new HTS221Sensor (&DEV_I2C);
68+
HumTemp->Enable();
69+
}
70+
71+
void loop() {
72+
// Led blinking.
73+
digitalWrite(13, HIGH);
74+
delay(250);
75+
digitalWrite(13, LOW);
76+
delay(250);
77+
78+
// Read humidity and temperature.
79+
float humidity, temperature;
80+
HumTemp->GetHumidity(&humidity);
81+
HumTemp->GetTemperature(&temperature);
82+
83+
// Output data.
84+
SerialPort.print("| Hum[%]: ");
85+
SerialPort.print(humidity, 2);
86+
SerialPort.print(" | Temp[C]: ");
87+
SerialPort.print(temperature, 2);
88+
SerialPort.println(" |");
89+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
******************************************************************************
3+
* @file X_NUCLEO_IKS01A2_HTS221_DataLog_Terminal.ino
4+
* @author AST
5+
* @version V1.0.0
6+
* @date 7 September 2017
7+
* @brief Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A2
8+
* MEMS Inertial and Environmental sensor expansion board.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
41+
42+
// Includes.
43+
#include <HTS221Sensor.h>
44+
45+
#if defined(ARDUINO_SAM_DUE)
46+
#define DEV_I2C Wire1 //Define which I2C bus is used. Wire1 for the Arduino Due
47+
#define SerialPort Serial
48+
#else
49+
#define DEV_I2C Wire //Or Wire
50+
#define SerialPort Serial
51+
#endif
52+
53+
// Components.
54+
HTS221Sensor *HumTemp;
55+
56+
void setup() {
57+
// Led.
58+
pinMode(13, OUTPUT);
59+
60+
// Initialize serial for output.
61+
SerialPort.begin(9600);
62+
63+
// Initialize I2C bus.
64+
DEV_I2C.begin();
65+
66+
// Initlialize components.
67+
HumTemp = new HTS221Sensor (&DEV_I2C);
68+
HumTemp->Enable();
69+
}
70+
71+
void loop() {
72+
// Led blinking.
73+
digitalWrite(13, HIGH);
74+
delay(250);
75+
digitalWrite(13, LOW);
76+
delay(250);
77+
78+
// Read humidity and temperature.
79+
float humidity, temperature;
80+
HumTemp->GetHumidity(&humidity);
81+
HumTemp->GetTemperature(&temperature);
82+
83+
// Output data.
84+
SerialPort.print("| Hum[%]: ");
85+
SerialPort.print(humidity, 2);
86+
SerialPort.print(" | Temp[C]: ");
87+
SerialPort.print(temperature, 2);
88+
SerialPort.println(" |");
89+
}

keywords.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#######################################
2+
# Syntax Coloring Map For HTS221
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
HTS221Sensor KEYWORD1 HTS221Sensor
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
Enable KEYWORD2
16+
Disable KEYWORD2
17+
ReadID KEYWORD2
18+
Reset KEYWORD2
19+
GetHumidity KEYWORD2
20+
GetTemperature KEYWORD2
21+
GetODR KEYWORD2
22+
SetODR KEYWORD2
23+
ReadReg KEYWORD2
24+
WriteReg KEYWORD2
25+
IO_Read KEYWORD2
26+
IO_Write KEYWORD2
27+
28+
#######################################
29+
# Constants (LITERAL1)
30+
#######################################

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=HTS221
2+
version=1.0
3+
author=AST, Wi6Labs
4+
maintainer=stm32duino
5+
sentence=Capacitive digital sensor for relative humidity and temperature.
6+
paragraph=This library provides Arduino support for the capacitive digital sensor for relative humidity and temperature HTS221 for STM32 boards.
7+
category=Sensors
8+
url=https://github.com/stm32duino/HTS221
9+
architectures=stm32

0 commit comments

Comments
 (0)