Folks,
Newbie here. Running a knock-off Nano. The sketch is about 600 lines long is nothing complex. It's just a clock that displays a happy birthday message on days where there are birthdays. When trying to compile I get an error that I'm out of memory. I wanted to be able to add more folks.
Below is the tail end of the error message.
Sketch uses 11876 bytes (38%) of program storage space. Maximum is 30720 bytes.
Global variables use 2065 bytes (100%) of dynamic memory, leaving -17 bytes for local variables. Maximum is 2048 bytes.data section exceeds available space in board
Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
Error compiling for board Arduino Nano.
I know my code could use a more sophisticated approach to checking if the day happens to be a birthday. Below is a segment of the code and what I'm doing. Again, I'm new to coding.
#include <Wire.h> // include wire library
#include <RTClib.h> // RTC
#include <LiquidCrystal_I2C.h> // for LCD
#include "DHT_U.h"
#define Type DHT22
LiquidCrystal_I2C lcd(0x27, 20, 4); // create LCD, address is 0x27
RTC_DS3231 rtc; // create rtc, address is 0x68
const int sensePin=7;
DHT DHTT(sensePin, Type);
float humidity;
float tempC;
float tempF;
// 0=Sunday, 1=Monday,...6=Saturday
const char dayInWords[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
// 0=" ", 1=Jan, 2=Feb, ... 12=Dec
const char monthInWords[13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
//byte heart[8] = {
// 0b00000,
// 0b01010,
// 0b11111,
// 0b11111,
// 0b11111,
// 0b01110,
// 0b00100,
// 0b00000
//};
//
void setup()
{
Serial.begin(9600); // start serial monitor for debugging if needed
lcd.init(); // initialize LCD
lcd.backlight(); // turn on LCD backlight
rtc.begin(); // initialize RTC
DHTT.begin();
// lcd.createChar(0, heart);
} //END of setup()
void loop()
{
// lcd.write(byte(0));
DateTime rtcTime = rtc.now(); // get time
int ss = rtcTime.second(); // save seconds
int mm = rtcTime.minute(); // save minutes
int hh = rtcTime.twelveHour(); // etc.
int DD = rtcTime.dayOfTheWeek();
int dd = rtcTime.day();
int MM = rtcTime.month();
int yyyy = rtcTime.year(); // save year
lcd.setCursor(0,0); // Set cursor to top left position
lcd.print(monthInWords[MM]); // print date in MMM-dd-yyyy format
lcd.print("-"); // print "-" for formating
if (dd<10) lcd.print ("0"); // add 0 before hour if less than 10
lcd.print(dd); // print day
lcd.print("-"); // print "-" for formatting
lcd.print(yyyy); // print year
lcd.print(" "); // print space for formatting
lcd.print(dayInWords[DD]); // print day in DDD format
lcd.setCursor(0,1); // set cursor at beginning of next row
if (hh<10) lcd.print("0"); // add 0 before hour if less than 10
lcd.print(hh); // print hour
lcd.print(":"); // add ":" for formatting
if (mm<10) lcd.print("0"); // add 0 before minite if less than 10
lcd.print(mm); // print minutes
lcd.print(":"); // add ":" for formatting
if (ss<10) lcd.print("0"); // add 0 before seconds if less than 10
lcd.print(ss); // print seconds
if (rtcTime.isPM()) lcd.print(" PM"); // print PM if PM
else lcd.print (" AM"); // else print AM
humidity = DHTT.readHumidity();
tempC = DHTT.readTemperature();
tempF = DHTT.readTemperature(true);
if (MM == 1 && dd == 4) {
lcd.setCursor(0,2);
lcd.print("Happy Birthday ");
lcd.setCursor(0,3);
lcd.print("Chris H. ");
}
else if (MM == 1 && dd == 7) {
lcd.setCursor(0,2);
lcd.print("RIP ");
lcd.setCursor(0,3);
lcd.print("Ann W. ");
}
else if (MM == 1 && dd == 10) {
lcd.setCursor(0,2);
lcd.print("Happy Birthday ");
lcd.setCursor(0,3);
lcd.print("Jim B. ");
}
else if (MM == 1 && dd == 27) {
lcd.setCursor(0,2);
lcd.print("Happy Birthday ");
lcd.setCursor(0,3);
lcd.print("William B. ");
}
else if (MM == 2 && dd == 2) {
lcd.setCursor(0,2);
lcd.print("Happy Birthday ");
lcd.setCursor(0,3);
lcd.print("Al C. ");
}
else if (MM == 2 && dd == 7) {
lcd.setCursor(0,2);
lcd.print("Happy Birthday ");
lcd.setCursor(0,3);
lcd.print("Nick P. ");
}
I'm looking for options people. Is my code a big bloated mess? Would some sort of array work better? But again, I'm kinda new to all if this. How about hardware? Does an UNO have more memory? How about a mega?
Thank you.
Best,
Tony