need help replacing ds3017 with ds3231
i got 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' not declared in scope
jarduino_v1_1:669: error: expected `)' before 'l'
jarduino_v1_1:669: error: expected `)' before ';' token
jarduino_v1_1.cpp: @ 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' not declared in scope
jarduino_v1_1:3191: error: 'rtc' not declared in scope
jarduino_v1_1:3209: error: 'rtc' not declared in scope
jarduino_v1_1:3227: error: 'rtc' not declared in scope
jarduino_v1_1.cpp: in function 'void processmytouch()':
jarduino_v1_1:3434: error: 'savertc' not declared in 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()' defined here
jarduino_v1_1:4561: error: 'rtc' not declared in 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()' defined here
jarduino_v1_1:4601: error: 'rtc' not declared in scope
and code used
#include "wire.h"
#define ds3231_i2c_address 16x2
// convert normal decimal numbers binary coded decimal
byte dectobcd(byte val)
{
return( (val/10*16) + (va l%10) );
}
// convert binary coded decimal normal decimal numbers
byte bcdtodec(byte val)
{
return( (val/16*10) + (val%16) );
}
void setup()
{
wire.begin();
serial.begin(9600);
// set 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 , date data ds3231
wire.begintransmission(ds3231_i2c_address);
wire.write(0); // set next input start @ 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 31)
wire.write(dectobcd(7)); // set month
wire.write(dectobcd(16)); // set year (0 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 00h
wire.endtransmission();
wire.requestfrom(ds3231_i2c_address, 7);
// request 7 bytes of data ds3231 starting 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 ds3231
readds3231time(&second, &minute, &hour, &dayofweek, &dayofmonth, &month,
&year);
// send serial monitor
serial.print(hour, dec);
// convert byte variable 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 real-time clock data on serial monitor,
delay(1000); // every second
need please
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' not declared in scope
jarduino_v1_1:669: error: expected `)' before 'l'
jarduino_v1_1:669: error: expected `)' before ';' token
jarduino_v1_1.cpp: @ 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' not declared in scope
jarduino_v1_1:3191: error: 'rtc' not declared in scope
jarduino_v1_1:3209: error: 'rtc' not declared in scope
jarduino_v1_1:3227: error: 'rtc' not declared in scope
jarduino_v1_1.cpp: in function 'void processmytouch()':
jarduino_v1_1:3434: error: 'savertc' not declared in 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()' defined here
jarduino_v1_1:4561: error: 'rtc' not declared in 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()' defined here
jarduino_v1_1:4601: error: 'rtc' not declared in scope
and code used
#include "wire.h"
#define ds3231_i2c_address 16x2
// convert normal decimal numbers binary coded decimal
byte dectobcd(byte val)
{
return( (val/10*16) + (va l%10) );
}
// convert binary coded decimal normal decimal numbers
byte bcdtodec(byte val)
{
return( (val/16*10) + (val%16) );
}
void setup()
{
wire.begin();
serial.begin(9600);
// set 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 , date data ds3231
wire.begintransmission(ds3231_i2c_address);
wire.write(0); // set next input start @ 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 31)
wire.write(dectobcd(7)); // set month
wire.write(dectobcd(16)); // set year (0 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 00h
wire.endtransmission();
wire.requestfrom(ds3231_i2c_address, 7);
// request 7 bytes of data ds3231 starting 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 ds3231
readds3231time(&second, &minute, &hour, &dayofweek, &dayofmonth, &month,
&year);
// send serial monitor
serial.print(hour, dec);
// convert byte variable 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 real-time clock data on serial monitor,
delay(1000); // every second
need please
first replace 16x2 16*2 if intention.
Arduino Forum > Using Arduino > Programming Questions > need help replacing ds3017 with ds3231
arduino
Comments
Post a Comment