Goeie middag vrienden,
Intussen ben ik wat gevorderd in mijn Arduino-"studies". Momenteel heb ik een RTC (DS3231) aangesloten en kan ik de datum + uur printen naar de seriële monitor. MAAR : toen heb ik een standaard LCD (2 x 16) aangesloten via de 4 data-lijnen (dus de gewone verbinding - geen I2C).
Ik dacht : laat ik Arduino de data van de RTC (voorlopig de temperatuur) eens sturen naar de LCD, maar dit lukt niet. Ik krijg enkele Chinese tekens rechts onderaan op de LCD.
Ik weet echt niet wat ik fout doe en info daarover vind ik niet direct. Ik denk : als Arduino de data correct naar de Seriële Monitor kan sturen, dan zou Arduino dit toch ook moeten doen naar de LCD.
Heeft iemand een ideetje wat ik verkeerd doe ?
Dit is mijn code bij mijn Arduino Leonardo waarvan de schets komt van RTC_DS3231 :
c code:
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <LiquidCrystal.h> //load lib Liquid Crystal
LiquidCrystal LCD (10, 9, 5, 4, 3, 2); //define the 6 pins of the LCD
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag"};
void setup () {
Serial.begin(9600);
LCD.begin (16, 2); //config the LCD as 16 row/2 colom
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
// When time needs to be re-set on a previously configured device, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.day(), DEC); //print nr day
Serial.print('/'); //print "/"
Serial.print(now.month(), DEC); //print nr month
Serial.print('/'); //print "/"
Serial.print(now.year(), DEC); //print nr year
Serial.print(" - "); //print " - "
//Serial.print(" (");
//Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
//Serial.print(") ");
Serial.print(now.hour(), DEC); //print hour
Serial.print(':'); //print ":"
Serial.print(now.minute(), DEC); //print minute
Serial.print(':'); //print ":"
Serial.print(now.second(), DEC); //print second
Serial.println(); //new line
Serial.print("Temperature: "); //print "txt"
Serial.print(rtc.getTemperature()); //print - temperature -
Serial.println(" C"); //print "txt"
Serial.println(); //print new line
delay (500);
LCD.clear();
LCD.setCursor (0, 0); //set cursor on colom zero and row zero
LCD.print("Temp: "); //transmit "txt" to LCD
LCD.print(rtc.getTemperature()); //transmit -temperature- to LCD
LCD.println(" C"); //transmit "txt" to LCD + new line
delay(500);
}
[Bericht gewijzigd door Henry S. op 2 mei 2022 21:13:27 (0%)