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:esp32:emb4_1 [2024/03/21 19:58] – [Prerequisites] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb4_1 [2024/04/22 17:55] (current) – ToDo checked: check if you don't need to call sensors.requestTemperatures(); before the code below ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <todo @pczekalski> | ||
====== EMB4: 1-Wire Temperature Sensor ===== | ====== EMB4: 1-Wire Temperature Sensor ===== | ||
The temperature-only sensor **DS18B20** uses a 1-wire protocol. " | The temperature-only sensor **DS18B20** uses a 1-wire protocol. " | ||
Line 24: | Line 23: | ||
===== Hands-on Lab Scenario ===== | ===== Hands-on Lab Scenario ===== | ||
+ | In this scenario, we present how to interface the 1-wire sensor, DS18B20 (temperature sensor). | ||
==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
- | //Describe a task to be implemented by the scenario | + | Read the temperature from the sensor and present it on the display of your choice. Show the reading in C. 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 |
+ | |||
+ | 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 ==== | ==== Start ==== | ||
- | //Write starting conditions, i.e. what to do in the beginning, what to pay attention to before beginning, how the mechanical part should look, etc.// Include needed compiler configuration, | + | Check if your display of choice is visible |
==== Steps ==== | ==== Steps ==== | ||
- | // Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph | + | 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 === | === Step 1 === | ||
- | //Describe activities done in Step 1.// | + | Include Dallas sensor library and 1-Wire protocol implementation library: |
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | </code> | ||
+ | <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 6 | ||
+ | static OneWire oneWire(ONE_WIRE_BUS); | ||
+ | static DallasTemperature sensors(& | ||
+ | static float tempDS; | ||
+ | </code> | ||
+ | < | ||
- | ... | + | === Step 3 === |
+ | Initialise sensors' | ||
+ | <code c> | ||
+ | sensors.begin(); | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Step 4 === | ||
+ | <todo @pczekalski # | ||
+ | Read the data: | ||
+ | <code c> | ||
+ | if (sensors.getDeviceCount()> | ||
+ | { | ||
+ | tempDS = sensors.getTempCByIndex(0); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // Sensors not present (broken?) or 1-wire bus error | ||
+ | } | ||
+ | </ | ||
+ | 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: | ||
+ | * '' | ||
+ | * '' | ||
- | === Step n === | + | The library can make non-blocking calls, which can also be implemented using timers, as presented |
- | //Describe activities done in Step n.// | + | |
==== Result validation ==== | ==== Result validation ==== | ||
- | //Provide some result validation methods for self-assessment.// | + | 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 ===== | ||
- | This section is to be extended as new questions appear. \\ | ||
- | When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. | ||
- | //Provide some FAQs in the following form:\\ | ||
- | **Question? | ||
- | // | ||
+ | |||
+ | <WRAP noprint> | ||
===== Project information ===== | ===== Project information ===== | ||
{{: | {{: | ||
Line 67: | Line 101: | ||
{{: | {{: | ||
</ | </ | ||
+ | </ | ||