This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:sut:stm32:emb4_1 [2024/04/22 20:41] – [Steps] ktokarz | en:iot-open:practical:hardware:sut:stm32:emb4_1 [2024/04/22 20:56] (current) – [Result validation] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== STM_4: 1-Wire Temperature Sensor ===== | ||
| + | The temperature-only sensor **DS18B20** uses a 1-wire protocol. " | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | To handle operations with **DS18B20**, | ||
| + | <code ini> | ||
| + | lib_deps = 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: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Suggested Readings and Knowledge Resources ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Hands-on Lab Scenario ===== | ||
| + | In this scenario, we present how to interface the 1-wire sensor, DS18B20 (temperature sensor). | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | Read the temperature from the sensor and present it on the display of your choice. Show the reading in Celsius degrees. Note that the scenario below presents only how to use the DS18B20 sensor. How to display the data is present in other scenarios, as listed above. We suggest using an LCD (scenario [[en: | ||
| + | |||
| + | Update reading every 10s. Too frequent readings may cause incorrect readings or faulty communication with the sensor. Remember, the remote video channel has its limits, even if the sensor can be read much more frequently. | ||
| + | |||
| + | ==== Start ==== | ||
| + | Check if your display of choice is visible in the FOV of the camera once the device is booked. | ||
| + | |||
| + | ==== Steps ==== | ||
| + | The steps below present only interaction with the sensor. Those steps should be supplied to present the data (or send it over the network) using other scenarios accordingly. | ||
| + | |||
| + | === Step 1 === | ||
| + | Include Dallas sensor library and 1-Wire protocol implementation library: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | <note important> | ||
| + | |||
| + | === Step 2 === | ||
| + | Declare the 1-Wire GPIO bus pin, 1-Wire communication handling object, sensor proxy and a variable to store readings: | ||
| + | <code c> | ||
| + | #define ONE_WIRE_BUS D0 | ||
| + | static OneWire oneWire(ONE_WIRE_BUS); | ||
| + | static DallasTemperature sensors(& | ||
| + | static float tempDS; | ||
| + | </ | ||
| + | < | ||
| + | |||
| + | === Step 3 === | ||
| + | Initialise sensors' | ||
| + | <code c> | ||
| + | sensors.begin(); | ||
| + | </ | ||
| + | |||
| + | === Step 4 === | ||
| + | Read the data: | ||
| + | <code c> | ||
| + | sensors.requestTemperatures(); | ||
| + | if (sensors.getDeviceCount()> | ||
| + | { | ||
| + | tempDS = sensors.getTempCByIndex(0); | ||
| + | } | ||
| + | </ | ||
| + | Remember not to read the sensor too frequently. 10s between consecutive readings is just fine.\\ | ||
| + | Devices in the 1-Wire bus are addressable either by index (as in the example above) or by their address.\\ | ||
| + | Some useful functions are present below: | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | |||
| + | ==== 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. | ||
| + | |||
| + | ===== 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> | ||
| + | ===== Project information ===== | ||
| + | {{: | ||
| + | This Intellectual Output was implemented under the Erasmus+ KA2.\\ | ||
| + | Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, | ||
| + | Project number: 2022-1-PL01-KA220-HED-000085090. | ||
| + | |||
| + | **__Erasmus+ Disclaimer__**\\ | ||
| + | This project has been funded with support from the European Commission. \\ | ||
| + | This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein. | ||
| + | |||
| + | **__Copyright Notice__**\\ | ||
| + | This content was created by the IOT-OPEN.EU Reloaded consortium, 2022, | ||
| + | The content is Copyrighted and distributed under CC BY-NC [[https:// | ||
| + | <figure label> | ||
| + | {{: | ||
| + | </ | ||
| + | </ | ||
| + | |||