logo elektroda
logo elektroda
X
logo elektroda

[Solved] ESP8266 WiFi: Inaccurate temperature values after decimal point - 28.50 instead of 28.18

slowik359 729 18
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 20727933
    slowik359
    Level 4  
    why does it display me a not exact decimal value in esp8266 wifi e.g. 28.50 ,34.00 ,25.50 ,22.50 and before it was 34.12 or 28.18


    Console screenshot displaying temperature measurement results. @ElektrodaBot
  • ADVERTISEMENT
  • #2 20727937
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    why does it display to me not the exact decimal value in esp8266 wifi e.g. 28.50 ,34.00 ,25.50 ,22.50 and before it was 34.12 or 28.18 https://obrazki.elektroda.pl/2611699600_1694342459.png
    Welcome to the forum!

    I'm guessing that the problem you're describing relates to the incorrect display of the values read from the sensor on the ESP8266 module.

    It appears that the values are rounded to the nearest .50 or .00, which suggests that the problem may lie in the rounding function or the conversion of a floating point number to a string.

    But before we go any further, additional information is needed:

    1. What sensor are you using for the measurements?
    2. What is the code that reads the values from the sensor and displays them?
    3. Have you made any changes to the code, hardware or settings that could cause this problem?
    4. Does the problem occur regardless of which value you are trying to read?

    In most cases, the incorrect display of the result could be due to an incorrect conversion of a floating point number to a string (or vice versa), an error in the rounding function, or a problem with the precision of the calculation on the microcontroller.

    Please provide the above information so that we can better understand and help you solve this problem.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #3 20727999
    slowik359
    Level 4  
    Code: JSON
    Log in, to see the code
    [/code]

    @ElektrodaBot
  • ADVERTISEMENT
  • #4 20728014
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    (...) t width height temp
    display.println(temp);
    display.println(" ");
    display.drawRect(123,30, 5, 5, WHITE); // this is from the celsius sign
    display.setCursor(110,25);
    display.setFont();
    display.display();
    Blynk.virtualWrite(V2, temp); //sending to Blynk app



    delay(5000);
    }
    Thanks for providing the full code again. It seems correct and should not cause problems with rounding to .50 or .00. The DallasTemperature library you are using returns the temperature as a `float`, so you should get a full precision reading.

    However, I noticed that you are using `display.println(temp);` to print the temperature to the display. By default, the `println()` function for the `float` type (as in the case of your `temp` variable) will only print two decimal places, which seems to be what you are seeing.

    Also, the `println()` method rounds floating-point numbers rather than truncates them, which may explain why you only see .50 or .00 - this is due to rounding.

    You could try using the `dtostrf()` function to convert `float` to `char[]` with the specified precision, and then print this string to the display. Below is an example of how to do this:

    Code: text
    Log in, to see the code


    The `dtostrf()` function converts a floating point value to a string. The second argument is the minimum width of the field, the third argument is the precision of the number (number of decimal places), and the last argument is the buffer for the result.

    Values greater than 99.99 or less than -9.99 will look slightly different because their length has exceeded 4 places. You can adjust the second argument of `dtostrf()` to match the longest expected number.

    Hopefully this solves the problem. Let me know if you need any more help!
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #5 20728031
    slowik359
    Level 4  
    further same
    Code: C / C++
    Log in, to see the code
    @ElektrodaBot
  • #6 20728036
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    (...) t width height temp
    display.println(temp);
    display.println(" ");
    display.drawRect(123,30, 5, 5, WHITE); // this is from the celsius sign
    display.setCursor(110,25);
    display.setFont();
    display.display();
    Blynk.virtualWrite(V2, temp); //sending to Blynk app


    delay(5000);
    }
    I noticed that despite using `dtostrf(temp, 4, 2, temp_display);` in your code, you still call `display.println(temp);` to display the temperature. This line will print the `float` value of temp, not the converted `temp_display` string.

    I suggest changing this part to `display.println(temp_display);` to print the converted string, which should contain the full temperature precision. Here is the modified code snippet:

    Code: text
    Log in, to see the code


    At the end I changed `display.println(temp);` to `display.println(temp_display);` in order to use the converted string instead of the original floating point value. This way you should see the full precision of the temperature on the display.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #7 20728079
    slowik359
    Level 4  
    did not help, because on the test one with the arduino it is the same, maybe the sensor is dead @ElektrodaBot
  • #8 20728091
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    it didn't help because on the test one with the arduino it is the same maybe the sensor is dead
    I guess when you say "on the test one with the arduino it is the same", you are trying to use a different microcontroller to test the same sensor? If so, and you still see the same results, it is possible that the problem actually lies with the DS18B20 sensor.

    The DS18B20 sensors are usually quite reliable, but like any device, they can fail.

    Remember that the DS18B20 is a digital sensor and returns temperature as a 16-bit number in binary format, so almost all possible values should be available. Limiting the results to values ending in .00 and .50 is very unusual and not typical of these sensors.

    Before assuming that the sensor is faulty, however, it is worth checking a few things:
    1. Check that the circuit is correctly powered and connected. The DS18B20 operates on a voltage between 3.0V and 5.5V. Make sure that the supply voltage is stable and within this range.
    2. Check that you have correctly connected the "pull-up" resistor to the data line. Typically, a resistor between 4.7k Ohm and 10k Ohm is recommended for the DS18B20.
    3. Try reading the temperature with another DS18B20 sensor (if you have one) to see if the problem occurs with other sensors as well.
    4. Try testing your sensor with simple code that only reads and displays the temperature, with no additional libraries or functions. Does the problem still occur?

    Remember that each sensor has its own specific operation and this may vary slightly from manufacturer to manufacturer. In some cases, sensors may need additional calibration to ensure accurate readings.

    If the problem persists despite attempts to solve it, it is likely that the sensor is actually faulty and you should replace it.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #9 20728120
    slowik359
    Level 4  
    The problem may lie in the fact that I have flashing it several times with espe tool, I don't know if I did it right maybe I need to do it again could you tell me what and how @ElektrodaBot
  • #10 20728122
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    The problem may lie in the fact that I have flashing it several times with the espe tool I don't know if I did it right maybe you need to do it again could you provide what and how
    Flashing the ESP8266 is the process of writing new firmware to the microcontroller. If you suspect the problem lies with this, it may be worth trying to re-flash the microcontroller. Below are the steps you should take. I use a tool called "esptool" for this.


    Please note - The steps below are for the Windows operating system.

    Step 1 : Download and install the latest version of Python from the official Python website.

    Step 2 : Open cmd (Command Prompt) and install esptool using the following command:


    Code: Text
    Log in, to see the code


    Step 3 : Connect the ESP8266 module to your computer using the USB cable. Then, using Device Manager, check under which COM port your ESP8266 module is connected.

    Step 4 : Now we need to clear the ESP8266 flash memory. To do this, type the following command into cmd, replacing "COMX" with the appropriate COM port number:

    Code: Text
    Log in, to see the code



    Step 5 : Now we can reflash our ESP8266 module. To do this, we need to download the appropriate firmware binary file. This can be found on the official NodeMCU website. After downloading the file, enter the following command into cmd:


    Code: Text
    Log in, to see the code


    Place "COMX" with your COM port number and "path_to_file_binary" with the path to the downloaded binary file.

    Assuming everything went well, you should now have the ESP8266 module flashed. You can now try running your code again and see if the problem still exists.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • ADVERTISEMENT
  • #11 20728291
    slowik359
    Level 4  

    I cannot find this binary file @ElektrodaBot
    .
  • #12 20728293
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    I may not be familiar with this binary file
    I understand that you may be having trouble finding the correct firmware file for your ESP8266 module. Let me help you.

    Firmware updates for the ESP8266 module are available on the ESP8266 Community project page on GitHub. Below is a link to the latest releases:

    [ESP8266 releases on GitHub](https://github.com/esp8266/Arduino/releases)

    On this page you will see a list of different releases. The latest one is the most recent one. Click on it and then scroll down the page until you see the "Assets" section. This is where you will find the firmware binaries.

    The files are named "esp8266-xxxxxx.zip". Download the latest .zip file and then unzip it. Inside, you should find the .bin file you need to perform the flashing process.

    Memorize to modify the above command appropriately to include the correct path to the binary file on your computer.

    If you still have problems finding the file or with the flashing process, please let me know. I will be happy to help you through the process step by step.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #13 20728312
    slowik359
    Level 4  
    I cannot know this binary file @ElektrodaBot
  • ADVERTISEMENT
  • #14 20728316
    ElektrodaBot
    AI OpenAI ChatGPT4
    slowik359 wrote:
    I cannot know this binary file
    It looks like you are still having problems finding the binary file. I apologise for any confusion. Please let me direct you more accurately.


    Download the latest ESP8266 firmware

    The first step is to download the latest firmware for the ESP8266. You can download it directly from the official GitHub page of the ESP8266 project. Here is the direct link to the firmware release page:

    [https://github.com/esp8266/Arduino/releases](https://github.com/esp8266/Arduino/releases)


    How to find the binary file on the release page

    When you get to the release page, scroll down to the "Assets" section. There you will find various files to download. Look for the file that ends in ".bin" - this is the firmware binary file you need to download.

    For example, for release 2.7.4, the binary file is called "esp8266-2.7.4.bin". Click on this file to download it.


    Where are downloaded files saved

    After downloading the file, it should be in the "Downloaded" directory on your computer, unless you have changed the default download settings in your browser.


    How to find the path to the binary file

    To find the path to the binary file, open the "Downloaded" directory and find the downloaded file. Right-click on the file and select "Properties". In the "Location" section, you will find the full path to the file.

    Provide this path when flashing the ESP8266, replacing "path_to_binary_file" in step 5 of my previous instructions.

    If you still encounter problems, please let me know! I will be happy to help you through the process.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • Helpful post
    #15 20728945
    Menuet
    Level 19  
    Hi,
    Bot, bot, but isn't it sometimes the case that by chance the resolution of the temperature sensor has changed? It is configurable if I am not mistaken from 9 to 12 bits. The default after coming out of the factory is 12 bits.
    Maybe connect another sensor and check or change the resolution by software.
    Greetings,
    Menuet
  • #16 20728991
    slowik359
    Level 4  
    I do not have a second sensor. how to change it
  • Helpful post
    #17 20729011
    Menuet
    Level 19  
    According to the "dallastemperature" library information, the function to change the resolution looks like this:
    // set resolution of all devices to 9, 10, 11, or 12 bits
    // if new resolution is out of range, it is constrained.
    void DallasTemperature::setResolution(uint8_t newResolution);


    So in your case the initialisation of the library and sensor should look like this:
    DS18B20.begin();
    DS18B20.setResolution(12);


    It should work, if this is where the problem is :)

    Greetings,
    Menuet
  • #18 20729020
    slowik359
    Level 4  
    Lord you have saved lives works great thanks
  • #19 20729024
    slowik359
    Level 4  
    thanks to Menuet

Topic summary

The discussion revolves around the issue of inaccurate temperature readings from a DS18B20 sensor connected to an ESP8266 module, where values are displayed as rounded to .00 or .50 instead of precise decimal values. Initial troubleshooting suggested that the problem might stem from the rounding function or the conversion of floating-point numbers to strings. The user provided their code, which was confirmed to be correct, but it was noted that the `println()` function used for displaying the temperature only prints two decimal places, leading to the observed rounding. A solution was proposed to use the `dtostrf()` function to convert the float to a string with specified precision. Further investigation revealed that the issue persisted even when tested with a different microcontroller, suggesting a potential fault with the DS18B20 sensor. The user was advised to check the sensor's wiring, power supply, and pull-up resistor. Additionally, it was suggested to re-flash the ESP8266 firmware if issues continued. Ultimately, the resolution involved changing the sensor's resolution setting using the DallasTemperature library, which successfully restored accurate temperature readings.
Summary generated by the language model.
ADVERTISEMENT