Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Calculated Variable Celsius to Fahrenheit DS18

Home Forums Mayfly Data Logger Calculated Variable Celsius to Fahrenheit DS18

Viewing 14 reply threads
  • Author
    Posts
    • #15133
      BrianJastram
      Participant

        My problem is that during compilation I get the error below.
        I’m trying to convert the Celsius reading from my DS18 to Fahrenheit by using the baro_rho_correction sketch as a guide. I feel like I’ve got the calculated variable code copied over right as far as I can tell but something’s still wrong in the 186 to 240 line range.
        I have included the sketch that I’m working on.

      • #15134
        Sara Damiano
        Moderator

          In line 237 you don’t need the “new” or anything else with the calcTempF.

          Replace new CalcTempF(&ds18, "12345689-abcd-1234-ef00-1234567890ab"), with just CalcTempF,

          You’ve already created and named the variable, so you don’t need to re-create it, just reference it. Actually, since you’ve created all your variables with names, you should reference all of them that way instead of creating a second identical one for each of them. So in your variable array, you can replace almost all of the new ... with the names you gave the variables in the sensor blocks. The result will look more like the VariableArray in the data saving example: https://github.com/EnviroDIY/ModularSensors/blob/149bb59cdb34f7d54d26cd4a81b7e7a90eabced8/examples/data_saving/data_saving.ino#L318

        • #15135
          Sara Damiano
          Moderator

            Does that make sense?

            So, for example, in line 178 you created a variable for the DS18 (Variable *ds18Temp = new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab");) Since you’ve already done that, down in line 234 instead you can replace new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab"), with just ds18Temp,.  And you can do the same with all of the other variables.

          • #15138
            BrianJastram
            Participant

              Awesome, thank you. That solved the error. I was wondering about my variable array because I saw the format of the variable array in the baro_rho_correction sketch and it was more bare bones.
              Now I’m puzzling on the -17966.20 Degree F output I’m seeing in the serial monitor. I tried adding true to the ds18->getValue(true) but that didn’t work.

            • #15139
              BrianJastram
              Participant

                Now I got it to be 33.8 F by replacing
                float TempF = TempCFromMaxiumDS18_Temp*1.8+32 with
                float TempF = true*1.8+32

              • #15140
                Sara Damiano
                Moderator

                  -17966.20 does seem a little bit cold for most offices.  Did you change your variable array so it has the ds18Temp named variable in it instead of the other new variable?  If not update step will update that other new variable and not the one that you’re calculating F from, though adding the “true” to the getValue should force it to update anyway.  Is the Celsius temperature from the DS18 reasonable?

                  Using true*1.8+32 will give you 33.8 no matter what happens.  In the multiplication “true” is converted to “1” so your equation is just (1*1.8)+32 = 33.8.

                • #15141
                  Sara Damiano
                  Moderator

                    You can throw a Serial.println(TempCFromMaxiumDS18_Temp); into the middle of your calculation equation just for testing.  I can try testing your code myself later this afternoon.

                  • #15142
                    BrianJastram
                    Participant

                      I tried just DS18Temp but that didn’t work.
                      The Celsius temperature from the DS18 is a reasonable 22.25 degrees.

                    • #15143
                      Sara Damiano
                      Moderator

                        Hm.  Can you post your current code? I’ll try running it.  I have a DS18 here so hopefully once I attach things and start trying to run them whatever issue I’m missing will jump out at me.

                      • #15144
                        BrianJastram
                        Participant

                          Yes, thank you. Here it is.

                        • #15145
                          BrianJastram
                          Participant

                            There should be no u in Maxium in line 194.

                          • #15146
                            Sara Damiano
                            Moderator

                              The C-to-F is working for me with this calculation function:

                              And this variableArray:

                              But I don’t have a BME280 on my desk so I commented out all of that code to get it to work. I also don’t have a working XBee3 right now, so I couldn’t test with that. I don’t think those would interfere, but I’m just warning you that my testing isn’t exactly what you have.

                              Are you planning to keep the code for displaying on the little screen? You could simplify your code by removing all of the extra code for the BME280 and then displaying the result of the BME280 by using the variables you created for it for the logger. So, replace display.print("T: "); display.print(sensors.getTempCByIndex(0)); display.println(" C"); with display.print("T: "); display.print(bme280Temp->getValueString()); display.println(" C"); and so forth. If you want, on Monday I can write up a simpler version for you following that model.

                            • #15147
                              Sara Damiano
                              Moderator

                                Here’s the version without the extra un-needed BME code.  I left in all the code for the display.

                              • #15148
                                Sara Damiano
                                Moderator

                                  Sorry, the formatter and I were having an argument. I think it’s right now.

                                • #15149
                                  Sara Damiano
                                  Moderator

                                    The print-outs are always going to be updated about a minute behind because the board will go to sleep at the end of the logdata() function and won’t do the printing until the next time it wakes up (which will be the next minute).

                                Viewing 14 reply threads
                                • You must be logged in to reply to this topic.