diff --git a/samples/sensor/hs300x/CMakeLists.txt b/samples/sensor/hs300x/CMakeLists.txt new file mode 100644 index 000000000000000..6f5eabb9d8cee21 --- /dev/null +++ b/samples/sensor/hs300x/CMakeLists.txt @@ -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}) diff --git a/samples/sensor/hs300x/README.rst b/samples/sensor/hs300x/README.rst new file mode 100644 index 000000000000000..345b0969a94dd37 --- /dev/null +++ b/samples/sensor/hs300x/README.rst @@ -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 + ... diff --git a/samples/sensor/hs300x/boards/nucleo_f401re.overlay b/samples/sensor/hs300x/boards/nucleo_f401re.overlay new file mode 100644 index 000000000000000..9223c61c6937014 --- /dev/null +++ b/samples/sensor/hs300x/boards/nucleo_f401re.overlay @@ -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>; + }; +}; diff --git a/samples/sensor/hs300x/prj.conf b/samples/sensor/hs300x/prj.conf new file mode 100644 index 000000000000000..4cea5f1b3e0b9b9 --- /dev/null +++ b/samples/sensor/hs300x/prj.conf @@ -0,0 +1,4 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_I2C=y +CONFIG_SENSOR=y +CONFIG_SENSOR_INIT_PRIORITY=90 diff --git a/samples/sensor/hs300x/sample.yaml b/samples/sensor/hs300x/sample.yaml new file mode 100644 index 000000000000000..77d06d05c7933d1 --- /dev/null +++ b/samples/sensor/hs300x/sample.yaml @@ -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 diff --git a/samples/sensor/hs300x/src/main.c b/samples/sensor/hs300x/src/main.c new file mode 100644 index 000000000000000..05bdc86fb61f1af --- /dev/null +++ b/samples/sensor/hs300x/src/main.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Ian Morris + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#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; +}