samples: sensor: thermometer: update sample
Update thermometer sample with mcp970x temperature sensor. Removing test with frdm_k64f integration platform as it doesn't provide an ambient temperature sensor. Removing the bbc_microbit board as it only seems to provide the die temperature of the nRF51 SoC and not an ambient temperature sensor. Signed-off-by: Nick Ward <nix.ward@gmail.com>
This commit is contained in:
parent
162c47ffc4
commit
51597cbc82
4 changed files with 78 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
.. _thermometer-samples:
|
||||
.. _thermometer-sample:
|
||||
|
||||
Thermometer sample
|
||||
##################
|
||||
|
@ -6,26 +6,50 @@ Thermometer sample
|
|||
Overview
|
||||
********
|
||||
|
||||
A simple thermometer example, which writes the temperature to the console once per second.
|
||||
This sample application periodically measures the ambient temperature
|
||||
at 1Hz. The result is written to the console.
|
||||
|
||||
Wiring
|
||||
*******
|
||||
|
||||
VDD pin should be connected to 2.3V to 5.5V
|
||||
GND pin connected to 0V
|
||||
VOUT pin connected to the ADC input pin.
|
||||
|
||||
.. _`MCP970X Sensor`: http://ww1.microchip.com/downloads/en/devicedoc/20001942g.pdf
|
||||
|
||||
An overlay is provided for the nrf52840dk_nrf52840 board with the
|
||||
sensor connected to pin AIN7.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
It can be built and executed on bbc_microbit as follows:
|
||||
To build for the nrf52840dk_nrf52840 board use:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/sensor/thermometer
|
||||
:board: bbc_microbit
|
||||
:goals: build
|
||||
:board: nrf52840dk_nrf52840
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
|
||||
To build for other boards and ambient temperature sensors, enable the sensor
|
||||
node that supports ``SENSOR_CHAN_AMBIENT_TEMP`` and use an overlay to create an
|
||||
alias named ``ambient-temp0`` to link to the node. See the overlay used for the
|
||||
``nrf52840dk_nrf52840`` board within this sample:
|
||||
``boards/nrf52840dk_nrf52840.overlay``
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
Thermometer Example!
|
||||
arm temp device is 0x20000184, name is TEMP_0
|
||||
Temperature is 29.5C
|
||||
Temperature is 29.5C
|
||||
Temperature is 29.5C
|
||||
*** Booting Zephyr OS build zephyr-v3.3.0-1205-g118f73e12a70 ***
|
||||
Thermometer Example (arm)
|
||||
Temperature device is 0x6150, name is mcp9700a
|
||||
Temperature is 24.0°C
|
||||
Temperature is 24.1°C
|
||||
Temperature is 24.2°C
|
||||
Temperature is 24.1°C
|
||||
Temperature is 24.0°C
|
||||
Temperature is 24.1°C
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/ {
|
||||
mcp9700a: mcp9700a {
|
||||
status = "okay";
|
||||
compatible = "microchip,mcp970x";
|
||||
family = "MCP9700/9700A";
|
||||
io-channels = <&adc 7>;
|
||||
};
|
||||
|
||||
aliases {
|
||||
ambient-temp0 = &mcp9700a;
|
||||
};
|
||||
};
|
||||
|
||||
&adc {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
channel@7 {
|
||||
reg = <7>;
|
||||
zephyr,gain = "ADC_GAIN_1_3";
|
||||
zephyr,reference = "ADC_REF_INTERNAL";
|
||||
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS,10)>;
|
||||
zephyr,input-positive = <NRF_SAADC_AIN7>;
|
||||
zephyr,resolution = <12>; /* 0.055C per ADC step */
|
||||
zephyr,oversampling = <2>; /* x4 */
|
||||
};
|
||||
};
|
|
@ -5,4 +5,5 @@ tests:
|
|||
tags: sensors
|
||||
harness: sensor
|
||||
integration_platforms:
|
||||
- frdm_k64f
|
||||
- nrf52840dk_nrf52840
|
||||
platform_allow: nrf52840dk_nrf52840
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2016 ARM Ltd.
|
||||
* Copyright (c) 2023 FTP Technologies
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -10,38 +11,33 @@
|
|||
|
||||
void main(void)
|
||||
{
|
||||
const struct device *temp_dev;
|
||||
const struct device *const dev = DEVICE_DT_GET(DT_ALIAS(ambient_temp0));
|
||||
struct sensor_value value;
|
||||
int ret;
|
||||
|
||||
printf("Thermometer Example! %s\n", CONFIG_ARCH);
|
||||
printf("Thermometer Example (%s)\n", CONFIG_ARCH);
|
||||
|
||||
temp_dev = device_get_binding("TEMP_0");
|
||||
if (!temp_dev) {
|
||||
printf("error: no temp device\n");
|
||||
if (!device_is_ready(dev)) {
|
||||
printf("Device %s is not ready\n", dev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("temp device is %p, name is %s\n",
|
||||
temp_dev, temp_dev->name);
|
||||
printf("Temperature device is %p, name is %s\n", dev, dev->name);
|
||||
|
||||
while (1) {
|
||||
int r;
|
||||
struct sensor_value temp_value;
|
||||
|
||||
r = sensor_sample_fetch(temp_dev);
|
||||
if (r) {
|
||||
printf("sensor_sample_fetch failed return: %d\n", r);
|
||||
ret = sensor_sample_fetch(dev);
|
||||
if (ret != 0) {
|
||||
printf("Sensor fetch failed: %d\n", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
r = sensor_channel_get(temp_dev, SENSOR_CHAN_AMBIENT_TEMP,
|
||||
&temp_value);
|
||||
if (r) {
|
||||
printf("sensor_channel_get failed return: %d\n", r);
|
||||
ret = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &value);
|
||||
if (ret != 0) {
|
||||
printf("Sensor get failed: %d\n", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Temperature is %gC\n",
|
||||
sensor_value_to_double(&temp_value));
|
||||
printf("Temperature is %0.1lf°C\n", sensor_value_to_double(&value));
|
||||
|
||||
k_sleep(K_MSEC(1000));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue