Hola, me seria de gran ayuda encontrar la forma de conectar LCD y Reloj juntos, e leído algo sobre que Arduino lea primero uno y luego otro intercaladamente pero no consigo hacerlo.
Gracias de antemano.
Algo así debería valerte
#include <Wire.h> // Reloj
#include <SLCD.h> // Librería de la pantalla LCD
#define WIRE_BUS 0x68
SLCD serialLCD = SLCD( 2, 16 );
// Conversion de datos decimal a hexadecimal
byte decABcd(byte val) {
return ( (val/10*16) + (val%10) );
} // p.ej. 25 -> 37
byte bcdADec(byte val) {
return ( (val/16*10) + (val%16) );
} // p.ej. 37 -> 25
void ponReloj( byte segundo, // 0-59
byte minuto, // 0-59
byte hora, // 1-23
byte diaSem, // 1 Lunes-7 Domingo
byte dia, // 1-28/29/30/31
byte mes, // 1-12
byte anio) // 0-99
{
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.send(decABcd(segundo)); // 0 to bit 7 starts the clock
Wire.send(decABcd(minuto));
Wire.send(decABcd(hora));
Wire.send(decABcd(diaSem));
Wire.send(decABcd(dia));
Wire.send(decABcd(mes));
Wire.send(decABcd(anio));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Toma la fecha y la hora del ds1307
void tomaHora( byte *segundo,
byte *minuto,
byte *hora,
byte *diaSem,
byte *dia,
byte *mes,
byte *anio)
{
// Resetea el registro puntero
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom( WIRE_BUS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*segundo = bcdADec(Wire.receive() & 0x7f);
*minuto = bcdADec(Wire.receive());
*hora = bcdADec(Wire.receive() & 0x3f); // Need to change this if 12 hora am/pm
*diaSem = bcdADec(Wire.receive());
*dia = bcdADec(Wire.receive());
*mes = bcdADec(Wire.receive());
*anio = bcdADec(Wire.receive());
}
void setup() {
Wire.begin();
serialLCD.init();
Serial.begin(9600);
// Si se quiere inicializar el reloj
ponReloj( 0, 0, 12, 5, 4, 4, 14 ) // 12:00 Viernes 4/4/2014
}
void loop() {
byte ss, mm, hh, dS, dd, nn, aa;
long tiempo;
tomaHora( &ss, &nn, &&hh, &dS, &dd, &mm, &aa );
Serial.print( aa, DEC );
Serial.print( "-" );
Serial.print( mm, DEC );
Serial.print( "-" );
Serial.print( dd, DEC );
Serial.print( " " );
Serial.print( &hh, DEC );
Serial.print( ":" );
Serial.println( &nn, DEC );
delay( 5000 ); // Actualiza la hora cada cinco segundos
}
Al cambiar la libreria del LCD (#include <LiquidCrystal_I2C.h>) da error
A ver si así...
#include <Wire.h> // Reloj
#define LIQUID_LCD_ROWS 4 // LCD
#define LIQUID_LCD_COLS 20 // LCD
#define LIQUID_I2C_ADDRESS 0x27 // Liquid Crystal
#define WIRE_BUS 0x68
LiquidCrystal_I2C liquidLCD( LIQUID_I2C_ADDRESS, LIQUID_LCD_COLS, LIQUID_LCD_ROWS );
// Conversion de datos decimal a hexadecimal
byte decABcd(byte val) {
return ( (val/10*16) + (val%10) );
} // p.ej. 25 -> 37
byte bcdADec(byte val) {
return ( (val/16*10) + (val%16) );
} // p.ej. 37 -> 25
void ponReloj( byte segundo, // 0-59
byte minuto, // 0-59
byte hora, // 1-23
byte diaSem, // 1 Lunes-7 Domingo
byte dia, // 1-28/29/30/31
byte mes, // 1-12
byte anio) // 0-99
{
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.send(decABcd(segundo)); // 0 to bit 7 starts the clock
Wire.send(decABcd(minuto));
Wire.send(decABcd(hora));
Wire.send(decABcd(diaSem));
Wire.send(decABcd(dia));
Wire.send(decABcd(mes));
Wire.send(decABcd(anio));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Toma la fecha y la hora del ds1307
void tomaHora( byte *segundo,
byte *minuto,
byte *hora,
byte *diaSem,
byte *dia,
byte *mes,
byte *anio)
{
// Resetea el registro puntero
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom( WIRE_BUS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*segundo = bcdADec(Wire.receive() & 0x7f);
*minuto = bcdADec(Wire.receive());
*hora = bcdADec(Wire.receive() & 0x3f); // Need to change this if 12 hora am/pm
*diaSem = bcdADec(Wire.receive());
*dia = bcdADec(Wire.receive());
*mes = bcdADec(Wire.receive());
*anio = bcdADec(Wire.receive());
}
void setup() {
Wire.begin();
liquidLCD.init();
liquidLCD.display();
liquidLCD.clear();
// Si se quiere la pantalla iluminada descomentar esta línea
// liquidLCD.backlight();
// Si se quiere la pantalla sin iluminar descomentar esta línea
// liquidLCD.noBacklight();
Serial.begin(9600);
// Si se quiere inicializar el reloj
ponReloj( 0, 0, 12, 5, 4, 4, 14 ) // 12:00 Viernes 4/4/2014
}
void loop() {
byte ss, mm, hh, dS, dd, nn, aa;
long tiempo;
tomaHora( &ss, &nn, &&hh, &dS, &dd, &mm, &aa );
Serial.print( aa, DEC );
Serial.print( "-" );
Serial.print( mm, DEC );
Serial.print( "-" );
Serial.print( dd, DEC );
Serial.print( " " );
Serial.print( &hh, DEC );
Serial.print( ":" );
Serial.println( &nn, DEC );
delay( 5000 ); // Actualiza la hora cada cinco segundos
}
Toda esta ristra de errores me da... =( :
sketch_may08a.ino: In function 'void ponReloj(byte, byte, byte, byte, byte, byte, byte)':
sketch_may08a:31: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:32: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:33: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:34: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:35: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:36: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:37: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:38: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:39: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a.ino: In function 'void tomaHora(byte*, byte*, byte*, byte*, byte*, byte*, byte*)':
sketch_may08a:55: error: 'class TwoWire' has no member named 'send'
Desde Arduino 1.0, la función Wire.send() ha sido renombrada Wire.write() para mantener la consistencia con otras librerías.
sketch_may08a:59: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:60: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:61: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:62: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:63: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:64: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a:65: error: 'class TwoWire' has no member named 'receive'
Desde Arduino 1.0, la función Wire.receive() ha sido renombrada Wire.read() para mantener la consistencia con otras librerías.
sketch_may08a.ino: In function 'void setup()':
sketch_may08a:87: error: expected `;' before '}' token
sketch_may08a.ino: In function 'void loop()':
sketch_may08a:95: error: invalid conversion from 'void*' to 'byte*'
sketch_may08a:95: error: initializing argument 3 of 'void tomaHora(byte*, byte*, byte*, byte*, byte*, byte*, byte*)'
sketch_may08a:104: error: call of overloaded 'print(byte*, int)' is ambiguous
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:59: note: candidates are: size_t Print::print(unsigned char, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:60: note: size_t Print::print(int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:61: note: size_t Print::print(unsigned int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:62: note: size_t Print::print(long int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:63: note: size_t Print::print(long unsigned int, int)
sketch_may08a:106: error: call of overloaded 'println(byte*, int)' is ambiguous
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:71: note: candidates are: size_t Print::println(unsigned char, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:72: note: size_t Print::println(int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:73: note: size_t Print::println(unsigned int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:74: note: size_t Print::println(long int, int)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:75: note: size_t Print::println(long unsigned int, int)
sketch_may08a:95: error: label 'hh' used but not defined
Hola Antonio30293
Porque no nos cuentas cual es le modelo de lcd que tienes y cual es el Tinny clock, he visto pocos modelos de RTC pero si se conectan de forma distinta, y lo mismo con las lcd.
Mira la marca que tiene el Integrado y escribe el modelo.
//---
Yo me imagino que los dos son I2C; y si el arduino primero lee uno y después el otro, tan rápido que no se nota.
La lcd es QC2004A con adaptador para conexión I2C y el reloj es Tiny RTC I2C modules.
OK
Mira yo por ejemplo tengo un modulo RTC con el integrado DS1307 y un lcd 1602 con un backpack que tiene el integrado PCF8574T y este transforma el lcd a i2c; también es compatible con un lcd 2004
Utilizo la libreria LiquidCrystal_I2C.h
Te dejo el código base que tengo para esto, tendrás que ajustarlo a tu pantalla si es necesario.
/*https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads*/
#define DS1307_ADDRESS 0x68
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity
void setup()
{
Wire.begin();
Serial.begin(9600);
lcd.begin(16,2); // Inicia el lcd con 2 renglones y 16 columnas
}
void loop()
{
printDia();
delay(1000);
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDia(){
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
switch(weekDay)
{
case 0:
lcd.setCursor(0,0);
lcd.print("Sun ");
break;
case 1:
lcd.setCursor(0,0);
lcd.print("Mon ");
break;
case 2:
lcd.setCursor(0,0);
lcd.print("Tues ");
break;
case 3:
lcd.setCursor(0,0);
lcd.print("Wed ");
break;
case 4:
lcd.setCursor(0,0);
lcd.print("Thurs ");
break;
case 5:
lcd.setCursor(0,0);
lcd.print("Fri ");
break;
case 6:
lcd.setCursor(0,0);
lcd.print("Sat ");
break;
}
lcd.print(monthDay);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(year);
lcd.setCursor(0,1);
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
lcd.setCursor(9,1);
lcd.print("Temp");
delay(1000);
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}
GRACIAS! ![]()
Ajustándolo un poco me a servido!!
Excelente
Ahora solo queda modificar lo para que ajuste a tu proyecto, si es necesario jejeje.
saludos.
Hola amigos!
Podríais subir un esquema de conexiones, o explicarlo un poco?
Estoy diseñando un dispensador de comida para perros, pudiendo elegir la hora deseada.
Muchas gracias y un saludo