Issue coding RTC 7 segment clock

What I do with unknown displays, is write a sketch that cycles through the segments/digits in linear order, and very slow. In one difficult case, I made it scan one segment at a time, controlled by a pushbutton to give me time to think/write what I see.

At the end of that, I have a verified "assignment table" to use when writing the code.

I wouldn't worry too much about the LED voltage if they do illuminate satisfactorily.

You do have current limiting resistors on the segments, right?

I was referring to the pin numbers in the code you posted not matching the schematic.

I have 2.2k resistors on the base of the pnp transistors and a 0 ohm resistor on the collector as per the recommendation of the review request I posted on the EEVblog, worse case scenario I can easily flip the two if need be.

Neither of those are segment current limiting resistors. Flipping them won't help.

Your segment resistors are here…

Not sure why the DP needs 6K8

Oh, boy, I didn't see that. I think the modules must be shown incorrectly. Strangely the datasheet agrees. Wired that way, only one of the 3 LEDs for each segment would conduct.

But in many larger modules, LEDs are series wired because they have to be multiple to cover the entire segment area. However the DP is small so only needs one LED. The voltage drop is lower, so a higher value resistor is needed for the same current.

Anybody else think the module LED wiring is strange? :confused:
https://datasheet.lcsc.com/lcsc/1811131731_Shenzhen-Zhihao-Elec-FJ11001BH_C12189.pdf

If they really are double in series, the LED voltage drop combined could exceed Vcc which is a problem.

For that reason, a voltage measurement might actually be wise.

There are TWO 2V4 green LEDS in series for a total of 4V8 needed. Easy on a 5V0 system, not so much on a 3V3.
Red v green are DIFFERENT in more ways than just emission spectra. Engineering is checking ALL params when subbing parts.

Note that the schematic being referenced is the original from the instructables project. The OP posted a different schematic in the PDF file in the original post.

That’s helpful ! Thanks, so we ignore one of them… but which one ?

Alright, so I found some code online that can potentially help solve my issue or at the very least is a step in the right direction. I realize now that even though I am using 4 individual displays, they are acting as combined 4 digit 7 segment display (quite obvious I know, but this is all a learning process for me clearly). I wrote some code here:

#include "SevSeg.h"
SevSeg sevseg; 

void setup(){
  byte numDigits = 4;
  byte digitPins[] = {8, 10, 9, 11};
  byte segmentPins[] = {3, 2, 0, 1, TXLED0, 4, 12, 6};

  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_ANODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
}

void loop(){
    sevseg.setNumber(7777);
    sevseg.refreshDisplay(); 
}


So all 4 segments do turn on, however segment E is the one that isn't turning on, making numbers 2, 6, and 8 missing a segment (Numbers 1,3,5,7, and 9 are all good). Putting in 0000 for the numbers doesn't really work either, segment U30 on my schematic doesn't turn on at all, and U31-U33 turn on but segment E is missing. I checked continuity with a multimeter and it was present, so I'm thinking my pin assignment for pin E is wrong.

There is not a pin number defined for the TX LED Actually the pin number is 30, or LED_BUILTIN_TX. TXLED0 is a macro to output a LOW to the pin, TXLED1 is a macro to output a HIGH.

#define TXLED0      PORTD |= (1<<5)
#define TXLED1      PORTD &= ~(1<<5)

You really should have breadboarded this and done some testing before building the hardware, you may need to do a bit of re-wiring to make it work with a library. See above, use LED_BUILTIN_TX instead of TXLED0.

The way you have all the LED segments wired to a single port would make it easy to directly write to the port, but that is a rather advanced bit of coding.

Changing pin E to LED_BUILTIN_TX does work, however as soon as I change one of the four numbers the display doesn't show those numbers properly

#include "SevSeg.h"
SevSeg sevseg; 

void setup(){
  byte numDigits = 4;
  byte digitPins[] = {8, 10, 9, 11};
  byte segmentPins[] = {3, 2, 0, 1, LED_BUILTIN_TX , 4, 12, 6};

  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_ANODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
}

void loop(){
    sevseg.setNumber(3332);  
    sevseg.refreshDisplay(); 
}

The display shows 3 on digit 1, and the remaining 3 digits show 3 with segment e on. I think my pin assignment for pin C is wrong, I made it digital pin 0 which is RX on the arduino leonardo. 

Try hardwareConfig = P_TRANSISTORS instead of COMMON_ANODE.

Tried that seemed to somewhat work but now if I put 2223, the displays show 3222

Try changing the number to 1234 and see which order they are display in, the library may be going the opposite direction than you are.

Okay, got it to work had to change the digit pins from 8,10,9,11 to 11,10,8,9

hehe, now read back over the thread, and see what you learned.

Cheers

I learned that I really need a better understanding of my pin assignments... still confused as to how I'm going to display the time from what I can find online a lot of the example code has numerous errors, I tried creating an array with my pin definitions of the original code I found on instructables but that didn't seem to work either.

This is a follow up with the RTC custom PCB thread I made here: Issue coding RTC 7 segment clock

For my RTC I'm using the DS1307, and when I upload the code I get this as my output in the serial monitor.

The schematic for my PCB can be found here: Digital Clock.pdf | DocDroid

Here's the front copper of the PCB
image

Originally I had capacitors connected to the crystal as I was using a different RTC IC, then changed to the DS1307. I updated the schematic, but then forgot to update the PCB (bad mistake I know), so I'm wondering if the unpopulated capacitors C28 and C29 for crystal Y21 is causing issues. This is the serial monitor output:

Here is the code btw:

//Arduino 1.0+ Only
//Arduino 1.0+ Only
// pre-set the time in the void then use reset button to set it!

#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
printDate();
Serial.println("loopstart");
}

void loop(){
  printDate();
  delay(1000);
}

void setDateTime(){

  byte second =      00; //0-59
  byte minute =      35; //0-59
  byte hour =        15; //0-23
  byte weekDay =     7; //1-7
  byte monthDay =    15; //1-31
  byte month =       1; //1-12
  byte year  =       23; //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);
}

flagged as duplicate thread