Hi, beginner here!
I was wondering if you could help me out. The components I have are RTC module (DS3231), SD card reader module, and an 8-channel relay.
When the code WITH ONLY THE LCD **AND RTC as components is uploaded, the display works just as fine.
However, when the other components are added to the code, the display is messed up and even shows other characters.
I'm only a beginner at Arduino so I'm not really familiar with how things work.
So the display works properly... The date and time are shown correctly without any other characters.
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
Time t;
void setup() {
rtc.begin();
lcd.begin(16, 4);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("HELLO WORLD");
lcd.setCursor(0, 1);
lcd.print(rtc.getDateStr());
lcd.print(" ");
lcd.print(rtc.getTimeStr());
delay(5000);
lcd.clear();
}
This one however... The text keeps on repeating and other characters are showing up too.
//rtc
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
Time t;
//relay_LIGHTS1
int relay_LIGHTS1 = 28;
int relay_LIGHTS2 = 29;
//data_logger
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 53;
//LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
void setup()
{
//lcd
lcd.begin(16, 4);
//rtc
rtc.begin();
//relay_LIGHTS1
pinMode(relay_LIGHTS1, OUTPUT);
pinMode(relay_LIGHTS2, OUTPUT);
Serial.begin(115200);
//data_logger
pinMode(pinCS, OUTPUT);
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
}
void loop()
{
// relay_LIGHTS
int HOUR = t.hour;
if (HOUR >= 6 && HOUR <= 18)
{
digitalWrite(relay_LIGHTS1, HIGH);
digitalWrite(relay_LIGHTS2, HIGH);
}
else
{
digitalWrite(relay_LIGHTS1, LOW);
digitalWrite(relay_LIGHTS2, LOW);
}
//
myFile = SD.open("test.txt", FILE_WRITE);
{
if (myFile)
{
myFile.print(rtc.getDOWStr());
myFile.print(",");
myFile.print(rtc.getDateStr());
myFile.print(",");
myFile.print(rtc.getTimeStr());
myFile.close(); // close the file
}
else
{
Serial.println("error opening test.txt");
delay(1000);
}
}
//rtc
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
delay(1000);
//lcd
lcd.setCursor(0, 0);
lcd.print("HELLO Z");
lcd.setCursor(0, 1);
lcd.print(rtc.getDateStr());
lcd.print(" ");
lcd.print(rtc.getTimeStr());
delay(5000);
lcd.clear();
delay(5000);
lcd.setCursor(0, 0);
lcd.print("HELLO J");
lcd.setCursor(0, 1);
lcd.print(rtc.getDateStr());
lcd.print(" ");
lcd.print(rtc.getTimeStr());
delay(5000);
lcd.clear();
delay(5000);
}
Thank you very much and hoping from some answers!