8:22 am

April 3, 2012

I found a post on the Arduino forum:
#include<stdlib.h> dtostrf(FLOAT,WIDTH, PRECISION,BUFFER);
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1205038401
(At the bottom of the post, that may help...)
If this works, please let us know and I will add it the Arduino tutorials.
10:57 am


Gold
June 16, 2013

Here's how I have done it:
char buffer2[14]; //make buffer large enough for 7 digits
String tempStr = dtostrf(allSensors[i].averageTemp, 7,2,buffer2);
//'7' digits including '-' negative, decimal and white space. '2' decimal places
tempStr.trim(); //trim whitespace, important so ThingSpeak will treat it as a number
The std lib.h is included by default.
3:56 pm

January 25, 2014

4:29 pm


Gold
June 16, 2013

Thanks, gadjet, thats very cool. That led me to read all the String object methods:
http://arduino.cc/en/Reference/StringObject
1:52 pm


Silver
October 10, 2015

gadjet said
I used this: -
updateThingSpeak("field1="+ String(sensors.getTempC(Thermometer),DEC));This takes the float value from my DS18B20 temp sensor.
If anyone is around I used a slightly different take to get decimal values to two decimal places.
I needed 3 values passed to thingspeak. Most of the code below is just debug stuff but I left it in.
The lines that do the work are the FLOAT.
Yes I borrowed the code from another thingspeak member and just tweaked it a little as it seemed slightly more modular and easier to add sensor routines see http://community.thingspeak.com/forum/arduino/ds18b20-temp-sensor/ Raklinks post
//Print Temperatures
Serial.print("Getting temperatures...
");
sensors.requestTemperatures();
float WT = sensors.getTempC(WaterTemp); // was int
Serial.print("INVALID: ");
Serial.print(WT);
Serial.print("C: ");
Serial.print("
");
float OT = sensors.getTempC(OutsideTemp); // was int
Serial.print("Room Temp is: ");
Serial.print(OT);
Serial.print("C: ");
Serial.print("
");
// read value of 5V solar panel 0 to 500
float LT = (analogRead(A0)); // was int
//String AP = String(analogRead(A0), DEC);
Serial.print("light: ");
Serial.print(LT/100); // divide by 100 to get voltage produced
Serial.print("V: ");
Serial.print("
");
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak("field1="+String(WT, DEC) +"&field2="+String(OT, DEC)+"&field3="+String(LT, DEC));
12:54 am

January 10, 2019

Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float. Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.
4:07 pm

February 18, 2019

I am sending voltage readings to thingspeak as float values, but I'm only seeing two decimals at this end. As my values are in the range of 0,001 -0,5 V, I am loosing everything below 0,01V. As far as I understand, the float values from the arduino should not be truncated, so do i need to change anything in thingspeak?
8:21 am


Moderators
March 7, 2017

Asche,
Are you seeing truncated values on plots or on data that you have exported? You can use a rest call or the data export button or tab to view your data. ThingSpeak does not truncate data you send but data on plots might be rounded. There is a setting in the plot settings for rounding.
If you try this in your browser, you should get the raw data back for the last data point in a private channel (be sure to change to your Read API key:
https://api.thingspeak.com/channels/266256/feeds/last?api_key=xxxxxxxxxxxxxxxx
Does the last point have the number of decimals you need?
Most Users Ever Online: 166
Currently Online:
32 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457