Hello all,
I'm new to Arduino, coding, and electronics (other than being on the end user side). I've taken up Arduino as a new hobby and having a blast with it over the last few weeks but I've hit a snag.
All the projects I've been working and doing serial.print for the results have gone fine. My end goal is to make a nice and inexpensive reef controller so getting my projects to show their output on my LCD is important. For instance, getting the time/date to print on the LCD hasn't worked.
I2C 20x4 LCD:
VCC to 5v
GRD to GRD
SCL to A5
SDL to A4
DS1307 RTC:
VCC to 5v
GRD to GRD
SCL to A5
SDL to A4
Both the RTC and LCD are sharing analog pin 4 and 5 on my Uno which I thought was ok since they are both serial devices(?). Maybe my thought process for the proper pins is wrong?
#include <LiquidCrystal_I2C.h>
#include <MD_DS1307.h>
#include <Wire.h>
#include <LCD.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.noCursor();
}
void p2dig(uint8_t v)
// print 2 digits leading zero
{
if (v < 10) lcd.print("0");
lcd.print(v);
}
char *dow2String(uint8_t code)
{
char *str[] = {" Sun", " Mon", " Tue", " Wed", " Thu", " Fri", " Sat"};
return(str[code-1]);
}
void printTime()
{
lcd.setCursor(0,0);
lcd.print(RTC.yyyy);
lcd.print("-");
p2dig(RTC.mm);
lcd.print("-");
p2dig(RTC.dd);
lcd.setCursor(0,1);
p2dig(RTC.h);
lcd.print(":");
p2dig(RTC.m);
lcd.print(":");
p2dig(RTC.s);
if (RTC.Status(DS1307_12H) == DS1307_ON)
lcd.print(RTC.pm ? " pm" : " am");
lcd.print(dow2String(RTC.dow));
}
void loop()
{
RTC.ReadTime();
printTime();
delay(100);
}
Any help/education on the matter would be greatly appreciated.