I'm struggling for a while now with displaying the time on a 4 digit 7 segment display by using the ds1302. My display gives me just 4 vertical stripes in the middle of each digit. I thought first it was caused by the difference in type. myRTC.hours is a uint8_t and the function I am using to display it; displayTime(int hours, int minutes) uses int as a type. But I still have the same result. As I have wired my ds1302 properly and the same goes to my display, I think the fault is somewhere in the code. Can You help me out?
Big thanks in advance.
#include <virtuabotixRTC.h>
#include <Wire.h>
virtuabotixRTC myRTC(A3, A4, A5);
#include <Robojax_SevenSegmentClock.h>
const int digits[]={9,10,11,12};// define digits pins
const int displayPins[] = {2,3,4,5,6,7,8}; // define segment pins
const int colonPin = 13;// colon pin
const int type =1;//1 common Anode, 2 for common cathode
Robojax_SevenSegmentClock clk(displayPins,digits,colonPin,type);
int blinkTime=0;
int blinkStatus=0;
void setup() {
Serial.begin(9600);
Serial.println("Initialize DS1302");
clk.begin();//for Robojax_SevenSegmentClock
Serial.println("Robojax Seven Segment Display Clock");
Serial.println("V 1.0 July 28, 2019");
myRTC.setDS1302Time(0, 7, 19, 1, 11, 5, 2020);
}
void loop() {
myRTC.updateTime();
int hr;
int mn;
hr = (int)myRTC.hours;
mn = (int)myRTC.minutes;
Serial.print(hr); Serial.print(":");
Serial.print(mn); Serial.print(":");
clk.displayTime(hr,mn);
delay(1);
}
Yes, like this: - - - - only the four stripes in the middle lit up. I then think that the problem is that there is no time coming true to display.
My display gives me just 4 vertical stripes in the middle of each digit.
Yes, like this: - - - - only the four stripes in the middle lit up.
Not vertical stripes then
#include <Robojax_SevenSegmentClock.h>
Is there a library example that you can run?
Yes, I can see only horizontal stripes. And there is no library example that I can run. The example in the library uses the ds3231 and I'm using the ds1302.
Is the serial output in your posted code correct? If so, then the DS1302 code is correct.
UKHeliBob:
Yes, like this: - - - - only the four stripes in the middle lit up.
Not vertical stripes then
Christ......
(Thank God for keyboard graphics.)
Could your display be Common Cathode instead of Common Anode?
The library can only display decimal digits. It MAY have trouble with negative values so using 'byte' or 'uint8_t' for your hour and minute values might be a good idea. There is no code for "If it doesn't look like a valid time, show '----'" so it's not a matter of not getting the right time.
Thank You for all the answers so far. But none of them seem to be the main problem. In my library I'm using for my display, the function displayTime(int hr, int mn) is using an integer as a type. While I'm injecting a uint8_t, displayTime(uint8_t myRTC.hours, uint8_t myRTC.minutes). I thought this was the problem so I converted it like this:
int hr;
int mn;
hr = (int) myRTC.hours;
mn = (int) myRTC.minutes;
Is this correct? Can this be the problem?
Here is the library example sketch modified for a fixed hour and fixed minute. It should show 12:34 on the display. I believe that your problem is with either the wiring or the parameters used in the display constructor.
/*
* Seven Segment LED Clock with Arduino and DS3231
* using Robojax Library
*
* Written by Ahmad Shamshiri
* on July 26, 2018 at 21:29 in Ajax, Ontario, Canada
watch video instruction for this code:https://youtu.be/qB0drI56zGE
Watch video instruction for DS3231: https://youtu.be/7hBtXdoaAOY
Get this code and other Arduino codes from Robojax.com
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
*
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//#include <Wire.h>
//#include <DS3231.h>
//DS3231 clock;
//RTCDateTime dt;
#include <Robojax_SevenSegmentClock.h>
const int digits[]={9,10,11,12};// define digits pins
const int displayPins[] = {2,3,4,5,6,7,8}; // define segment pins
const int colonPin = 13;// colon pin
const int type =1;//1 common Anode, 2 for common cathode
Robojax_SevenSegmentClock clk(displayPins,digits,colonPin,type);
int blinkTime=0;// do not change. Used internally
int blinkStatus=0;// do not change. Used internally
int testHour = 12;
int testMinute = 34;
void setup() {
Serial.begin(9600);
// Initialize DS3231
//Serial.println("Initialize DS3231");
//clock.begin();//for DS3231
clk.begin();//for Robojax_SevenSegmentClock
Serial.println("Robojax Seven Segment Display Clock");
Serial.println("V 1.0 July 28, 2019");
// Robojax Seven Segment Clock for Arduino
// uncomment the line below only ONCE to updat the time. Then comment it back
//clock.setDateTime(__DATE__, __TIME__);
}// setup ends here
void loop() {
// Robojax Seven Segment LED Clock with Arduino
// dt = clock.getDateTime();
// Serial.print(dt.hour); Serial.print(":");
// Serial.print(dt.minute); Serial.print(":");
// Serial.print(dt.second); Serial.println("");
//clk.displayTime(dt.hour,dt.minute);
clk.displayTime(testHour, testMinute);
delay(1000);
}// loop ends here