0

Multiple 7-Segment & Alphanumeric Displays for a Clock
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Tue Nov 07, 2017 2:20 pm

I am working on a clock using an Arduino and some of the 7-Segment and Alphanumeric displays with I2C backpacks. I want to have not only a 4-digit clock, but also displays for the date with 3 letter abbreviation for the month, 2-digit day and 4-digit year. I found this example code below from Adafruit and I am wondering if it can be modified to use multiple displays and do what I need it to do. I see it has a line of code, #define DISPLAY_ADDRESS 0x70. That's fine for one display, but can I add others for the different functions, and how would that be coded? Can I just say #define DISPLAY_ADDRESS_2 0x71, enter the rest of the code for month, day, etc.? Thoughts? Here's the example code from Adafruit:

Code: Select all | TOGGLE FULL SIZE
// Clock example using a seven segment display & DS1307 real-time clock.
//
// Must have the Adafruit RTClib library installed too!  See:
//   https://github.com/adafruit/RTClib
//
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
// and DS1307 real-time clock breakout:
// ----> http://www.adafruit.com/products/881
// ----> http://www.adafruit.com/products/880
// ----> http://www.adafruit.com/products/879
// ----> http://www.adafruit.com/products/878
// ----> https://www.adafruit.com/products/264
//
// Adafruit invests time and resources providing this open source code,
// please support Adafruit and open-source hardware by purchasing
// products from Adafruit!
//
// Written by Tony DiCola for Adafruit Industries.
// Released under a MIT license: https://opensource.org/licenses/MIT

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


// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      false

// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back 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;

// Remember if the colon was drawn on the display so it can be blinked
// on and off every second.
bool blinkColon = false;


void setup() {
  // Setup function runs once at startup to initialize the display
  // and DS1307 clock.

  // Setup Serial port to print debug output.
  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.
 
  // Check if it's the top of the hour and get a new time reading
  // from the DS1307.  This helps keep the clock accurate by fixing
  // any drift.
  if (minutes == 0) {
    // Get the time from the DS1307.
    DateTime now = rtc.now();
    // Print out the time for debug purposes:
    Serial.print("Read date & time from DS1307: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    // Now set the hours and minutes.
    hours = now.hour();
    minutes = now.minute();
  }

  // Show the time on the display by turning it into a numeric
  // value, like 3:30 turns into 330, by multiplying the hour by
  // 100 and then adding the minutes.
  int displayValue = hours*100 + minutes;

  // Do 24 hour to 12 hour format conversion when required.
  if (!TIME_24_HOUR) {
    // Handle when hours are past 12 by subtracting 12 hours (1200 value).
    if (hours > 12) {
      displayValue -= 1200;
    }
    // Handle hour 0 (midnight) being shown as 12.
    else if (hours == 0) {
      displayValue += 1200;
    }
  }

  // Now print the time value to the display.
  clockDisplay.print(displayValue, DEC);

  // Add zero padding when in 24 hour mode and it's midnight.
  // In this case the print function above won't have leading 0's
  // which can look confusing.  Go in and explicitly add these zeros.
  if (TIME_24_HOUR && hours == 0) {
    // Pad hour 0.
    clockDisplay.writeDigitNum(1, 0);
    // Also pad when the 10's minute is 0 and should be padded.
    if (minutes < 10) {
      clockDisplay.writeDigitNum(2, 0);
    }
  }

  // Blink the colon by flipping its value every loop iteration
  // (which happens every second).
  blinkColon = !blinkColon;
  clockDisplay.drawColon(blinkColon);

  // Now push out to the display the new values that were set above.
  clockDisplay.writeDisplay();

  // Pause for a second for time to elapse.  This value is in milliseconds
  // so 1000 milliseconds = 1 second.
  delay(1000);

  // Now increase the seconds by one.
  seconds += 1;
  // If the seconds go above 59 then the minutes should increase and
  // the seconds should wrap back to 0.
  if (seconds > 59) {
    seconds = 0;
    minutes += 1;
    // Again if the minutes go above 59 then the hour should increase and
    // the minutes should wrap back to 0.
    if (minutes > 59) {
      minutes = 0;
      hours += 1;
      // Note that when the minutes are 0 (i.e. it's the top of a new hour)
      // then the start of the loop will read the actual time from the DS1307
      // again.  Just to be safe though we'll also increment the hour and wrap
      // back to 0 if it goes above 23 (i.e. past midnight).
      if (hours > 23) {
        hours = 0;
      }
    }
  }

  // Loop code is finished, it will jump back to the start of the loop
  // function again!
}

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Tue Nov 07, 2017 2:40 pm

You will need to declare multiple instances of the clock display

Code: Select all | TOGGLE FULL SIZE
Adafruit_7segment clockDisplay1 = Adafruit_7segment();
Adafruit_7segment clockDisplay2 = Adafruit_7segment();


And initialize them with different addresses:

Code: Select all | TOGGLE FULL SIZE
  clockDisplay1.begin(DISPLAY_ADDRESS_1);
  clockDisplay2.begin(DISPLAY_ADDRESS_2);

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Tue Nov 07, 2017 11:00 pm

Thank you for the response. I have another question regarding the hookup of the displays. I am currently testing the code with two displays--both hooked up to the I2C lines of a Pro Trinket. I have the actual clock display (the one that shows the time) set to the 0x70 address and the other set to 0x71 which is supposed to display the year. With the time display and the year display connected, both displays remain blank. With only the time display connected, it works. Does the Pro Trinket not provide enough current for both displays to run or is it more likely a coding issue? Do I need any other components? I am powering it via USB at the moment. Based on the code I provided, how would I properly display the year on a second display?

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 6:45 am

Is it a 5v Pro Trinket or a 3.3v Pro Trinket? With the 5v, it is a straight pass-through of the 5v from the USB. With the 3.3v, it needs to go through the 3.3v regulator, which would limit the current available. If you post some photos showing your setup and connections, we can take a look.

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 1:43 pm

It is a 5V Pro Trinket. I have uploaded a few photos for your review. I am aware of the one blue wire that is disconnected from the one display. This was done for troubleshooting and has been reconnected each time I test with both displays. It is difficult to see all of the connections, but I have checked them several times and everything seems to be in order. My next step is to try this with an Uno to see if that makes a difference.
Attachments
Trinket 3.jpg
Trinket 3.jpg (64.34 KiB) Viewed 134 times
Trinket 4.jpg
Trinket 4.jpg (57.76 KiB) Viewed 134 times
Trinket 5.jpg
Trinket 5.jpg (48.57 KiB) Viewed 134 times

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 1:53 pm

Try temporarily removing the RTC from the i2c bus (and the code) to see if that makes a difference.

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 6:25 pm

Ok, so with the RTC removed from the circuit and one display connected, I get the first display lighting up with 4 "dashes" (the middle segments) and a blinking colon. When both displays are connected, with the RTC still out of circuit, both displays are still blank.

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 8:18 pm

OK. That rules out an i2C bus problem.
Please post some photos showing your soldering on both sides of the LED backpacks.

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 8:55 pm

Here are the photos. It should be noted that I have tested the displays independently with their respective addresses and they each work by themselves--just not together.
Attachments
IMG_20171108_193239714.jpg
IMG_20171108_193239714.jpg (419.14 KiB) Viewed 115 times
IMG_20171108_193147957.jpg
IMG_20171108_193147957.jpg (989.39 KiB) Viewed 115 times
IMG_20171108_193044480.jpg
IMG_20171108_193044480.jpg (370.83 KiB) Viewed 115 times

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 8:56 pm

Here's a few more photos.
Attachments
IMG_20171108_193940270.jpg
IMG_20171108_193940270.jpg (761.8 KiB) Viewed 115 times
IMG_20171108_193254810.jpg
IMG_20171108_193254810.jpg (984.09 KiB) Viewed 115 times

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 9:16 pm

The soldering looks fine. Have you run the "sevenseg" example code on both displays to test? (You will need to change the address in the matrix.begin() for the second display)

https://github.com/adafruit/Adafruit_LE ... venseg.ino

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 9:23 pm

Yes. In fact, I just did it again to double check.

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 9:29 pm

And the results were?

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by BluesPwr1009 on Wed Nov 08, 2017 9:32 pm

They both worked perfectly--but each on its own of course.

BluesPwr1009
 
Posts: 22
Joined: Sat Aug 22, 2015 5:52 pm

Re: Multiple 7-Segment & Alphanumeric Displays for a Clock

by adafruit_support_bill on Wed Nov 08, 2017 9:53 pm

If they all work independently, but not together, one possibility is that there are to many pullup resistors on the i2c bus. You have 3 devices on the bus that all have pullup resistors.

If you follow the traces from the SDA and SCL pins, you will see two small resistors with a "1002" marking. If you remove those from one of the boards, it might allow normal communication on the bus.

adafruit_support_bill
 
Posts: 62905
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.