amc2020:group_n:ds18b20
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
amc2020:group_n:ds18b20 [2020/07/15 15:54] – jonas001 | amc2020:group_n:ds18b20 [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | < | ||
+ | < | ||
+ | <a href=" | ||
+ | <span style=" | ||
+ | ↩ Back to the main page | ||
+ | </ | ||
+ | </a> | ||
+ | </ | ||
+ | </ | ||
+ | |||
====== DS18B20 Waterproof Digital Temperature Sensor ====== | ====== DS18B20 Waterproof Digital Temperature Sensor ====== | ||
Line 11: | Line 21: | ||
It also features a variety of other possibilities such a powering the device through a pullup resistor connected to the Data line (parasite mode) or setting alarms for a high and a low temperature. | It also features a variety of other possibilities such a powering the device through a pullup resistor connected to the Data line (parasite mode) or setting alarms for a high and a low temperature. | ||
- | {{: | + | ^{{: |
- | **//Figure 1//** DS18B20 waterproof digital temperature sensor and pins. | + | |**//Figure 1//** DS18B20 waterproof digital temperature sensor and pins.| |
===== 2. Data Transmission and Working Principle of the Module ===== | ===== 2. Data Transmission and Working Principle of the Module ===== | ||
Line 33: | Line 43: | ||
The 64-bit ROM and the 1-Wire port are connected through the memory control logic to the scratchpad. The scratchpad is a high-speed internal memory that is used for storing small, often temporary, pieces of data which can be rapidly retrieved if needed. The scratchpad memory, which gets erased after powering down, is connected to the temperature sensor itself and stores its data in a 2-byte register. Furthermore, | The 64-bit ROM and the 1-Wire port are connected through the memory control logic to the scratchpad. The scratchpad is a high-speed internal memory that is used for storing small, often temporary, pieces of data which can be rapidly retrieved if needed. The scratchpad memory, which gets erased after powering down, is connected to the temperature sensor itself and stores its data in a 2-byte register. Furthermore, | ||
- | {{: | + | ^{{: |
- | **//Figure 2//** DS18B20 block diagram (Source: {{https:// | + | |**//Figure 2//** DS18B20 block diagram (Source: {{https:// |
==== 2.3 Temperature Register ==== | ==== 2.3 Temperature Register ==== | ||
Line 40: | Line 50: | ||
Normally the sensor is in an idle state after powering up. When the MCU issues a Convert T command, the sensor measures the temperature and does an analog to digital conversion and stores the result in the scratchpad 2-byte temperature register (figure 3) and the sensor goes back into idle state. | Normally the sensor is in an idle state after powering up. When the MCU issues a Convert T command, the sensor measures the temperature and does an analog to digital conversion and stores the result in the scratchpad 2-byte temperature register (figure 3) and the sensor goes back into idle state. | ||
- | {{: | + | ^{{: |
- | **//Figure 3//** Structure of the temperature register, LS = Least Significant, | + | |**//Figure 3//** Structure of the temperature register, LS = Least Significant, |
In the register, the 5 leading bits are representing the sign of the temperature. If the temperature is below 0°C, S = 1 and if it is above 0°C, S = 0. The other 11 bits represent the temperature indicated in figure 3, where bit 0, 1 and 2 can be undefined depending on the resolution stored in the configuration register: | In the register, the 5 leading bits are representing the sign of the temperature. If the temperature is below 0°C, S = 1 and if it is above 0°C, S = 0. The other 11 bits represent the temperature indicated in figure 3, where bit 0, 1 and 2 can be undefined depending on the resolution stored in the configuration register: | ||
Line 51: | Line 61: | ||
The maximum range of values that can be displayed is thus -127.9375 – 127.9375, which exceeds the range of the temperature sensor. Some examples of different temperatures displayed in 12-bit resolution can be seen in table 1. | The maximum range of values that can be displayed is thus -127.9375 – 127.9375, which exceeds the range of the temperature sensor. Some examples of different temperatures displayed in 12-bit resolution can be seen in table 1. | ||
- | **//Table 1//** Different temperature values and how they are stored in the temperature register. | + | ^**//Table 1//** Different temperature values and how they are stored in the temperature register.^^^ |
^ **MS Byte** | ^ **MS Byte** | ||
| 0000 0111 | 1101 0000 | + 125 °C | | | 0000 0111 | 1101 0000 | + 125 °C | | ||
Line 64: | Line 74: | ||
The configuration register is stored in the scratchpad memory (and EEPROM) and contains 1 byte of data. The MSB (bit 7) and the 5 LSB (bit 0 – 4) are reserved for internal use and cannot be changed. Bit 6 (R1) and bit 5 (R0) can be changed to adjust the resolution (figure 4). As can be seen, the conversion time doubles each time the resolution is increased by 1. A 12-bit resolution measurement takes 8 times as long as a 9-bit conversion. | The configuration register is stored in the scratchpad memory (and EEPROM) and contains 1 byte of data. The MSB (bit 7) and the 5 LSB (bit 0 – 4) are reserved for internal use and cannot be changed. Bit 6 (R1) and bit 5 (R0) can be changed to adjust the resolution (figure 4). As can be seen, the conversion time doubles each time the resolution is increased by 1. A 12-bit resolution measurement takes 8 times as long as a 9-bit conversion. | ||
- | {{: | + | ^{{: |
- | **//Figure 4//** Schematic of the configuration register and the different thermometer resolution configurations. | + | |**//Figure 4//** Schematic of the configuration register and the different thermometer resolution configurations.| |
==== 2.5 1-Wire Bus ==== | ==== 2.5 1-Wire Bus ==== | ||
Line 89: | Line 99: | ||
===== 3. Technical Specifications and Setup of the Sensor ===== | ===== 3. Technical Specifications and Setup of the Sensor ===== | ||
- | When connecting the pins (figure 1), pin 1 (red) is VDD, pin 2 (black) is GND and pin 3 (yellow) is the data pin. In this project two sensors, one measuring the temperature at the bottom of the pond and one at the surface, are connected to the ESP32. As each sensor can be addressed individually by its serial code, the data pins can be connected to the same GPIO pin of the ESP32 (here pin 14 was used). As mentioned before, the sensors need a pullup resistor connecting the data pin with VDD. As both sensors are connected in the same data bus, only a single 5kΩ resistor between their data pins and VDD needs to be added. | + | When connecting the pins (figure 1), pin 1 (red) is VDD, pin 2 (black) is GND and pin 3 (yellow) is the data pin. In this project two sensors, one measuring the temperature at the bottom of the pond and one at the surface, are connected to the ESP32. As each sensor can be addressed individually by its serial code, the data pins can be connected to the same GPIO pin of the ESP32 (here pin 14 was used). As mentioned before, the sensors need a pullup resistor connecting the data pin with VDD. As both sensors are connected in the same data bus, only a single 5kΩ resistor between their data pins and VDD needs to be added (see figure 5). |
Like the DHT-22, VDD can be anywhere between 3.0 V to 5.5 V and can thus be powered by the ESP32 without a problem. Further information on the sensor’s specifications can be found in table 2 and in the datasheet. | Like the DHT-22, VDD can be anywhere between 3.0 V to 5.5 V and can thus be powered by the ESP32 without a problem. Further information on the sensor’s specifications can be found in table 2 and in the datasheet. | ||
- | **//Table 2//** Specifications of the DS18B20 digital temperature sensor (local power supply with ESP32). | + | ^**//Table 2//** Specifications of the DS18B20 digital temperature sensor (local power supply with ESP32).^^^^ |
- | ^ Sensor | + | ^ Sensor |
| Supply Voltage $V_{DD}$ | | Supply Voltage $V_{DD}$ | ||
| Pullup Supply Voltage $V_{PU}$ | | Pullup Supply Voltage $V_{PU}$ | ||
Line 109: | Line 119: | ||
| ::: | 11 bit | 0.125 °C | 187.5 ms | | | ::: | 11 bit | 0.125 °C | 187.5 ms | | ||
| ::: | 12 bit | 0.0625 °C | 93.75 ms | | | ::: | 12 bit | 0.0625 °C | 93.75 ms | | ||
+ | |||
+ | ^{{: | ||
+ | |**//Figure 5//** ESP32 connected to two DS18B20s, here the DS18B20s have 4 pins, white is the data bus, orange is not used.| | ||
===== 4. Programming the DS18B20 ===== | ===== 4. Programming the DS18B20 ===== | ||
Line 278: | Line 291: | ||
- The variable RESOLUTION stores the resolution of the DS18B20 sensors. As the resolution is not changed during the sketch, it is by default 12 bit. | - The variable RESOLUTION stores the resolution of the DS18B20 sensors. As the resolution is not changed during the sketch, it is by default 12 bit. | ||
- The variable TCONV stores the time necessary for the sensor to convert the temperature reading to a digital signal and store it in the scratchpad memory with a resolution of 12 bit. | - The variable TCONV stores the time necessary for the sensor to convert the temperature reading to a digital signal and store it in the scratchpad memory with a resolution of 12 bit. | ||
- | - After issuing a temperature conversion command, the sensor needs a certain time (table 2) depending on the resolution for the data to be actualized. If the temperature data is read before, the old data is retrieved. When powering up the sensor first, the default value for T equals +85 °C. If the delay after the convert command is too short, the readings can be highly erroneous. The necessary time for the conversion is t_delay=t_CONV/2^(12-RESOLUTION) . As it is an integer variable, the conversion time for 10 bit and 9 bit resolution is rounded down. Therefore, a safety margin of 10ms was added here. The function pow() calculates the value of a number that is raised to a power. The first argument is the base, the second is the exponent. | + | - After issuing a temperature conversion command, the sensor needs a certain time (table 2) depending on the resolution for the data to be actualized. If the temperature data is read before, the old data is retrieved. When powering up the sensor first, the default value for T equals +85 °C. If the delay after the convert command is too short, the readings can be highly erroneous. The necessary time for the conversion is $t_{delay}=\frac{t_{CONV}}{2^{(12-RESOLUTION)}}$ . As it is an integer variable, the conversion time for 10 bit and 9 bit resolution is rounded down. Therefore, a safety margin of 10ms was added here. The function pow() calculates the value of a number that is raised to a power. The first argument is the base, the second is the exponent. |
- The function measureDS18B20Tem() is defined below and performs the temperature measurements and actualizes the variables. It is to be implemented later on in the complete project sketch. | - The function measureDS18B20Tem() is defined below and performs the temperature measurements and actualizes the variables. It is to be implemented later on in the complete project sketch. | ||
- The actualized string objects containing the temperatures is printed to the serial monitor. | - The actualized string objects containing the temperatures is printed to the serial monitor. | ||
Line 310: | Line 323: | ||
</ | </ | ||
- | The first sensor (1) was measuring the room temperature on a rather warm day. The second sensor (2) measured the temperature of my hand. Both measurements seem reasonable and when both sensors measure the room temperature, | + | The first sensor (1) was measuring the room temperature on a rather warm day. The second sensor (2) measured the temperature of my hand. Both measurements seem reasonable and when both sensors measure the room temperature, |
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <a href=" | ||
+ | <span style=" | ||
+ | Back to the top &# | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ |
amc2020/group_n/ds18b20.1594821293.txt.gz · Last modified: 2023/01/05 14:38 (external edit)