How can I upload and plot temperature values that are both above zero (e.g., ambient) and below zero (e.g., in a freezer)?

7 views (last 30 days)
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);
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);
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?
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 appeared with those one just reads a buffer and magic happens...

Sign in to comment.

Answers (3)

Ardish Morawala
Ardish Morawala on 12 Sep 2022
Hello DB. I am not an Arduino fan. I use the Arduino hardware but do the programming with Atmel Studio 7. I do not use Arduino IDE. So I do not use Arduino libraries. But I observed that the sprintf statement does not give output as negative values, even though the LCD shows negative readings. Can you spot any issues in my use of the sprintf function? Also, can you please guide me how to use MATLAB's data conversion functions to generate correct output from signed hex integer? Thanks.

Image Analyst
Image Analyst on 12 Sep 2022
If you can get your data into a double image, you can use
imshow(yourTemperatureImage, []);

Christopher Stapels
Christopher Stapels on 12 Sep 2022
Edited: Christopher Stapels on 12 Sep 2022
I think the library answer seems best.
Here is an example using the dallas one wire (that has some other dependancies built in )
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
Ardish Morawala on 15 Sep 2022
Hello Christopher. I am sorry for the delay responding to your advice, I was caught upin some othr work. As suggested by you and others, I simulated thenegative temperature as sent by DS18B20 in the Atmel Studio debugger. I was happy to see that the sprintf statement (for -ve data) was properly working, it showed me proper negative temperature. But once again, when I put the system online, I got only positive readings. Then I checked the actual raw data just before processing it for the sprintf statement (Refer debug statements incode). I caught the bug here. I found that I was mistakenly using the already processed data used by the LCD display routine just before the routine toupload toThingspeak. This was a mistake. I then edited the code to copy the DS18B20 data to another variable and processed it.This worked. Now the temperature is showing negative readings as desired. It was sheer overlook on my part not to have used the proper data.
Thank you all to advise me and suggest the way to solve the problem.
int16_t ts_temperature; //set variable for temperature upload to Thingspeak -ADDED
int8_t temp_msb; //variable to check sign
int16_t temp_data; //variable to hold integer part of ts_temperature
ts_temperature = rawtemp; //copy to upload to TS - USED THIS DATA
memset(debug_buff, 0, 10);
sprintf(debug_buff, "%X", ts_temperature); //debug- read temp
...............//FURTHER CODE

Sign in to comment.


More Answers in the  ThingSpeak Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by