7 segment display problems

Basically I have a day counter using an Arduino Uno R3, RTC Module DS1307 & Adafruit 0.56" 4-Digit 7-Segment Display. I think the code is correct for what I want to do now, but the display is unreadable.

I found this project and I am doing the same thing and it appears I have the same issue.

There was never a resolution posted so hopefully someone can help me out.

#include <TimeLib.h>
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"



Adafruit_7segment clockDisplay = Adafruit_7segment();
RTC_DS1307 rtc = RTC_DS1307();

int hours = 0;
int minutes = 0;
int seconds = 0;

unsigned long previousMillis = 0;        // will store last millis event time
unsigned long sensorpreviousMillis = 0;        // will store last millis event time
unsigned long fiveMinuteInterval = 300000;           // interval at which to use event time (milliseconds)
unsigned long postDaysInterval = 7200000 ; //seconds in a day 86400000

#define DISPLAY_ADDRESS   0x70

unsigned long WeddingDate = 1059235200   ;  //in unixtime
unsigned long days ;
int weeks ;

void setup() {
  Serial.begin(115200);

  clockDisplay.begin(DISPLAY_ADDRESS);

  rtc.begin();

  bool setClockTime = !rtc.isrunning();
  if (setClockTime) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {

  time_t t = now();
  days = ((now() - WeddingDate) / 86400); //86400 is the number of seconds in a day
  unsigned long currentMillis = millis();
  ShowDaysReading();


  if (currentMillis - sensorpreviousMillis > fiveMinuteInterval)
  {
    // save the last time you performed event
    sensorpreviousMillis = currentMillis;
    DateTime Zeit = rtc.now();
  }
}

void ShowDaysReading()
{
  days = ((now() - WeddingDate) / 86400); //86400 number of seconds in a day
  weeks = ((now() - WeddingDate) / (86400 * 7) ); //86400 number of seconds in a day

  clockDisplay.print(days);


}

The first thing to do is to test only the display with the simplest possible program and get it working.

Check the wiring extremely carefully. Is the power correct? Are the grounds connected?

You may need to adjust the contrast.

Then add the other stuff.

It's definitely the sketch. I can use an example one and the display works perfectly.

That is a very simple program. You need to go through it line by line, making sure you understand what each line does.

However, you should keep in mind that about half of the code is complete nonsense and doesn't actually do anything useful, for example:

  if (currentMillis - sensorpreviousMillis > fiveMinuteInterval)
  {
    // save the last time you performed event
    sensorpreviousMillis = currentMillis;
    DateTime Zeit = rtc.now();
  }

Its main purpose seems to be to print the value of the variable "days" on the display tens to hundreds of thousands of times per second.

Thanks for looking at my code. I'm definitely not a code writer so your comments are helpful. I have basically borrowed parts of other people's code that was supposed to accomplish the task I'm after.
I will go through the code and try to make more sense of what's in there.
So I take it that portion you brought up is a complete waste and has nothing to do with what I'm trying to do?

Ok I spent a couple of hours this morning going through the code and commenting on lines for a clearer understanding for myself. It helps me learn what I am actually doing.

Like you had mentioned all of the milli and intervals are really unnecessary. Can I just remove them from the code? I would just try it, but I am not home with the Arduino in front of me.

Please look at the code to better understand what I am asking.

//Library Callouts

#include <TimeLib.h>
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"


// I2C address of the display.

#define DISPLAY_ADDRESS   0x70

// Create display and DS1307 objects.  These are global variables that
// can be accessed from both the setup and loop function below.

Adafruit_7segment clockDisplay = Adafruit_7segment();
RTC_DS1307 rtc = RTC_DS1307();

// Keep track of the hours, minutes, seconds displayed by the clock.
// Start off at 0:00:00 as a signal that the time should be read from
// the DS1307 to initialize it.

int hours = 0;
int minutes = 0;
int seconds = 0;

unsigned long previousMillis = 0;        // will store last millis event time
unsigned long fiveMinuteInterval = 300000;           // interval at which to use event time (milliseconds)
unsigned long postDaysInterval = 7200000 ; //seconds in a day 86400000

// CAN I DELETE ALL OF THESE MILLI/INTERVALLS???????????????


unsigned long WeddingDate = 1059235200   ;  //in unixtime
unsigned long days ;
int weeks ;

void setup() {

  // Setup function runs once at startup to initialize the display
  // and DS1307 clock.
  Serial.begin(115200);
  Serial.println("Clock starting!");

  // Setup the display.
  clockDisplay.begin(DISPLAY_ADDRESS);
  
  // Setup the DS1307 real-time clock.
  rtc.begin();
  

  // Set the DS1307 clock if it hasn't been set before.
  bool setClockTime = !rtc.isrunning();
  // Alternatively you can force the clock to be set again by
  // uncommenting this line:
  //setClockTime = true;
  if (setClockTime) {
    Serial.println("Setting DS1307 time!");
    // This line sets the DS1307 time to the exact date and time the
    // sketch was compiled:
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // Alternatively you can set the RTC with an explicit date & time, 
    // for example to set January 21, 2014 at 3am you would uncomment:
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop() {
  // Loop function runs over and over again to implement the clock logic.

  time_t t = now();  // Returns the current time as seconds (TimeLib)
  days = ((now() - WeddingDate) / 86400); // Defines "Days" & converts current time(s) to days, 86400 seconds per day
  //weeks = ((now() - WeddingDate) / (86400 * 7) ); //86400 number of seconds in a day (USE FOR LATER DATE)
  Serial.print("Current Day")
  Serial.print(now())
  Serial.print("Days Together")
  Serial.print(days)
  // Prints to serial monitor unixtime current day and then unixtime "days" together.
 
  unsigned long currentMillis = millis(); // DELETE THIS PORTION FROM HERE...
  ShowDaysReading();


  if (currentMillis - sensorpreviousMillis > fiveMinuteInterval)
  {
    // save the last time you performed event
    sensorpreviousMillis = currentMillis;
    DateTime Zeit = rtc.now(); // TO HERE??????????????????
  }
}

void ShowDaysReading()
{
    
  clockDisplay.print(days);


}

Define what you want the program to do, then write a program to do it.

Test it, and if it doesn't work, post on the forum with the information needed to solve the problem.

I got it working. Thanks