need help replacing ds3017 with ds3231

i got this error messege

Jarduino_v1_1.cpp:745:26: error: invalid suffix "x2" on integer constant
Jarduino_v1_1.cpp:764:26: error: invalid suffix "x2" on integer constant
Jarduino_v1_1.cpp:767:20: error: invalid suffix "x2" on integer constant
Jarduino_v1_1:39: error: variable or field 'setDS3231time' declared void
Jarduino_v1_1.cpp: In function 'byte decToBcd(byte)':
Jarduino_v1_1:669: error: 'va' was not declared in this scope
Jarduino_v1_1:669: error: expected )' before 'l' Jarduino_v1_1:669: error: expected )' before ';' token
Jarduino_v1_1.cpp: At global scope:
Jarduino_v1_1:684: error: variable or field 'setDS3231time' declared void
Jarduino_v1_1.cpp: In function 'void readDS3231time(byte*, byte*, byte*, byte*, byte*, byte*, byte*)':
Jarduino_v1_1:707: error: 'class TwoWire' has no member named 'write'
Jarduino_v1_1:711: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:712: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:713: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:714: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:715: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:716: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:717: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1.cpp: In function 'void feedingTimeOutput()':
Jarduino_v1_1:3173: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3191: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3209: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3227: error: 'RTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void processMyTouch()':
Jarduino_v1_1:3434: error: 'SaveRTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void setup()':
Jarduino_v1_1:4516: error: redefinition of 'void setup()'
Jarduino_v1_1:676: error: 'void setup()' previously defined here
Jarduino_v1_1:4561: error: 'RTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void loop()':
Jarduino_v1_1:4572: error: redefinition of 'void loop()'
Jarduino_v1_1:771: error: 'void loop()' previously defined here
Jarduino_v1_1:4601: error: 'RTC' was not declared in this scope

and this is the code i used

#include "Wire.h"
#define DS3231_I2C_ADDRESS 16x2
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return( (val/1016) + (va l%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16
10) + (val%16) );
}
void setup()
{
Wire.begin();
Serial.begin(9600);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
//setDS3231time(30,42,21,4,26,11,14);
}
void setDS3231time(30,42,21,4,26,11,14)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(40)); // set seconds
Wire.write(decToBcd(25)); // set minutes
Wire.write(decToBcd(9)); // set hours
Wire.write(decToBcd(5)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(17)); // set date (1 to 31)
Wire.write(decToBcd(7)); // set month
Wire.write(decToBcd(16)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// send it to the serial monitor
Serial.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Serial.print(":");
if (minute<10)
{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print("0");
}
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day of week: ");
switch(dayOfWeek){
case 1:
Serial.println("Sunday");
break;
case 2:
Serial.println("Monday");
break;
case 3:
Serial.println("Tuesday");
break;
case 4:
Serial.println("Wednesday");
break;
case 5:
Serial.println("Thursday");
break;
case 6:
Serial.println("Friday");
break;
case 7:
Serial.println("Saturday");
break;
}
}
void loop()
{
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second

need you help please

First replace 16x2 with 16*2 if that is your intention.

KeithRB:
First replace 16x2 with 16*2 if that is your intention.

ok thank you done

 #define DS3231_I2C_ADDRESS 16*2
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (va  l%10) );
}

but i still got alot of errors

Jarduino_v1_1:39: error: variable or field 'setDS3231time' declared void
Jarduino_v1_1.cpp: In function 'byte decToBcd(byte)':
Jarduino_v1_1:669: error: 'va' was not declared in this scope
Jarduino_v1_1:669: error: expected )' before 'l' Jarduino_v1_1:669: error: expected )' before ';' token
Jarduino_v1_1.cpp: At global scope:
Jarduino_v1_1:684: error: variable or field 'setDS3231time' declared void
Jarduino_v1_1.cpp: In function 'void readDS3231time(byte*, byte*, byte*, byte*, byte*, byte*, byte*)':
Jarduino_v1_1:707: error: 'class TwoWire' has no member named 'write'
Jarduino_v1_1:711: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:712: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:713: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:714: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:715: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:716: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:717: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1.cpp: In function 'void feedingTimeOutput()':
Jarduino_v1_1:3173: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3191: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3209: error: 'RTC' was not declared in this scope
Jarduino_v1_1:3227: error: 'RTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void processMyTouch()':
Jarduino_v1_1:3434: error: 'SaveRTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void setup()':
Jarduino_v1_1:4516: error: redefinition of 'void setup()'
Jarduino_v1_1:676: error: 'void setup()' previously defined here
Jarduino_v1_1:4561: error: 'RTC' was not declared in this scope
Jarduino_v1_1.cpp: In function 'void loop()':
Jarduino_v1_1:4572: error: redefinition of 'void loop()'
Jarduino_v1_1:771: error: 'void loop()' previously defined here
Jarduino_v1_1:4601: error: 'RTC' was not declared in this scope

can you help me please

gendiaaa:
need you help please

fix all the mistakes in your code, i.e. I2C address of the RTC module
For example: Instead of

#define DS3231_I2C_ADDRESS 16x2

better use

#define DS3231_I2C_ADDRESS 0x68

jurs:
fix all the mistakes in your code, i.e. I2C address of the RTC module
For example: Instead of

#define DS3231_I2C_ADDRESS 16x2

better use

#define DS3231_I2C_ADDRESS 0x68

i fixed that already and for that error
Jarduino_v1_1:707: error: 'class TwoWire' has no member named 'write'
Jarduino_v1_1:711: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:712: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:713: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:714: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:715: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:716: error: 'class TwoWire' has no member named 'read'
Jarduino_v1_1:717: error: 'class TwoWire' has no member named 'read'

i tried to change the wire library

with that one

but i got that erorr

In file included from Jarduino_v1_1.cpp:77:
C:\arduino-0022\libraries\Wire/Wire.h:56: error: conflicting return type specified for 'virtual size_t TwoWire::write(uint8_t)'
C:\arduino-0022\hardware\arduino\cores\arduino/Print.h:40: error: overriding 'virtual void Print::write(uint8_t)'
C:\arduino-0022\libraries\Wire/Wire.h:57: error: conflicting return type specified for 'virtual size_t TwoWire::write(const uint8_t*, size_t)'
C:\arduino-0022\hardware\arduino\cores\arduino/Print.h:42: error: overriding 'virtual void Print::write(const uint8_t*, size_t)'

i do not understand what is that mean i am not advanced in c programming but all i need that i have code written and this code they used the ds1307 and i want to replace it with ds3231

You had 4 errors in the code which I have fixed. It compiles with my library installation of Wire.h
I have not run it.

  1. i2c address 0x68
  2. typo in line of decToBcd function
  3. improper definition of setDS3231times() input parameters
  4. lack of closing bracket
#include "Wire.h"
//
//#define DS3231_I2C_ADDRESS 16x2
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  //return( (val/10*16) + (va  l%10) );
  return( (val/10*16) + (val%10) ); //fix typo
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  //setDS3231time(30,42,21,4,26,11,14);
}
//void setDS3231time(30,42,21,4,26,11,14)
void setDS3231time(byte seconds,byte minutes, byte hours, byte day, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(40)); // set seconds
  Wire.write(decToBcd(25)); // set minutes
  Wire.write(decToBcd(9)); // set hours
  Wire.write(decToBcd(5)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(17)); // set date (1 to 31)
  Wire.write(decToBcd(7)); // set month
  Wire.write(decToBcd(16)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
}
void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second

}//add closing bracket

i have code written and this code they used the ds1307 and i want to replace it with ds3231

You don't need to change the code, you can use it as it is.

DS3231 has no NVRAM like DS1307, might need some tweaking for that.

Nick_Pyner:
You don't need to change the code, you can use it as it is.

i can not use it as its

gendiaaa:
i can not use it as its

Did you try the corrected code that cattledog provided in reply #5?

It compiles fine for UNO and Mega2560. (IDE V1.6.5)

gendiaaa:
i can not use it as its

This is what I use http://bildr.org/2011/03/ds1307-arduino/ and looks rather like what you originally had - minus the mistakes. It works fine with both modules.