-->
Page 1 of 2

Default SDA and SCL pins on NodeMCU V1.0

PostPosted: Sun Jun 12, 2016 3:35 am
by lotus49
I am trying to get a DS3231 RTC to work with Makuna's DS3231 RTC library (https://github.com/Makuna/Rtc.git). The library does support the ESP8266.

I am decidedly unsure as to which pins I should be using and I have read different things that say I should be using GPIO4 and 5 or pins 4 and 5 (ie GPIO2 and 14). I have tried both and just get the following output when I run Makuna's DS3231_Simple sketch.

Code: Select allRTC lost confidence in the DateTime!
85/165/2009 37:165:
-3.31C


I like the cold but it's a lot warmer than that in my sitting room where I am at the moment so my ESP8266 does not appear to be communicating properly with my DS3231.

I am using the Arduino IDE. As far as I can tell, the library initialises the I2C bus on the default pins (ie whatever the Arduino IDE defines the constants SDA and SCL as).

Any help would be very much appreciated.

Re: Default SDA and SCL pins on NodeMCU V1.0

PostPosted: Sun Jun 12, 2016 8:39 am
by martinayotte
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);

Re: Default SDA and SCL pins on NodeMCU V1.0

PostPosted: Sun Jun 12, 2016 1:04 pm
by lotus49
I understand now and I found the pins_arduino.h file (which was in ~/.arduino15/packages/esp8266/hardware/esp8266/2.2.0/variants/nodemcu on my Ubuntu laptop).

Unfortunately it still doesn't work so my problem must lie elsewhere. I'll do some more digging and create another thread if I am unable to work out what is wrong.

Thank you for your help.

Re: Default SDA and SCL pins on NodeMCU V1.0

PostPosted: Wed Jul 13, 2016 11:19 am
by lucascastorina
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=0


The 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.
}