I need help!!!

Hi folks I need some help with a project
I made the code that reads the temperature from DS18B20 sensor (x3)
and now I need to save data to an SD card and everything I ever tried
did not work so please help
Here’s the code:

#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 177 };
static uint8_t myPort = 80; 
#define PREFIX ""
WebServer webserver( PREFIX, myPort );
#define SENSOR_A  7
#define SENSOR_B  6
#define SENSOR_C  5
void sendTemperatureValues( WebServer &server);
void sendAboutPage( WebServer &server);
void sendFormButtons( WebServer &server);
void valuesCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendTemperatureValues( server );
  sendFormButtons( server );
}
void aboutCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendAboutPage( server );
  sendFormButtons( server );
}
void setup(){
  Ethernet.begin (mac, ip);
  webserver.begin();
  webserver.setDefaultCommand( &valuesCmd );
  webserver.addCommand( "values", &valuesCmd );
  webserver.addCommand( "about", &aboutCmd );
  digitalWrite(SENSOR_A, LOW);
  pinMode(SENSOR_A, INPUT);
  digitalWrite(SENSOR_B, LOW);
  pinMode(SENSOR_B, INPUT);
  digitalWrite(SENSOR_C, LOW);
  pinMode(SENSOR_C, INPUT);
}
void loop(){
  webserver.processConnection();
}
void sendAboutPage( WebServer &server )
{
  server.print("<h>napravio David Blažević u suradnji sa Centrom energije</h1>");
}
void sendFormButtons( WebServer &server )
{
  server << "<p><form METHOD='POST' action='" PREFIX "/values'>";
  server.println("<input type=submit value=\"ponovno ucitaj\">");
  server.println("</form></p>");
  server << "<p><form METHOD=POST action='" PREFIX "/about'>";
  server.println("<input type=submit value=\"o senzru\">");
  server.println("</form>");
}
void sendTemperatureValues( WebServer &server )
{
  char temp_string_a[10];
  char temp_string_b[10];
  char temp_string_c[10];
  getCurrentTemp(SENSOR_A, temp_string_a);
  getCurrentTemp(SENSOR_B, temp_string_b);
  getCurrentTemp(SENSOR_C, temp_string_c);
  server.print("Sensor A:");
  server.print(temp_string_a);
  server.print("
");
  server.print("Sensor B:");
  server.print(temp_string_b);
  server.print("
");
  server.print("Sensor C:");
  server.print(temp_string_c);
  delay(1);
  
}
void OneWireReset (int Pin)
{
  digitalWrite (Pin, LOW);
  pinMode (Pin, OUTPUT);        
  delayMicroseconds (500);
  pinMode (Pin, INPUT);
  delayMicroseconds (500);
}
void OneWireOutByte (int Pin, byte d) 
{
  byte n;
  for (n=8; n!=0; n--)
  {
    if ((d & 0x01) == 1)  
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (5);
      pinMode (Pin, INPUT);
      delayMicroseconds (60);
    }
    else
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (60);
      pinMode (Pin, INPUT);
    }
    d = d>>1; 
  }
}
byte OneWireInByte (int Pin) 
{
  byte d, n, b;
  for (n=0; n<8; n++)
  {
    digitalWrite (Pin, LOW);
    pinMode (Pin, OUTPUT);
    delayMicroseconds (5);
    pinMode (Pin, INPUT);
    delayMicroseconds (5);
    b = digitalRead (Pin);
    delayMicroseconds (50);
    d = (d >> 1) | (b<<7); 
  }
  return (d);
}
void getCurrentTemp (int sensorPin, char *temp)
{
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0x44); 
  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0xbe);
  LowByte = OneWireInByte (sensorPin);
  HighByte = OneWireInByte (sensorPin);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  
  if (sign) 
  {
    TReading = (TReading ^ 0xffff) + 1; 
  }
  Tc_100 = (6 * TReading) + TReading / 4;    

  whole = Tc_100 / 100;  
  fract = Tc_100 % 100;
  if (sign) {
    temp[0] = '-';
  } else {
    temp[0] = '+';
  }

  if (whole/100 == 0) {
    temp[1] = ' ';
  } else {
    temp[1] = whole/100+'0';
  }
  temp[2] = (whole-(whole/100)*100)/10 +'0' ;
  temp[3] = whole-(whole/10)*10 +'0';
  temp[4] = '.';
  temp[5] = fract/10 +'0';
  temp[6] = fract-(fract/10)*10 +'0';
  temp[7] = '\0';
}

Read this: How to post code properly
and then fix up your code.

Pete

#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 177 };
static uint8_t myPort = 80; 
#define PREFIX ""
WebServer webserver( PREFIX, myPort );
#define SENSOR_A  7
#define SENSOR_B  6
#define SENSOR_C  5
void sendTemperatureValues( WebServer &server);
void sendAboutPage( WebServer &server);
void sendFormButtons( WebServer &server);
void valuesCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendTemperatureValues( server );
  sendFormButtons( server );
}
void aboutCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendAboutPage( server );
  sendFormButtons( server );
}
void setup(){
  Ethernet.begin (mac, ip);
  webserver.begin();
  webserver.setDefaultCommand( &valuesCmd );
  webserver.addCommand( "values", &valuesCmd );
  webserver.addCommand( "about", &aboutCmd );
  digitalWrite(SENSOR_A, LOW);
  pinMode(SENSOR_A, INPUT);
  digitalWrite(SENSOR_B, LOW);
  pinMode(SENSOR_B, INPUT);
  digitalWrite(SENSOR_C, LOW);
  pinMode(SENSOR_C, INPUT);
}
void loop(){
  webserver.processConnection();
}
void sendAboutPage( WebServer &server )
{
  server.print("<h>napravio David Blaževi? u suradnji sa Centrom energije</h1>");
}
void sendFormButtons( WebServer &server )
{
  server << "<p><form METHOD='POST' action='" PREFIX "/values'>";
  server.println("<input type=submit value=\"ponovno ucitaj\">");
  server.println("</form></p>");
  server << "<p><form METHOD=POST action='" PREFIX "/about'>";
  server.println("<input type=submit value=\"o senzru\">");
  server.println("</form>");
}
void sendTemperatureValues( WebServer &server )
{
  char temp_string_a[10];
  char temp_string_b[10];
  char temp_string_c[10];
  getCurrentTemp(SENSOR_A, temp_string_a);
  getCurrentTemp(SENSOR_B, temp_string_b);
  getCurrentTemp(SENSOR_C, temp_string_c);
  server.print("Sensor A:");
  server.print(temp_string_a);
  server.print("
");
  server.print("Sensor B:");
  server.print(temp_string_b);
  server.print("
");
  server.print("Sensor C:");
  server.print(temp_string_c);
  delay(1);
  
}
void OneWireReset (int Pin)
{
  digitalWrite (Pin, LOW);
  pinMode (Pin, OUTPUT);        
  delayMicroseconds (500);
  pinMode (Pin, INPUT);
  delayMicroseconds (500);
}
void OneWireOutByte (int Pin, byte d) 
{
  byte n;
  for (n=8; n!=0; n--)
  {
    if ((d & 0x01) == 1)  
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (5);
      pinMode (Pin, INPUT);
      delayMicroseconds (60);
    }
    else
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (60);
      pinMode (Pin, INPUT);
    }
    d = d>>1; 
  }
}
byte OneWireInByte (int Pin) 
{
  byte d, n, b;
  for (n=0; n<8; n++)
  {
    digitalWrite (Pin, LOW);
    pinMode (Pin, OUTPUT);
    delayMicroseconds (5);
    pinMode (Pin, INPUT);
    delayMicroseconds (5);
    b = digitalRead (Pin);
    delayMicroseconds (50);
    d = (d >> 1) | (b<<7); 
  }
  return (d);
}
void getCurrentTemp (int sensorPin, char *temp)
{
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0x44); 
  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0xbe);
  LowByte = OneWireInByte (sensorPin);
  HighByte = OneWireInByte (sensorPin);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  
  if (sign) 
  {
    TReading = (TReading ^ 0xffff) + 1; 
  }
  Tc_100 = (6 * TReading) + TReading / 4;    

  whole = Tc_100 / 100;  
  fract = Tc_100 % 100;
  if (sign) {
    temp[0] = '-';
  } else {
    temp[0] = '+';
  }

  if (whole/100 == 0) {
    temp[1] = ' ';
  } else {
    temp[1] = whole/100+'0';
  }
  temp[2] = (whole-(whole/100)*100)/10 +'0' ;
  temp[3] = whole-(whole/10)*10 +'0';
  temp[4] = '.';
  temp[5] = fract/10 +'0';
  temp[6] = fract-(fract/10)*10 +'0';
  temp[7] = '\0';
}

Which arduino are you using?

I need to save data to an SD card

Your code doesn't have anything which deals with an SD card.

everything I ever tried did not work

What did you try and in what way did it fail?

Pete

using duemilanove
and the original Arduino Mega Compatible Ethernet sheild
i posted original code witouth SD card
Here is the current code with sd card
and as you can see I use DS18B20 sensors

#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
#include <SD.h>
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 177 };
static uint8_t myPort = 80; 
#define PREFIX ""
WebServer webserver( PREFIX, myPort );
#define SENSOR_A  7
#define SENSOR_B  6
#define SENSOR_C  5
File webfile;
void sendTemperatureValues( WebServer &server);
void sendAboutPage( WebServer &server);
void sendFormButtons( WebServer &server);
void valuesCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendTemperatureValues( server );
  sendFormButtons( server );
}


void aboutCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  sendAboutPage( server );
  sendFormButtons( server );
}


void setup(){
  pinMode(4, OUTPUT);
  Serial.begin(9600);
      Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
  webserver.begin();
  webserver.setDefaultCommand( &valuesCmd );
  webserver.addCommand( "values", &valuesCmd );
  webserver.addCommand( "about", &aboutCmd );
  pinMode(10, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(SENSOR_A, LOW);
  pinMode(SENSOR_A, INPUT);
  digitalWrite(SENSOR_B, LOW);
  pinMode(SENSOR_B, INPUT);
  digitalWrite(SENSOR_C, LOW);
  pinMode(SENSOR_C, INPUT);
}
void loop(){
  webserver.processConnection();
}
void sendAboutPage( WebServer &server )
{
  server.print("<h>napravio David Blažević u suradnji sa Centrom energije</h1>");
}


void sendFormButtons( WebServer &server )
{
  server << "<p><form METHOD='POST' action='" PREFIX "/values'>";
  server.println("<input type=submit value=\"ponovno ucitaj\">");
  server.println("</form></p>");
  server << "<p><form METHOD=POST action='" PREFIX "/about'>";
  server.println("<input type=submit value=\"o senzru\">");
  server.println("</form>");
}


void sendTemperatureValues( WebServer &server )
{
  char temp_string_a[10];
  char temp_string_b[10];
  char temp_string_c[10];
  getCurrentTemp(SENSOR_A, temp_string_a);
  getCurrentTemp(SENSOR_B, temp_string_b);
  getCurrentTemp(SENSOR_C, temp_string_c);



  
  server.print("Sensor A:");
  server.print(temp_string_a);
  server.print("
");
  server.print("Sensor B:");
  server.print(temp_string_b);
  server.print("
");
  server.print("Sensor C:");
  server.print(temp_string_c);
  delay(1);
  webfile =SD.open("podci.txt", FILE_WRITE);
  getCurrentTemp(SENSOR_A, temp_string_a);
  getCurrentTemp(SENSOR_B, temp_string_b);
  getCurrentTemp(SENSOR_C, temp_string_c);
  webfile.print("0.00");
  webfile.print(temp_string_a);
  webfile.print(temp_string_b);
  webfile.print(temp_string_c);
  webfile.close ();
  digitalWrite(4, 1);
  digitalWrite(10, 0);
}

void OneWireReset (int Pin)
{
  digitalWrite (Pin, LOW);
  pinMode (Pin, OUTPUT);        
  delayMicroseconds (500);
  pinMode (Pin, INPUT);
  delayMicroseconds (500);
}

void OneWireOutByte (int Pin, byte d) 
{
  byte n;

  for (n=8; n!=0; n--)
  {
    if ((d & 0x01) == 1)  
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (5);
      pinMode (Pin, INPUT);
      delayMicroseconds (60);
    }
    else
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (60);
      pinMode (Pin, INPUT);
    }

    d = d>>1; 
  }
}


byte OneWireInByte (int Pin) 
{
  byte d, n, b;

  for (n=0; n<8; n++)
  {
    digitalWrite (Pin, LOW);
    pinMode (Pin, OUTPUT);
    delayMicroseconds (5);
    pinMode (Pin, INPUT);
    delayMicroseconds (5);
    b = digitalRead (Pin);
    delayMicroseconds (50);
    d = (d >> 1) | (b<<7); 
  }
  return (d);
}



void getCurrentTemp (int sensorPin, char *temp)
{
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0x44); 

  OneWireReset (sensorPin);
  OneWireOutByte (sensorPin, 0xcc);
  OneWireOutByte (sensorPin, 0xbe);

  LowByte = OneWireInByte (sensorPin);
  HighByte = OneWireInByte (sensorPin);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  
  if (sign) 
  {
    TReading = (TReading ^ 0xffff) + 1; 
  }
  Tc_100 = (6 * TReading) + TReading / 4;    

  whole = Tc_100 / 100;  
  fract = Tc_100 % 100;

  if (sign) {
    temp[0] = '-';
  } else {
    temp[0] = '+';
  }

  if (whole/100 == 0) {
    temp[1] = ' ';
  } else {
    temp[1] = whole/100+'0';
  }

  temp[2] = (whole-(whole/100)*100)/10 +'0' ;
  temp[3] = whole-(whole/10)*10 +'0';
  temp[4] = '.';
  temp[5] = fract/10 +'0';
  temp[6] = fract-(fract/10)*10 +'0';
  temp[7] = '\0';

}

I can't even compile your code because I haven't got an ethernet card, so unless you tell me what the code does and doesn't do I can't help you.
But, as far as the SD card is concerned, your code seems to open a file for writing but doesn't write anything to it so that isn't going to get you very far.

Pete

I'm just getting started with SD cards myself and found this tutorial helpful: Tutorial 11 for Arduino: SD Cards and Datalogging – JeremyBlum.com

I would start by writing one number or letter to the card and slowly building from there and adding your code a bit at a time.

Mike

thanks Mike
I know I work with SD cards and complex code
only that now do not write on file on the SD card but not written anything on it
but I think I might know what the problem is I’ll see and I’ll post