How can I upload and plot temperature values that are both above zero (e.g., ambient) and below zero (e.g., in a freezer)?
Show older comments
I wish to upload and plot on channel chart both positive and negative temperatures from DS18B20 sensor. While I can see the positive temperatures properly on the chart, the negative temperatures also show as above zero. The code snippet is as below:
if(temp_data & 0x80)
{
temp_data = (~temp_data)+1;
sprintf(esp_buff, "GET /update?api_key=%s&field1=%d", API_WRITE_KEY, -temp_data);
}
else
{
sprintf(esp_buff, "GET /update?api_key=%s&field1=%d", API_WRITE_KEY, temp_data);
}
//sprintf(esp_buff, "GET /update?api_key=%s&field1=%d", API_WRITE_KEY, temp_data);
ESP8266_Send(esp_buff);

It can be seen that the last two readings which are -6 and -9 deg C,show as +6 and +9 deg C. what should I do to make them come below the zero line?
5 Comments
dpb
on 10 Sep 2022
Looks as though you're munging on an 8-bit data value and masking off the sign bit -- should be reading into a signed int8 variable or doing a typecast to a double of the signed input instead before this where retrieve the data. Then you wouldn't have need for all the above machinations.
Ardish Morawala
on 11 Sep 2022
Christopher Stapels
on 12 Sep 2022
Can you send the esp_buff to the serial monitor to see what you are sending to ThingSpeak? ThingSpeak is actually quite good at number interpretation, I suspect you may be failing to send the data that you wish to send.
You could also send rawtemp and do the conversion with MATLAB inside of ThingSpeak.
Ardish Morawala
on 12 Sep 2022
dpb
on 12 Sep 2022
I backed out of the thread because I have no Arduino experience nor one at hand to play with to learn about, but the poking around I did indicated there are at least a couple of libraries that can be used to interact with the one-wire device...it appeared with those one just reads a buffer and magic happens...
Answers (3)
Ardish Morawala
on 12 Sep 2022
0 votes
Image Analyst
on 12 Sep 2022
If you can get your data into a double image, you can use
imshow(yourTemperatureImage, []);
Christopher Stapels
on 12 Sep 2022
Edited: Christopher Stapels
on 12 Sep 2022
I think the library answer seems best.
This article seems to indicate that you can use arduino libraries in Atmel Studio.
If you wanted to fix the code above, I would start by writing rawtemp to thingspeak and seeing if the negative values are encoded in there. Then you can fix your code to translate rawtemp appropriately.
sprintf(esp_buff, "GET /update?api_key=%s&field1=%d&field2=%d", API_WRITE_KEY, temp_data,rawtemp);
1 Comment
Ardish Morawala
on 15 Sep 2022
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!