Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: sensor: hs300x: Add HS300x sample application
This simple application periodically prints the temperature and humidity measured by either the HS3001 or HS3003 sensors. Signed-off-by: Ian Morris <ian.d.morris@outlook.com>
- Loading branch information
1 parent
dff5558
commit e9aa919
Showing
6 changed files
with
153 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,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(hs300x) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
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,65 @@ | ||
.. _hs300x_sample: | ||
|
||
HS300X Sample | ||
############# | ||
|
||
Description | ||
*********** | ||
|
||
This sample application periodically takes temperature and humidity readings | ||
using the renesas_hs300x sensor driver. The result is written to the console. | ||
The HS3001 and HS3003 sensors are supported by the same application and driver. | ||
|
||
Requirements | ||
************ | ||
|
||
This sample needs a Renesas HS3001 or HS3003 sensor connected to the target | ||
board's I2C connector. | ||
|
||
Wiring | ||
****** | ||
|
||
This sample has been tested with Nucleo STM32F401RE board. A click shield for | ||
NUCLEO-64 was used to connect TEMP&HUM 17 click and TEMP&HUM 18 click boards to | ||
the STM32F401RE board. | ||
|
||
The sensor operates at 3.3V and uses I2C to communicate with the board. | ||
|
||
External Wires: | ||
|
||
* Breakout **GND** pin <--> Nucleo **GND** pin | ||
* Breakout **VCC** pin <--> Nucleo **3V3** pin | ||
* Breakout **SDA** pin <--> Nucleo **CN5-D14** pin | ||
* Breakout **SCL** pin <--> Nucleo **CN5-D15** pin | ||
|
||
Building and Running | ||
******************** | ||
|
||
In order to build the sample, connect the board to the computer with a USB cable | ||
and enter the following commands: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/sensor/hs300x | ||
:board: nucleo_f401re | ||
:goals: build flash | ||
:compact: | ||
|
||
Sample Output | ||
************* | ||
The output can be seen via a terminal emulator (e.g. minicom). Connect the board | ||
with a USB cable to the computer and open /dev/ttyACM0 with the below serial | ||
settings: | ||
|
||
* Baudrate: 115200 | ||
* Parity: None | ||
* Data: 8 | ||
* Stop bits: 1 | ||
|
||
The output should look like this: | ||
|
||
.. code-block:: console | ||
Device HS300x - 0x200010a8 is ready | ||
temp is 26.70 oC | ||
hum is 50.71 %RH | ||
... |
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,14 @@ | ||
/* | ||
* Copyright (c) 2023 Ian Morris | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&i2c1 { | ||
renesas_hs300x: renesas_hs300x@44 { | ||
compatible = "renesas,hs300x"; | ||
reg = <0x44>; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
}; | ||
}; |
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,4 @@ | ||
CONFIG_STDOUT_CONSOLE=y | ||
CONFIG_I2C=y | ||
CONFIG_SENSOR=y | ||
CONFIG_SENSOR_INIT_PRIORITY=90 |
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,21 @@ | ||
# | ||
# Copyright (c) 2023 Ian Morris | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
sample: | ||
name: Renesas HS300x Sensor Sample | ||
tests: | ||
sample.sensor.hs300x: | ||
harness: console | ||
platform_allow: nucleo_f401re | ||
integration_platforms: | ||
- nucleo_f401re | ||
tags: sensors | ||
depends_on: i2c | ||
harness_config: | ||
type: multi_line | ||
regex: | ||
- "temp is (.*) oC" | ||
- "hum is (.*) %RH" | ||
fixture: fixture_i2c_hs300x |
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,41 @@ | ||
/* | ||
* Copyright (c) 2023 Ian Morris | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/sensor.h> | ||
#include <zephyr/sys/printk.h> | ||
#include <zephyr/sys/__assert.h> | ||
|
||
#define HS300X_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(renesas_hs300x) | ||
|
||
int main(void) | ||
{ | ||
const struct device *const dev = DEVICE_DT_GET(HS300X_NODE); | ||
struct sensor_value temp, hum; | ||
int ret; | ||
|
||
__ASSERT(device_is_ready(dev), "HS300x device not ready"); | ||
|
||
printk("Device %s - %p is ready\n", dev->name, dev); | ||
|
||
while (1) { | ||
ret = sensor_sample_fetch(dev); | ||
if (ret) { | ||
printk("Failed to fetch measurements (%d)\n", ret); | ||
return 0; | ||
} | ||
|
||
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp); | ||
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &hum); | ||
|
||
printk("temp is %d.%d oC\n", temp.val1, temp.val2); | ||
printk("hum is %d.%d %%RH\n", hum.val1, hum.val2); | ||
|
||
k_sleep(K_MSEC(1000)); | ||
} | ||
return 0; | ||
} |