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 ビュー (過去 30 日間)
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 件のコメント
dpb
dpb 2022 年 9 月 12 日
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...

サインインしてコメントする。

回答 (3 件)

Ardish Morawala
Ardish Morawala 2022 年 9 月 12 日
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 2022 年 9 月 12 日
If you can get your data into a double image, you can use
imshow(yourTemperatureImage, []);

Christopher Stapels
Christopher Stapels 2022 年 9 月 12 日
編集済み: Christopher Stapels 2022 年 9 月 12 日
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 件のコメント
Ardish Morawala
Ardish Morawala 2022 年 9 月 15 日
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
uart_puts(debug_buff); //THIS SHOWED THAT WRONG DATA WAS BEING USED
uart_puts("\r\n");
...............//FURTHER CODE

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

Community Treasure Hunt

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

Start Hunting!

Translated by