Hello, I'm Santiago and I'm looking for an answer to a problem, I was doing a project with a rtc 1302 and a lcd with an I2C and it does not detect the threeWire MyWire code, so you can tell me how to solve it postscript: the problem is in the code, not in the connection.
Don’t you think it will help if you would actually share the code?
And how do you know it’s not the circuit?
PS: I moved your post to a more suitable forum. do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).
ok sorry, the code is
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//SE AGREGA LIBRERÍAS PARA RTC
#include <ThreeWire.h>
#include <RtcDS1302.h>
ThreeWire myWire(4,5,2); // IO, SCLK, CE
RtcDS1302 Rtc(myWire);
void setup ()
{
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
{
// Common Causes:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
Rtc.SetDateTime(compiled);
}
if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}
if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
}
void loop ()
{
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();
if (!now.IsValid())
{
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}
delay(10000); // ten seconds
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}
#include <ThreeWire.h>
#include <RtcDS1302.h>
//SE CREA Y CONFIGURA OBJETO PARA MANEJAR RTC
ThreeWire myWire(4,5,2); // IO, SCLK, CE
RtcDS1302 Rtc(myWire);
void setup () {
// SE INICAR MONITOR SERIE E IMPRIME FECHA Y HORA
Serial.begin(57600);
Serial.print("CONFIGURACIÓN INICIAL ");
Serial.print(DATE);
Serial.println(TIME);
lcd.begin(16,2); //SE INICIARLIZA LCD
Rtc.Begin();// SE INICIALIZA RTC
RtcDateTime compiled = RtcDateTime(DATE, TIME);//SE CONFIGURA FECHA Y HORA ACTUAL
printDateTime(compiled); //SE IMPRIME FECHA Y HORA
Rtc.SetDateTime(compiled);
Serial.println();
}
void loop () {
//SE OBTENIE FECHA Y HORA ACTUAL Y SE ACTUALIZA
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();
if (!now.IsValid()){
Serial.println("ERROR EN FECHA Y HORA");
}
delay(1000);
//RETARDO DE 1 SEGUNDO
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
//FUNCION PARA IMPRIMIR FECHA Y HORA CON FORMATO ADECUADO
void printDateTime(const RtcDateTime& dt){
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),//SE CONFURA FORMATO DE FECHA Y HORA
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
//SE IMPRIME LA FECHA Y HORA EN LCD
lcd.setCursor(0,0);
lcd.print("DATE ");
lcd.print(dt.Month());
lcd.print("/");
lcd.print(dt.Day());
lcd.print("/");
lcd.print(dt.Year());
lcd.print(" ");
lcd.setCursor(0,14);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("TIME ");
lcd.print(dt.Hour());
lcd.print(":");
lcd.print(dt.Minute());
lcd.print(":");
lcd.print(dt.Second());
lcd.print(" ");
Serial.print(datestring);//SE IMPRIME EN MONITOR SERIE
}
sorry I'm new to this forum
" it does not detect the threeWire MyWire code "
What does this mean? Do you get an error? If you do, can you post it as my crystal ball is in for a service.
You also have 2 setup & 2 loop - NOT allowed.
English please, or go to the Spanish section.
thanks for you help friend , i solved that problem
Post how you solved the problem for others, it may help them.
New is not an excuse for not reading and applying the rules … please add code tags
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.