0

I am making an alarm clock using a 4x20 lcd display, rtc, and Arduino Pro Mini 3.3v. I have implemented a menu system for setting the time/date that blinks the text on the lcd display to indicate that I have it selected, but the blinking randomly stops and the Arduino stops printing to the serial after about ten seconds.

After much head scratching and Googling I came to the conclusion that all my lcd.print() lines were using up all my ram. I tried to create PROGMEM variables to use in the print commands, but I couldn't get it to work so I ended up just adding the F() macro to every print statement (there's a lot). This now prints everything as expected, but the Arduino still freezes up after the same amount of time. Am I using F() wrong or is the problem something else like power???

Visual Studio code says I am using 643/2048 bytes of data/ram and 14960/30720 bytes of flash when I upload the code. (that is with the F() macro implemented)

--------------EDIT----------------

So I've created a small test sketch to use with the same circut, and now I'm really confused. I've been running it for about an hour now and it is still not freezing. The script blinks a full screen of number signs every 200ms. The backlight is on and everything is still powered the same way. This, in theory, rules out both running out of ram and not providing enough power. Any other ideas?

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClibExtended.h>

LiquidCrystal_I2C lcd(0x27,20,4);
RTC_DS3231 clock;

void setup() {
    Serial.begin (9600);
    lcd.init();
    clock.begin();
    clock.adjust (DateTime (__DATE__, __TIME__));
    lcd.backlight();
}

bool on = true;

void loop() {
    lcd.setCursor (0, 0);

    if (on) {
        for (int i = 0; i < 4; i++) {
            lcd.setCursor (0, i);
            for (int j = 0; j < 20; j++) {
                lcd.print ("#");
            }
        }
    }
    else {
        for (int i = 0; i < 4; i++) {
            lcd.setCursor (0, i);
            for (int j = 0; j < 20; j++) {
                lcd.print (" ");
            }
        }
    }

    on = !on;
    delay (200);
}
  • 2
    add your code to the Question. – Juraj Oct 18 '18 at 4:32
  • A lcd display requires 5v and your Arduino is a 3.3v pro mini board. How did you connect that? Are there long wires to the rtc and the display? – Jot Oct 18 '18 at 5:04
  • Along with what Jot said, and my own WAG, it sounds like you're trying to pull too much power, potentially overheating the power regulator. Once you add some code, we can see if that's an alternate possibility. – computercarguy Oct 18 '18 at 18:46
  • I have the Arduino powered by the usb from my computer and the rtc and lcd are connected to the vcc pin on the Arduino. I am using the lcd without the backlight, so does it still need 5v? Also, I tried using a 9v battery to power the circuit (connected the Arduino to the battery through the raw pin and connected the lcd and rtc directly into the battery instead of the vcc pin from the Arduino), and the lcd still freezes. Would it be helpful if I posted the circuit diagram? My code is over 1000 lines long, so I'm not sure what the best way to share it with you would be. – cr5519 Oct 19 '18 at 5:16
  • create a small test sketch to test if the problem is power or overheating – Juraj Oct 19 '18 at 19:59
0

I found the problem! it was specific to my code and didn't turn out to have anything to do with ram or power. The problem was I hadn't detached the interrupt from the rtc when I woke it up with a button. It would freeze seemingly randomly because the rtc would fire an interrupt signal when the next minute ticked, while the arduino was awake. I guess it causes problems when you try to interrupt arduino's sleep and it's not actually sleeping. All I had to do was detach both interrupts when the button is clicked. Thank you all for your help :)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.