writing data to SD gives overload is ambiguous

Hi there,

On another project of mine (the first I haven’t yet finished, it is quite difficult) I try to log some temperature data to an SD (and lateron to wifi).
As for now, the data is displayed real time on a LCD and written to the SD(although that’s the goal haha).

I first used another piece of code (from the internet, duh) which involved a digital conversion I believe. But I can’t find this anymore.
But now I’ve run on wall, I already tried a lot but I can’t seem to fix it, it will pop up another error.
the real error is:
call of overloaded ‘println(DeviceAddress)’ is ambiguous.

If I am right, this means that my data has to be converted somehow to a number (I am quite new to programming), an integer? To problem is that my dsb18b20 probably gives a 12(?) bit signal…

Now I can’t figure out what to do, I already tried to add this piece of code:

{
  void printDouble( double val, byte precision){
 // prints val with number of decimal places determine by precision
 // precision is a number from 0 to 6 indicating the desired decimial places
 // example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)

 Serial.print (int(val));  //prints the int part
 if( precision > 0) {
   Serial.print("."); // print the decimal point
   unsigned long frac;
   unsigned long mult = 1;
   byte padding = precision -1;
   while(precision--)
      mult *=10;
      
   if(val >= 0)
     frac = (val - int(val)) * mult;
   else
     frac = (int(val)- val ) * mult;
   unsigned long frac1 = frac;
   while( frac1 /= 10 )
     padding--;
   while(  padding--)
     Serial.print("0");
   Serial.print(frac,DEC) ;
 }
}
}

But this gives me an error that the next ‘void’ won’t work. Well, it then says my printtemperature isn’t defined, which definetly is…

Here is my code:

/* YourDuino.com Example Software Sketch
 20 character 4 line I2C Display
 Backpack Interface labelled "LCM1602 IIC  A0 A1 A2"
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>
File myFile;
char filename[] = "Temp.CSV";

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 9
const int chipSelect = 4;
/*-----( Declare Constants )-----*/
//none
/*-----( Declare objects )-----*/
// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0xFF, 0x1E, 0x45, 0x34, 0x16, 0x03, 0x13 }; 
DeviceAddress Probe02 = { 0x28, 0xFF, 0xEB, 0x2B, 0x90, 0x15, 0x03, 0xDF };
/*DeviceAddress Probe03 = { 0x28, 0x4D, 0x8D, 0x40, 0x04, 0x00, 0x00, 0x78 }; voor meer sensors
DeviceAddress Probe04 = { 0x28, 0x9A, 0x80, 0x40, 0x04, 0x00, 0x00, 0xD5 };
DeviceAddress Probe05 = { 0x28, 0xE1, 0xC7, 0x40, 0x04, 0x00, 0x00, 0x0D };
*/

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
{


  // initialize the lcd for 20 chars 4 lines and turn on backlight
  lcd.begin(20,4); 
  
    // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 9);
  sensors.setResolution(Probe02, 9);
/*  sensors.setResolution(Probe03, 10);
  sensors.setResolution(Probe04, 10);
  sensors.setResolution(Probe05, 10);
*/
}
{
    // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  }
}
void loop()
{
  

  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("temp1: ");
  printTemperature(Probe02);
  lcd.println();

  delay(500);
  lcd.setCursor(0,1);
  lcd.print("temp2: ");
  printTemperature(Probe01);
  lcd.println();
  
// myFile = SD.open("Temp.csv", FILE_WRITE);//<<<<<<<<<<<<< OPEN
//  myFile.println(Probe02);
//  myFile.println(Probe01);
//  myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE


  
}


void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   lcd.print("C: ");
   lcd.print(tempC);
   }
}// End printTemperature

/* ( THE END ) */

I tried to write:
myFile.println((int)Probe0x1);
But this gave quite strange numbers :grin: haha.

I hope you guys have a solution, so I can start log data starting tonight 8) .
I don’t really know what I do wrong, so I don’t know how to fix this…

(I edited my code, so it’s abit cleaner)

If I am right, this means that my data has to be converted somehow to a number (I am quite new to programming), an integer? To problem is that my dsb18b20 probably gives a 12(?) bit signal...

That's nonsense. The problem is that address of the device is NOT something that you can print to the SD card. Why would you want to? Printing the index makes sense. Printing the temperature makes sense. Printing the address does not.

If you just MUST print the address, notice how much it looks like an array. Print the elements of the array, one at a time.

No, I want to print the temperature. But I don't know how then...

Why can I print (probe01) to my lcd, but why can't I print it to my sd file?

Surely the question is why do you [u]want[/u] to print it to the file ?

Why can I print (probe01) to my lcd, but why can't I print it to my sd file?

To answer this question, YOU would have to look at the inheritance path for each of the libraries involved. The SD File class inherits from Print. Print does not know how to handle printing a collection of data whose type is DeviceAddress.

Again, WHY do you want to record the address of the thermometer? The location makes sense. The thermometer number makes sense. The temperature detected by the thermometer makes sense. The address does NOT.

It would be like recording the gas used by your cars using the starter motor's serial number. If you do that, and decide to take a long trip, and use the car that gets the best mileage, you'd have to drawl under all the cars to find which one had the right serial number.

The blue car gets 20 mpg; the red one gets 30; the truck gets 12. Which vehicle do you use? Well, it's a no-brainer. No need to crawl under the car to see if it is red.

Well.
What I want, is to log the temperatures to the sd card. That’s it. (For the sd card).
I probably did something wrong to log the data :stuck_out_tongue: .

What I want, is to log the temperatures to the sd card.

So, which variable contains the temperature? Probe01 is not the correct answer.

ok so I added these 2 lines:
float celsius1 = sensors.getTempC(Probe01);
float celsius2 = sensors.getTempC(Probe02);

and changed these 2:
myFile.println(celsius1);
myFile.println(celsius2);

which gave as a result:

void loop()


{
 
  float celsius1 = sensors.getTempC(Probe01);
  float celsius2 = sensors.getTempC(Probe02);
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("temp1: ");
  printTemperature(Probe02);
  lcd.println();

  delay(500);
  lcd.setCursor(0,1);
  lcd.print("temp2: ");
  printTemperature(Probe01);
  lcd.println();

  Serial.println(celsius1);
  Serial.println(celsius2);
  
 myFile = SD.open("Temp.csv", FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.println(celsius1);
  myFile.println(celsius2);
  myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE


  
}

Oh damn. This was a hard lesson to learn :grin: