-->
Page 1 of 1

ESP8266 basic I2C Exmp

PostPosted: Mon Nov 28, 2016 12:05 pm
by manolotarr
Hola amigos,
Ejemplo de uso del módulo ESP8266 basic para controlar periféricos I2C: RTC, 2x I2C LCD.
Saludos. Manolo
https://youtu.be/bAA2Hnxggm8

Re: ESP8266 basic I2C Exmp

PostPosted: Fri Dec 02, 2016 3:50 am
by manolotarr
Hello guys, here is the code for the small example.
Anyone know where I find the complete description of the classes of the specific libraries: ESP8266WiFi, ESP8266WebServer, ...??


/*Manolo Amores Nov 2016 lcdi2c_b.ino
email: mam@tinet.org
Comunicacion bus I2C ESP8266 Basic
Gpio_0 es SDA GPIO_2 es SCL
RTC DS1307 I2C add 0x68
Saludos desde Tarragona, Catalonia, Spain, Eurp...
*/
#include <Wire.h>
#include <SparkFunDS1307RTC.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,2);
LiquidCrystal_I2C lcd1(0x26,20,4);

int sec=0, sec5=0;
boolean fl=0, fl1=0;
//======================================
void setup()
{
Wire.begin(0,2);//ESP8266BAS GPIO_0 SDA
//ESP8266BAS GPIO_2 SDL
rtc.begin();

lcd.init();
delay(50);
lcd.clear();
lcd.backlight();
lcd.print("M. Amores 2016");
lcd.setCursor ( 0, 1 );
lcd.print("ESP8266 I2C");

lcd1.init();
delay(50);
lcd1.clear();
lcd1.backlight();
lcd1.print(" M. Amores 2016");
lcd1.setCursor ( 0, 1 );
lcd1.print("ESP8266basicI2C Exmp");

delay (2000);
lcd.clear();

//rtc.setTime(00,02,14,2,28,11,16);
//delay(50);
//rtc.set12Hour();

}
//=====================================
void loop()
{
static int8_t lastSecond = -1;
rtc.update();
sec=rtc.second();
if (sec != lastSecond)
{
printTime();
lastSecond=rtc.second();
sec5++;
lcd1.setCursor(19,0);
lcd1.print(3-sec5);
}
if (sec5==3)
{
sec5=0;
printlcd1();
}

}
//=======================================
void printTime()
{
lcd.setCursor(0,0);//primera fila LCD 20x2
if (rtc.hour() < 10) lcd.print('0');
lcd.print(String(rtc.hour()) + ":");
if (rtc.minute() < 10) lcd.print('0');
lcd.print(String(rtc.minute()) + ":");
if (rtc.second() < 10) lcd.print('0');
lcd.print(String(rtc.second()));
if (rtc.is12Hour())
{
if (rtc.pm()) lcd.print(" PM "); // Returns true if PM
else lcd.print(" AM ");
}
if (!fl)
{
lcd.print(" RTC I2C");
fl=1;
}
else
{
lcd.print(" ");
fl=0;
}

lcd.setCursor ( 0, 1 );//segunda fila LCD 20x2
String strn=rtc.dayStr();
lcd.print(strn.substring(0,3));
//lcd.print(rtc.dayStr());
//lcd.print(rtc.dayC()); // Print day character
//lcd.print(rtc.day()); // Print day integer (1-7, Sun-Sat)
lcd.print(" ");
lcd.print(String(rtc.date()) + "/" +
String(rtc.month()) + "/20");
lcd.print(String(rtc.year()));

}
//==========================================
void printlcd1()
{
lcd1.setCursor ( 0, 2 );
if (!fl1)
{
lcd1.print(" As easy as: ");
lcd1.setCursor ( 0, 3 );
lcd1.print(" Wire.begin(0,2) ");
fl1=1;
}
else
{
lcd1.print(" ");
lcd1.setCursor ( 0, 3 );
lcd1.print(" ");
fl1=0;
}
}