Print Float numbers

Can anyone explain to me why I get "call of overload 'String(float&)' is ambiguous" when verifying this sketch?

The line highlighted is near the end when trying to create a datastring for storing to SD card.

#include <SD.h>

// The value of the attached resistor
#define SERIESRESISTOR 10000    
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000      
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25   
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
 
// Which pin the thermistors are connected to
#define THERMISTOR1 A0 
#define THERMISTOR2 A1
#define THERMISTOR3 A2
#define THERMISTOR4 A3
#define THERMISTOR5 A4
#define THERMISTOR6 A5

//SPI Settings
//MOSI, MISO, SCLK Set by default
int CS_pin = SS;

long id = 1;  //Use this to store id # of reading.

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);

  Serial.println("Initializing Card");
  //CS Pin is an output
  pinMode(CS_pin, OUTPUT);
  
  //Check if card ready
  if(!SD.begin(CS_pin))
  {
    Serial.println("Card Failure");
  }
  Serial.println("Card Ready");

  //Write Log File Header
  File logFile = SD.open("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println(", ,");  //Just a leading blank line, incase there was previous data
    logFile.println("ID, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6");
    logFile.close();
    Serial.println("ID, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6");
  }
  else
  {
    Serial.println("Couldn't open log file");
  }
}

void loop() {
  float reading1;
  reading1 = analogRead(THERMISTOR1);
 
  // convert the value to resistance
  reading1 = (1023 / reading1)  - 1;
  reading1 = SERIESRESISTOR / reading1;
  
  // convert resistance to temperature
  float steinhart1;
  steinhart1 = reading1 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart1 = log(steinhart1);                  // ln(R/Ro)
  steinhart1 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart1 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart1 = 1.0 / steinhart1;                 // Invert
  steinhart1 -= 273.15;                         // convert to C
  
  float reading2;
  reading2 = analogRead(THERMISTOR2);
  
  // convert the value to resistance
  reading2 = (1023 / reading2)  - 1;
  reading2 = SERIESRESISTOR / reading2;

  // convert resistance to temperature
  float steinhart2;
  steinhart2 = reading2 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart2 = log(steinhart2);                  // ln(R/Ro)
  steinhart2 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart2 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart2 = 1.0 / steinhart2;                 // Invert
  steinhart2 -= 273.15;                         // convert to C
  
  float reading3;
  reading3 = analogRead(THERMISTOR3);
  
  // convert the value to resistance
  reading3 = (1023 / reading3)  - 1;
  reading3 = SERIESRESISTOR / reading3;

  // convert resistance to temperature
  float steinhart3;
  steinhart3 = reading3 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart3 = log(steinhart3);                  // ln(R/Ro)
  steinhart3 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart3 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart3 = 1.0 / steinhart3;                 // Invert
  steinhart3 -= 273.15;                         // convert to C
  
  float reading4;
  reading4 = analogRead(THERMISTOR4);
  
  // convert the value to resistance
  reading4 = (1023 / reading4)  - 1;
  reading4 = SERIESRESISTOR / reading4;

  // convert resistance to temperature
  float steinhart4;
  steinhart4 = reading4 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart4 = log(steinhart4);                  // ln(R/Ro)
  steinhart4 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart4 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart4 = 1.0 / steinhart4;                 // Invert
  steinhart4 -= 273.15;                         // convert to C
  
  float reading5;
  reading5 = analogRead(THERMISTOR5);
  
  // convert the value to resistance
  reading5 = (1023 / reading5)  - 1;
  reading5 = SERIESRESISTOR / reading5;

  // convert resistance to temperature
  float steinhart5;
  steinhart5 = reading5 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart5 = log(steinhart5);                  // ln(R/Ro)
  steinhart5 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart5 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart5 = 1.0 / steinhart5;                 // Invert
  steinhart5 -= 273.15;                         // convert to C
  
  float reading6;
  reading6 = analogRead(THERMISTOR6);
  
  // convert the value to resistance
  reading6 = (1023 / reading6)  - 1;
  reading6 = SERIESRESISTOR / reading6;

  // convert resistance to temperature
  float steinhart6;
  steinhart6 = reading6 / THERMISTORNOMINAL;     // (R/Ro)
  steinhart6 = log(steinhart6);                  // ln(R/Ro)
  steinhart6 /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart6 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart6 = 1.0 / steinhart6;                 // Invert
  steinhart6 -= 273.15;                         // convert to C
  
  //Create Data string for storing to SD card
  //We will use CSV Format
  String dataString = String(id) + ", " + String (steinhart1) + ", " + String (steinhart2) + ", " + String (steinhart3) + ", " + String (steinhart4) + ", " + String (steinhart5) + ", " + String (steinhart6);
  
  //Open a file to write to
  //Only one file can be open at a time
  File dataFile = SD.open("LOG.csv", FILE_WRITE);
  if(dataFile)
  {
    dataFile.println(dataString);
    dataFile.close();
  }
  else
  {
    Serial.println("Couldn't access file");
  }
  
  //Increment ID number
  id++;
  
  delay(1000);
}

I can Serial.print the steinhart values though can't seem to be able to write them to a csv file on a SD card, is it because the numbers are too large? Do I need to simplify the numbers?

Thanks in advance for any help.

There was more to the message than that. Specifically, it told you what the alternatives were.

There is no reason to be building a String object to write to the file. Write the pieces one at a time, and avoid the issues with the String class altogether.

PaulS:
There was more to the message than that. Specifically, it told you what the alternatives were.

There is no reason to be building a String object to write to the file. Write the pieces one at a time, and avoid the issues with the String class altogether.

Could you give an example of code please?

dataFile.print("ID,");
dataFile.print(Temp1);
dataFile.print(",");
dataFile.print(Temp2);
dataFile.print(",");
dataFile.print(Temp3);
dataFile.print(",");
etc

robtillaart:
dataFile.print("ID,");
dataFile.print(Temp1);
dataFile.print(",");
dataFile.print(Temp2);
dataFile.print(",");
dataFile.print(Temp3);
dataFile.print(",");
etc

Again your a star :slight_smile: One thing more though, how do I get the ID to (a) print as a number again? (b) increment+1 each time like it used to when in the string?

Thanks

indieflow:

robtillaart:
dataFile.print("ID,");
dataFile.print(Temp1);
dataFile.print(",");
dataFile.print(Temp2);
dataFile.print(",");
dataFile.print(Temp3);
dataFile.print(",");
etc

Again your a star :slight_smile: One thing more though, how do I get the ID to (a) print as a number again? (b) increment+1 each time like it used to when in the string?

Thanks

Doesn't matter I realised I just had to change the line dataFile.print("ID,"); to dataFile.print(id);

And add another line to output the comma to the file after id

UKHeliBob:
And add another line to output the comma to the file after id

Thanks :slight_smile: