- Wed Jul 13, 2016 11:19 am
#50699
martinayotte wrote:The default pins are defined in variants/nodemcu/pins_arduino.h as SDA=4 and SCL=5, but those are not pins number but GPIO number, so since the pins are D1=5 and D2=4.
Anyway, you can also choose the pins yourself using the I2C constructor Wire.begin(int sda, int scl);
I think that i have similar PROBLEMS:
I am doing a little project with the development board esp8266-12E and a RTC tiny ds1307.
I want to program the esp8266 to watch the real time in the serial monitor but it always shows me:
DATE: 0/0/0 TIME: 0:0:0.
I am programming this with the arduino ide a esp libraries for nomeMCU board.
I have tried the same program with a ARDUINO UNO and it functions very good, but changing to the development board esp8266-
12E continue to show zeros.
I also run the SCAN I2C program to see if pin D1(gpio05)-->SCL and D2(gpio04)-->SDA were incorrects and the program responds
CONECTION 1 on IP address is 0x50.
I think that this is the RTCmemory because i expect to have a 0x68 (RTC address).
LIR2032 Battery is OK
Vcc from the RTC clock is OK
Please if you know how to make it function tell me ...i have been working on it but in all this week I could not reach the
goal.
Thank you very much
DOWNLOAD PROGRAMS USED
https://www.dropbox.com/s/yptxukj07zy21 ... s.rar?dl=0The main program is:
//PINES esp826612e D1-->SCL, D2-->SDA
#include <Wire.h>
// Declaracion de las variables para almacenar informacion de tiempo
uint8_t second, minute, hour, wday, day, month, year, ctrl;
#define DS1307_I2C_ADDRESS 0x68 // each I2C object has a unique bus address, the DS1307 is 0x68
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
delay(1000);
// Leer los registros del RTC
read_ds1307();
// Mostrar la fecha y hora
print_time();
}
bool read_ds1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0x00);
if(Wire.endTransmission() != 0)
return false;
Wire.requestFrom(DS1307_I2C_ADDRESS, 8);
second = bcd2bin(Wire.read());
minute = bcd2bin(Wire.read()); // Continuamos recibiendo cada uno de los registros
hour = bcd2bin(Wire.read());
wday = bcd2bin(Wire.read());
day = bcd2bin(Wire.read());
month = bcd2bin(Wire.read());
year = bcd2bin(Wire.read());
ctrl = Wire.read();
}
uint8_t bcd2bin(uint8_t bcd)
{
// Convertir decenas y luego unidades a un numero binario
return (bcd / 16 * 10) + (bcd % 16);
}
void print_time()
{
Serial.print("Fecha: ");
Serial.print(day);
Serial.print('/');
Serial.print(month);
Serial.print('/');
Serial.print(year);
Serial.print(" Hora: ");
Serial.print(hour);
Serial.print(':');
Serial.print(minute);
Serial.print(':');
Serial.print(second);
Serial.println();
}
THE SCANNING PROGRAM IS:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(3000); // wait 5 seconds for next scan
}
And to set the hour correctly i use a arduino uno and this program:
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;
void setup () {
Wire.begin(); // Inicia el puerto I2C
RTC.begin(); // Inicia la comunicación con el RTC
RTC.adjust(DateTime(__DATE__, __TIME__)); // Establece la fecha y hora del momento de subir el archivo
Serial.begin(9600); // Establece la velocidad de datos del puerto serie
}
void loop () {
DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
Serial.print(now.year(), DEC); // Año
Serial.print(' ');
Serial.print('/');
Serial.print(' ');
Serial.print(now.month(), DEC); // Mes
Serial.print(' ');
Serial.print('/');
Serial.print(' ');
Serial.print(now.day(), DEC); // Dia
Serial.print(' ');
Serial.print(' ');
Serial.print(' ');
Serial.print(now.hour(), DEC); // Horas
Serial.print(':');
Serial.print(now.minute(), DEC); // Minutos
Serial.print(':');
Serial.print(now.second(), DEC); // Segundos
Serial.println();
delay(500); // La información se actualiza cada 1 seg.
}