"Skipping" Glitch? arduino nano/RTC/OLED

Hi all! Been working on a project, one that apparently where nothing wants to work properly. My current issue(Out of many...) Is if i leave my "Clock" for a little while, it all works and everything, but then the display just glitches/Skips. i will be posting a video to explain what i mean, and also my code.

https://imgur.com/a/Nk62uS2

As you can see, when every it lags or whatever you may call it, the "L" rapidly blinks twice. Mind you, its still keeping accurate time, its just... idk lagging

Currently using Oled 128x64 display, rtc ds3231 and Arduino nano

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
#include <Servo.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS3231 rtc;
char message[]="                          ";
   int x, minX;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup() {
  Serial.begin(9600);
  delay(3000); // wait for console opening
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // 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(2023, 4, 22, 10, 22, 00)); 
  }
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)// Check your I2C address and enter it here, in Our case address is 0x3C
  display.clearDisplay();
  display.display(); // this command will display all the data which is in buffer
  display.setTextColor(SSD1306_BLACK);
  display.drawRect(117, 25, 3, 3, BLACK);     // Put degree symbol ( ° )
    display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  x = display.width();
  minX = -12 * strlen(message);  // 12 = 6 pixels/character * text size 2
  }

void loop() {


  DateTime now = rtc.now();


  /*============Display Date=================*/
  display.fillRect(0,0,128,16,SSD1306_BLACK);
  display.fillRect(0,16,128,28,SSD1306_BLACK);
  //display.fillRect(0,28,128,46,SSD1306_BLACK);
  display.fillRect(0,46,128,64,SSD1306_BLACK);


 /* Display appropriate message based on time of day */
  if (now.hour() >= 24 || now.hour() < 8) { // 11pm till 8am
    display.setCursor(x, 48);
    display.print("Have a great morning, Twig!");
  } else if (now.hour() >= 8 && now.hour() < 19) { // 8am till 7pm
    display.setCursor(x, 48);
    display.print("Have a good day!!!");
  } else if (now.hour() >= 19 && now.hour() < 24) { // 7pm till 11pm
    display.setCursor(x, 48);
    display.print("Night Night!");
  }
  
  /* Update scrolling message */
  x = x - 4; // scroll speed, make more positive to slow down the scroll
  if (x < minX) x = display.width();
  display.setTextSize(2);
  display.setCursor(x, 48);
  display.print(message);

 


display.setTextSize(1);
display.setCursor(0,0);
display.setTextColor(SSD1306_WHITE);
display.print(daysOfTheWeek[now.dayOfTheWeek()]);
char currentDate [16];
uint8_t thisDay, thisMonth ;
thisDay = now.day();
thisMonth = now.month();
sprintf (currentDate, "%02d/%02d/", thisDay, thisMonth); //add leading zeros to the day and month
display.setTextSize(1);
display.setCursor(62,0);
display.setTextColor(SSD1306_WHITE);
display.print(currentDate);
display.setTextSize(1);
display.setCursor(102,0);
display.print(now.year(), DEC);
/*================Display Time================*/ 
char buffer[16]; // Declare buffer before using it
uint8_t thisSec, thisMin;
thisSec = now.second();
thisMin = now.minute();

uint8_t thisHour = now.hour();
bool isPM = thisHour >= 12; // determine if it's PM
thisHour = thisHour % 12; // convert to 12-hour format
if (thisHour == 0) {
  thisHour = 12; // 12 midnight is 12am
}
sprintf(buffer, "%2d:%02d:%02d", thisHour, thisMin, thisSec);// format time with AM/PM indicator
display.setTextSize(2);
display.setCursor(5,20);
display.setTextColor(WHITE);
display.print(buffer);

sprintf(buffer, "%s", isPM ? "PM" : "AM");


display.setTextSize(2);
display.setCursor(105,15);
display.setTextColor(WHITE);
display.print(buffer);

display.display();
}

It seems that the issue in the project is the display is glitching or skipping when left for a while. The user is working on a clock project using an OLED 128x64 display, RTC DS3231, and Arduino Nano. The code is attached to the post.

One potential cause of the issue is the display's driver code. The user is using Adafruit's SSD1306 display driver library, which may be incompatible with the OLED display used in the project. The user could try using a different library or updating the existing one to see if it resolves the issue.

Another potential cause could be the power supply. OLED displays are known to consume a lot of power, and if the power supply is not sufficient, the display may start glitching or skipping. The user should check if the power supply is providing enough voltage and current to the display.

Lastly, the issue could be related to the clock module. The RTC DS3231 is a relatively accurate clock module, but it may drift over time, leading to the display glitching or skipping. The user should check if the clock is set accurately and make adjustments if necessary.

In conclusion, the user should try the following steps to resolve the issue:

  1. Check if the display driver library is compatible with the OLED display used in the project or try using a different library.
  2. Check if the power supply is providing enough voltage and current to the display.
  3. Check if the clock module is set accurately and make adjustments if necessary.

1 through 3 is all correct. ET: Libary is designed for thos oled display, There is enough power since its connected to computer, and clock is set at the accurate time

Thank you for the information. Based on the information provided, it seems that the hardware and power supply are working properly. However, there could still be potential issues with the software or connections.

Here are some further troubleshooting steps that may help:

  1. Check the connections: Double-check that all connections are securely in place and that there are no loose wires or connections. If possible, try using a different cable or port to ensure that the issue is not with the connection.

  2. Check the code: Review the code to ensure that it is properly written and that there are no errors or typos. If necessary, try running a simple test code to verify that the display is working properly.

  3. Try a different display: If possible, try using a different display to see if the issue is with the OLED display or the code. This will help to narrow down the problem and determine if a replacement display is necessary.

  4. Check for software updates: Make sure that you are using the latest version of any software or libraries needed to run the OLED display. Updating the software may help to resolve any compatibility issues.

  5. Contact the manufacturer: If none of the above steps resolve the issue, it may be necessary to contact the manufacturer for additional support or a replacement display.

I hope these troubleshooting steps help you to identify and resolve the issue with your OLED display. Let me know if you have any further questions or concerns.

And thank you for copy-pasting the "wisdom" of ChatGPT.

Now don't. Do that anymore. These are fora for humans.

If you have to, please make it clear that you have, and are actually not supplying any of your own knowledge or experience.

a7

2 Likes

If you cut and past chatGPT answers, you are required to say so.

3 Likes

ok sorry for that yes i used chat gpt i was just trying to help out will not do so anymore

The answers it provides are full of waffle and rarely useful. If you want to use it fine... but interpret the response it provides first and evaluate whether it actually provides a solution... rather just cutting and pasting into the forum.

I suspect your program is crashing and restarting. Put some Serial.print statements into setup() to confirm.

Also... are you expecting xMin to contain -312 ? That is causing you to send negative column positions to setCursor().

Weird. Idk why it would be crashing and what not, but I'll give that a go, and see what's going on

Well, from the video, it looks like you're powering everything through the USB connection.
Looks like insufficient power to me (and others i.e. chatGPT).

I would at minimum try using a USB hub with power adapter to guarantee that there's at least 500mA available, however I highly recommend using a 5V power source rated for at least 2A, especially if you have a servo motor connected.

No servo motor, I just didn't take that out of the code and no. Everything powers properly just from the USB. I can even add 2 servos, and it will still work properly.

From the video, it appears that the Nano also resets.
Does the Nano stop resetting if you disconnect the OLED display?

Nope continues to keep resetting. I have just been having extremely bad luck with my code or something, I've gone through 6 Arduino Nanos lmao cause they keep bricking/After awhile of running my code, I just won't be able to upload anything to it, no matter what I do

I'm finding this very hard to believe at this point. It also contradicts the resetting issue.

  • Have you tried a different USB cable and a different USB port?
  • I highly recommend trying a powered USB hub, or even a different PC to see if the issue persists.
  • Perhaps try testing while the serial monitor is closed.
  • Try running a simple blink sketch (i.e LED 10000 ms ON / 10000 ms OFF) and see if the issue persists.

Note: I haven't looked at your code yet.

Yes, surprisingly it does. I had a TFT display +2 DHT11 sensor, moisture sensor, and UV sensor running off of it. And it still worked fine.

I originally was working on this, on my gizmo computer (The computer where I do all my 3D printing/Coding/Learning) and it was still doing it, so that's when I brought it to my "Gaming PC" and tried it there, where it still gave me same issue.

Blink sketch appears to be working good. So far

Global variables use 820 bytes (40%) of dynamic memory, leaving 1228 bytes for local variables. Maximum is 2048 bytes.

The Adafruit library uses 1024 bytes for a display buffer, which is not included in the total shown by the compiler. Running out of dynamic memory is very likely to cause a processor reset.

Try using the F() macro with the text literals in the print() statements.

Thank you, I will give that a go

I don't seem to have a problem running the sketch here, so memory may not be a problem, although that might be affected by the version of the IDE and libraries that I have.

does the oled display work proper etc for you? or did you just run the sketch?