This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb4_1 [2024/04/22 17:38] – created ktokarz | en:iot-open:practical:hardware:sut:stm32:emb4_1 [2024/04/22 17:56] (current) – [Result validation] ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== STM_4: 1-Wire Temperature Sensor ===== | ====== STM_4: 1-Wire Temperature Sensor ===== | ||
- | The temperature-only sensor **DS18B20** uses a 1-wire protocol. " | + | The temperature-only sensor **DS18B20** uses a 1-wire protocol. " |
===== Prerequisites ===== | ===== Prerequisites ===== | ||
To handle operations with **DS18B20**, | To handle operations with **DS18B20**, | ||
<code ini> | <code ini> | ||
- | lib_deps = | + | lib_deps = milesburton/ |
- | milesburton/ | + | |
</ | </ | ||
Sensor readings can be sent over the network or presented on one of the node's displays (e.g. LCD), so understanding how to handle at least one of the displays is essential: | Sensor readings can be sent over the network or presented on one of the node's displays (e.g. LCD), so understanding how to handle at least one of the displays is essential: | ||
Line 39: | Line 38: | ||
#include < | #include < | ||
</ | </ | ||
- | <note important> | + | <note important> |
=== Step 2 === | === Step 2 === | ||
Declare the 1-Wire GPIO bus pin, 1-Wire communication handling object, sensor proxy and a variable to store readings: | Declare the 1-Wire GPIO bus pin, 1-Wire communication handling object, sensor proxy and a variable to store readings: | ||
<code c> | <code c> | ||
- | #define ONE_WIRE_BUS | + | #define ONE_WIRE_BUS |
static OneWire oneWire(ONE_WIRE_BUS); | static OneWire oneWire(ONE_WIRE_BUS); | ||
static DallasTemperature sensors(& | static DallasTemperature sensors(& | ||
Line 56: | Line 55: | ||
sensors.begin(); | sensors.begin(); | ||
</ | </ | ||
- | |||
=== Step 4 === | === Step 4 === | ||
Read the data: | Read the data: | ||
<code c> | <code c> | ||
+ | sensors.requestTemperatures(); | ||
if (sensors.getDeviceCount()> | if (sensors.getDeviceCount()> | ||
{ | { | ||
tempDS = sensors.getTempCByIndex(0); | tempDS = sensors.getTempCByIndex(0); | ||
- | } | ||
- | else | ||
- | { | ||
- | // Sensors not present (broken?) or 1-wire bus error | ||
} | } | ||
</ | </ | ||
Line 76: | Line 71: | ||
* '' | * '' | ||
- | The library can make non-blocking calls, which can also be implemented using timers, as presented in the scenario [[en: | ||
==== Result validation ==== | ==== Result validation ==== | ||
The observable temperature is usually within the range of 19-24C. If you find the temperature much higher, check your code, and if that is okay, please contact our administrator to inform us about the faulty AC. | The observable temperature is usually within the range of 19-24C. If you find the temperature much higher, check your code, and if that is okay, please contact our administrator to inform us about the faulty AC. | ||
+ | ===== FAQ ===== | ||
+ | **I've got constant readings of value 85.0. What to do?**: Check if GPIO is OK (should be D0), check if you initialised controller class and call the function '' | ||
<WRAP noprint> | <WRAP noprint> |