7-segment display with backpack
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- microhead
- Posts: 4
- Joined: Fri Feb 15, 2013 1:34 pm
7-segment display with backpack
I'm using the Adafruit 7-segment LED Backup plus a DS3231 clock module. Bread boarded these and I notice the DS3231 is not keeping accurate time, usually jumping ahead by a minute. I removed the display and run the DS3231 by itself and get the expected accuracy. Thinking noise issues from the backpack module. Anyone else seen this? I tried some bypass caps to no avail.
- Franklin97355
- Posts: 23938
- Joined: Mon Apr 21, 2008 2:33 pm
Re: 7-segment display with backpack
Are you using the same code when testing and what are you using for the controller?
- microhead
- Posts: 4
- Joined: Fri Feb 15, 2013 1:34 pm
Re: 7-segment display with backpack
I'm using the Metro Mini. I'm using the example code for the backpack: clock_sevenseg_ds1307 from the Adafruit LED Backpack library to run the clock module and display.
Running the clock module by itself, still using the Metro Mini, and running a code I picked up from Adafruit that directly sets the clock module and reads it back on serial monitor. I've used this for years on many clock projects.
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime(); //MUST CONFIGURE IN FUNCTION
}
void loop(){
printDate();
delay(1000);
}
void setDateTime(){
byte second = 00; //0-59
byte minute = 7; //0-59
byte hour = 16; //0-23
byte weekDay = 2; //1-7
byte monthDay = 32; //1-31
byte month = 8; //1-12
byte year = 22; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}
Running the clock module by itself, still using the Metro Mini, and running a code I picked up from Adafruit that directly sets the clock module and reads it back on serial monitor. I've used this for years on many clock projects.
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime(); //MUST CONFIGURE IN FUNCTION
}
void loop(){
printDate();
delay(1000);
}
void setDateTime(){
byte second = 00; //0-59
byte minute = 7; //0-59
byte hour = 16; //0-23
byte weekDay = 2; //1-7
byte monthDay = 32; //1-31
byte month = 8; //1-12
byte year = 22; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}
Please be positive and constructive with your questions and comments.