Combining Sketches

Hi, I have this code by ZoomKat.

It works fine so far.

I want to now add an ds1307 rtc: http://compare.ebay.com/like/230584918558?var=lv&ltyp=AllFixedPriceItemTypes&var=sbar&rvr_id=211542956240&crlp=1_263602_309572&UA=%3F*F%3F&GUID=3b73156d12e0a0aa16e46b44ff7e7126&itemid=230584918558&ff4=263602_309572

How can I combine a code that runs the RTC with my other code below:

//zoomkat 12-22-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x22, 0x8A };
byte ip[] = { 192, 168, 0, 104 };
byte server[] = { 97, 74, 166, 239 };

Client client(server, 80);

void setup()
{
  byte gateway[] = { 192, 168, 0, 1 };
  Ethernet.begin(mac, ip, gateway); 
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /processedfeed.aspx?feedcode=%5Bbc_u1%5Dhttp%253A//pipes.yahoo.com/pipes/pipe.run%253F_id%253D6d2c0b97b3c18eba6be661489a35c9c3%2526_render%253Drss%5B/bc_u1%5D%5Bbc_m1%5D3%5B/bc_m1%5D%5Bbc_o%5D0%5B/bc_o%5D HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    readString += c;
  }

  if (!client.connected()) {
     client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

    }
 }

Here is the RTC Code:

/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
   digitalClockDisplay();  
   delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Thanks...

How can I combine a code that runs the RTC with my other code below:

Now that all depends on what you want to do with the data from the RTC, doesn't it?

Well, Paul, I now actually want to use ntp and display everything on a some 0832 Matrices by Sure Electronics.

I got the RTC up and running. Now all I havve to do is combine the following RTC code with the code in the first post:

/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
   digitalClockDisplay();  
   delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Can someone at least point me in the right direction?

Sure.
Put the stuff that goes before setup with the other stuff that is before setup.
Put the stuff that is in setup in with the setup stuff.
Put the void loop code (the little there is) in void loop.
Put the other functions after the void loop.

Check for duplicate use of pins, variable names Serial.begin at different speeds, etc.

Should not be too difficult.

I am terrible at this, Here it is in a non working state:

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> 
#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;
int rtc[7];
byte data[56];
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x22, 0x8A };
byte ip[] = { 192, 168, 0, 104 };
byte server[] = { 97, 74, 166, 239 };
Client client(server, 80);
Serial.begin(9600);
  
  RTC.stop();
  RTC.set(DS1307_HR,10);
  RTC.set(DS1307_MIN,34);
  RTC.set(DS1307_SEC,1);
  RTC.set(DS1307_MTH,2);
  RTC.set(DS1307_DATE,18);
  RTC.set(DS1307_YR,11);
  RTC.start();
  
  for(int i=0; i<56; i++)
  
  {
    RTC.set_sram_byte(65,i);
  }
  byte gateway[] = { 192, 168, 0, 1 };
  Ethernet.begin(mac, ip, gateway); 
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /processedfeed.aspx?feedcode=%5Bbc_u1%5Dhttp%253A//pipes.yahoo.com/pipes/pipe.run%253F_id%253D6d2c0b97b3c18eba6be661489a35c9c3%2526_render%253Drss%5B/bc_u1%5D%5Bbc_m1%5D3%5B/bc_m1%5D%5Bbc_o%5D0%5B/bc_o%5D HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
      }

}

void loop()
{
  RTC.get(rtc,true);

  for(int i=0; i<7; i++)
  {
    Serial.print(rtc[i]);
    Serial.print(" ");
  }
  Serial.println();
  Serial.print(RTC.min_of_day(true));  
  Serial.println();
  delay(1000);
  //RTC.get_data(data);
  //for(int i=0; i<56; i++)
  //{
    //Serial.print(data[i]);
    //Serial.print(" ");
  //}
  
  Serial.print(RTC.get_sram_byte(29));
  Serial.println();
  
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    readString += c;
  }

  if (!client.connected()) {
     client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

    }
 }

I get this error message:

Combined:5: error: expected constructor, destructor, or type conversion before '.' token
Combined:17: error: expected constructor, destructor, or type conversion before '.' token
Combined:18: error: expected constructor, destructor, or type conversion before '.' token
Combined:19: error: expected constructor, destructor, or type conversion before '.' token
Combined:20: error: expected constructor, destructor, or type conversion before '.' token
Combined:21: error: expected constructor, destructor, or type conversion before '.' token
Combined:22: error: expected constructor, destructor, or type conversion before '.' token
Combined:23: error: expected constructor, destructor, or type conversion before '.' token
Combined:24: error: expected constructor, destructor, or type conversion before '.' token
Combined:26: error: expected unqualified-id before 'for'
Combined:26: error: expected constructor, destructor, or type conversion before '<' token
Combined:26: error: expected constructor, destructor, or type conversion before '++' token
Combined:32: error: expected constructor, destructor, or type conversion before '.' token
Combined:33: error: expected constructor, destructor, or type conversion before '.' token
Combined:34: error: expected constructor, destructor, or type conversion before '.' token
Combined:35: error: expected constructor, destructor, or type conversion before '.' token
Combined:37: error: expected unqualified-id before 'if'
Combined:41: error: expected unqualified-id before 'else'
Combined:45: error: expected declaration before '}' token

  RTC.stop();
  RTC.set(DS1307_HR,10);
  RTC.set(DS1307_MIN,34);
  RTC.set(

This stuff needs to be in a function.
Probably a function called setup.

Sorry for the trouble, but how do I do that?

void setup()
{
// your code goes in here
}

Yeah, you left
void setup(){

}
out
Probably put it before Serial.begin

Now with this:

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> 
#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;
int rtc[7];
byte data[56];
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x00, 0x22, 0x8A };
byte ip[] = { 
  192, 168, 0, 104 };
byte server[] = { 
  97, 74, 166, 239 };
Client client(server, 80);
void setup()
{


  RTC.stop();
  RTC.set(DS1307_HR,10);
  RTC.set(DS1307_MIN,34);
  RTC.set(DS1307_SEC,1);
  RTC.set(DS1307_MTH,2);
  RTC.set(DS1307_DATE,18);
  RTC.set(DS1307_YR,11);
  RTC.start();

  for(int i=0; i<56; i++)

  {
    RTC.set_sram_byte(65,i);
  }
  byte gateway[] = { 
    192, 168, 0, 1     };
  Ethernet.begin(mac, ip, gateway); 
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /processedfeed.aspx?feedcode=%5Bbc_u1%5Dhttp%253A//pipes.yahoo.com/pipes/pipe.run%253F_id%253D6d2c0b97b3c18eba6be661489a35c9c3%2526_render%253Drss%5B/bc_u1%5D%5Bbc_m1%5D3%5B/bc_m1%5D%5Bbc_o%5D0%5B/bc_o%5D HTTP/1.0");
    client.println();
  } 
  else {
    Serial.println("connection failed");
  }
}

Serial.begin(9600);


void loop()
{
  RTC.get(rtc,true);

  for(int i=0; i<7; i++)
  {
    Serial.print(rtc[i]);
    Serial.print(" ");
  }
  Serial.println();
  Serial.print(RTC.min_of_day(true));  
  Serial.println();
  delay(1000);
  //RTC.get_data(data);
  //for(int i=0; i<56; i++)
  //{
  //Serial.print(data[i]);
  //Serial.print(" ");
  //}

  Serial.print(RTC.get_sram_byte(29));
  Serial.println();

  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    readString += c;
  }

  if (!client.connected()) {
    client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

  }
}

I only get one error,
Combined:52: error: expected constructor, destructor, or type conversion before '.' token

You need Serial.begin within void setup, back before you start the print statements.

Serial.begin(9600);

Maybe this should be in a function.

Like This?

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> 
#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;
int rtc[7];
byte data[56];
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x00, 0x22, 0x8A };
byte ip[] = { 
  192, 168, 0, 104 };
byte server[] = { 
  97, 74, 166, 239 };
Client client(server, 80);
void setup()
{
  Serial.begin(9600);
  RTC.stop();
  RTC.set(DS1307_HR,10);
  RTC.set(DS1307_MIN,34);
  RTC.set(DS1307_SEC,1);
  RTC.set(DS1307_MTH,2);
  RTC.set(DS1307_DATE,18);
  RTC.set(DS1307_YR,11);
  RTC.start();
  for(int i=0; i<56; i++)

  {
    RTC.set_sram_byte(65,i);
  }
  byte gateway[] = { 
    192, 168, 0, 1     };
  Ethernet.begin(mac, ip, gateway); 
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /processedfeed.aspx?feedcode=%5Bbc_u1%5Dhttp%253A//pipes.yahoo.com/pipes/pipe.run%253F_id%253D6d2c0b97b3c18eba6be661489a35c9c3%2526_render%253Drss%5B/bc_u1%5D%5Bbc_m1%5D3%5B/bc_m1%5D%5Bbc_o%5D0%5B/bc_o%5D HTTP/1.0");
    client.println();
  } 
  else {
    Serial.println("connection failed");
  }
}



void loop()
{
  RTC.get(rtc,true);

  for(int i=0; i<7; i++)
  {
    Serial.print(rtc[i]);
    Serial.print(" ");
  }
  Serial.println();
  Serial.print(RTC.min_of_day(true));  
  Serial.println();
  delay(1000);
  //RTC.get_data(data);
  //for(int i=0; i<56; i++)
  //{
  //Serial.print(data[i]);
  //Serial.print(" ");
  //}

  Serial.print(RTC.get_sram_byte(29));
  Serial.println();

  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    readString += c;
  }

  if (!client.connected()) {
    client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

  }
}

I believe so.

That gives me this:
C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp:30:19: error: types.h: No such file or directory
In file included from C:\Users\Christopher\Documents\arduino-0022\libraries\SPI/SPI.h:15,
from C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\utility/w5100.h:14,
from C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp:31:
C:\Users\Christopher\Documents\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:18: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
C:\Users\Christopher\Documents\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:17: error: previous declaration 'uint16_t makeWord(uint16_t)' here
C:\Users\Christopher\Documents\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:28: error: declaration of C function 'long int random(long int)' conflicts with
c:/users/christopher/documents/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
C:\Users\Christopher\Documents\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:29: error: declaration of C function 'long int random(long int, long int)' conflicts with
C:\Users\Christopher\Documents\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:28: error: previous declaration 'long int random(long int)' here
C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp: In member function 'void UdpBytewiseClass::begin(uint16_t)':
C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp:46: error: 'Sn_MR_UDP' was not declared in this scope
C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp: In member function 'int UdpBytewiseClass::available()':
C:\Users\Christopher\Documents\arduino-0022\libraries\Ethernet\UdpBytewise.cpp:55: error: 'getSn_RX_RSR' was not declared in this scope

So why didn't you try asking the compiler before asking us?

That seems to have gotten worse then.
I can only compile a little because I don't have the libraries installed. This looke like missing library errors to me.