Community Forum
    • Blog
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Negative temperature measures

    Scheduled Pinned Locked Moved TH02
    temperatureth02negativelibrary
    4 Posts 2 Posters 2.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kgx123
      last edited by

      Hi Charles-Henri,

      I am using your excellent TH02 library on Moteino. I have one sensor outside my house, with minus degrees celsius. However the TH02 lib reports the absolute value, without the minus prefix. E.g. “6.5” instead of “-6.5″. Please advise on what I am doing wrong.

      Merci beacoup,
      Karim

      From the Arduino sketch:

      int16_t temp, rh, rh_comp;
       //uint8_t status;
       
       Serial.print(F("Starting Temperature conversion."));
       sensor.startTempConv();
       sensor.waitEndConversion();
       Serial.println(F(".done!"));
      
       // Get temperature calculated and rounded
       temp = sensor.getConversionValue();
       
       // Display unrounded value (raw)
       Serial.print(F("Temperature = "));
       // this call does not do any I2C reading, it use last reading
       Serial.print(sensor.getLastRawTemp()/100.0);
       Serial.print(F(" C  =>  "));
       // Display now rounded value returned by 1st call
       Serial.print(temp/10.0);
       Serial.println(F(" C"));
      
      1 Reply Last reply Reply Quote
      • CharlesC Offline
        Charles
        last edited by

        Karim,

        Would you try to modify the following line (261 to 269) to the library th02.cpp

         if(result >= 5000)
        {
          result -= 5000;
        }
        else
        {
          result -= 5000;
          result = -result;
        }
        

        by

        result -= 5000;
        

        Let me know if it works, I don’t understand why I’ve done like that 😉

        1 Reply Last reply Reply Quote
        • K Offline
          kgx123
          last edited by

          Changes done to th02.cpp. Thanks! Seems to be working fine ::

          NEGATIVE TEMP:
          Starting Temperature conversion..done!
          Temperature = -7.00 C => -7.00 C

          Starting Temperature conversion..done!
          Temperature = -5.82 C => -5.80 C

          Starting Temperature conversion..done!
          Temperature = -2.10 C => -2.10 C

          Starting Temperature conversion..done!
          Temperature = -0.79 C => -0.80 C

          POSITIVE TEMP:
          Starting Temperature conversion..done!
          Temperature = 1.43 C => 1.40 C

          Starting Temperature conversion..done!
          Temperature = 2.87 C => 2.90 C

          1 Reply Last reply Reply Quote
          • CharlesC Offline
            Charles
            last edited by

            Excellent,
            I will modify the lib on github
            Charles

            1 Reply Last reply Reply Quote
            • First post
              Last post

            3

            Online

            5.7k

            Users

            534

            Topics

            5.0k

            Posts

            Top Topics

            • Denky 4 - Domoticz - Triphasé -
              Nicolas BernaertsN
              Nicolas Bernaerts
              0
              7
              249

            • Denky D4 et Linky Standard TInfo Rx Non Configuré
              CharlesC
              Charles
              0
              5
              282

            • CC1101
              CharlesC
              Charles
              0
              2
              117

            Popular Tags

            teleinfo
            24 topics
            arduino
            19 topics
            remora
            16 topics
            esp8266
            10 topics
            arduipi
            10 topics
            wifinfo
            7 topics
            raspberry
            7 topics
            broadcast
            7 topics
            Copyright © 2022 Charles-Henri Hallard | Return to blog page | Powered by NodeBB