6

I've got project that needed to have some (4) digits display, and had plenty of 7 seg. displays lying around. I didn't have any multiplexers left but have instead wired it up as per this diagram: enter image description here

I've the wired my duemilanove with the a-dp pins on the 13-6, and the transistors on 5-2.

Getting the right segments on has been a breeze, but I'm finding that if I have any kind of counting logic, the displays dim to about 20%. What I mean by this is that I can have my sketch run with all digits full brightness displaying 8s no problem, but if anywhere in the loop I have a variable that I increment up (say by incrementing up 1 per loop), and change nothing else, the display will go from 100% brightness, to 20% (at best).

Below is the demo code I'm using (there are tons of weird things in it at the moment as I've been desperately trying to track this dimming issue down), and all I have to change to see the effect take place is to uncomment the line at the end of the loop: "//count = count + 1;"

const int sub_delay = 1000;

const int middle_middle = 13;
const int middle_top = 11;
const int middle_bottom = 8;


const int top_left = 12;
const int top_right = 10;
const int bottom_left = 9;
const int bottom_right = 7;
//Build the digit quick table

int digits_all[] = {top_left, top_right, middle_top, middle_bottom, bottom_right, bottom_left, middle_middle};
int digits0[] = {top_left, middle_top, top_right, middle_bottom, bottom_right, bottom_left};
int digits1[] = {top_right, bottom_right};
int digits2[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_left};
int digits3[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_right};
int digits4[] = {};
int digits5[] = {};
int digit_selector0 = 2;
int digit_selector1 = 3;
int digit_selector2 = 4;
int digit_selector3 = 5;
int digit_selectors[] = {digit_selector0, digit_selector1, digit_selector2, digit_selector3};

int last = digits_all;
int last_size = sizeof(digits_all);
int last_selector = digit_selector0;


String test = "12, 13, 10, 8, 7, 9";

int count = 0;



// the setup function runs once when you press reset or power the board
void setup() {
  //Initialize the digit segments
  for (int c = 0; c < sizeof(digits0); c++) {
    //digitalWrite(digits0[c], HIGH);
    pinMode(digits0[c], OUTPUT);
  }


//demo
  //digitalWrite(middle_middle, HIGH);
  //digitalWrite(top_left, HIGH);
  //digitalWrite(middle_top, HIGH);
  //digitalWrite(top_right, HIGH);
  //digitalWrite(bottom_left, HIGH);
  //digitalWrite(middle_bottom, HIGH);
  //digitalWrite(bottom_right, HIGH);

    Serial.begin(9600);

}

void turn_off_all (int digit, int digits[], int digits_size, int num) {

  last = digits;
  last_size = digits_size;

  digitalWrite(last_selector, LOW);
  last_selector = digit;

  digitalWrite(digit, HIGH);
int temp = 1;
  if (num == 0) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(middle_middle, LOW);
  }

  if (num == 1) {
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);

    digitalWrite(top_left, LOW);
    digitalWrite(middle_bottom, LOW);
    digitalWrite(bottom_left, LOW);
    digitalWrite(middle_top, LOW);
    digitalWrite(middle_middle, LOW);    
  }

  if (num == 2) {
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_left, HIGH);


    digitalWrite(top_left, LOW);
    digitalWrite(bottom_right, LOW);    
  }

  if (num == 3) {
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);

    digitalWrite(top_left, LOW);
    digitalWrite(bottom_left, LOW);
  }

  if (num == 4) {
    digitalWrite(top_right, HIGH);
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_middle, HIGH);

    digitalWrite(middle_bottom, LOW);
    digitalWrite(middle_top, LOW);
    digitalWrite(bottom_left, LOW);
  }

  if (num == 5) {
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(top_right, LOW);
    digitalWrite(bottom_left, LOW);
  }    

  if (num == 6) {
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(top_right, LOW);
  }    

  if (num == 7) {
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_top, HIGH);


    digitalWrite(bottom_left, LOW);
    digitalWrite(middle_bottom, LOW);
    digitalWrite(middle_middle, LOW);
    digitalWrite(top_left, LOW);
  }    

  if (num == 8) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);
  }    

  if (num == 9) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_bottom, HIGH);

    digitalWrite(bottom_left, LOW);
  }    








}

// the loop function runs over and over again forever
void loop() {


    turn_off_all(digit_selector0, digits0, sizeof(digits0), 1);
  delay(1000);

  //count = count + 1;




}

Any suggestions welcome!

Extra notes: I haven't yet tried another arduino board, but I've never had issues with this particular board before (Though I am hoping to switch to an ESP8622, but that is irrelevant to this issue).

  • You can try to change "digitalWrite" into directly assign to the PORT. It will be a lot more efficient – dhimaspw Nov 14 '16 at 1:21
  • It is often because of a lack of current. Use an external 5V supply some good enough current. – Dat Ha Nov 14 '16 at 1:31
  • I'm definitely open to it being a current issue, but that doesn't explain why it would only occur if I start counting (or seemingly any other math op) – Shane Gadsby Nov 14 '16 at 2:31
  • @dpw: I'll look into that and see if the increased efficiency helps at all – Shane Gadsby Nov 14 '16 at 2:32
  • 1
    I don't see how count is relevant to the function. Is this also the same code you used to turn on all the segments? – TisteAndii Nov 14 '16 at 3:18
2

You seem to be trying to do this from scratch. I haven't analysed the code, but you would be better off using one of the established libraries.

The code is unclear - I am not sure what much of it is trying to do (a few comments would help). There are obvious errors - in particular the incorrect use of sizeof() which is a common error.

I use the following http://playground.arduino.cc/Main/SevenSegmentLibrary

This just requires a single call to set the digits to be displayed and includes a Brightness call.

  • I did start with this, and seemed to have the same results, so I went the manual route to see if that pinpointed the issue; I'll try it again just to be extra sure however! – Shane Gadsby Nov 14 '16 at 2:30
  • If you posted your original code using the library it would be easier to debug. Also add some comments. – Milliways Nov 14 '16 at 2:32
  • Further to the wrong use of sizeof: if I change it from that I get the dimming issues again, haha, which is even more puzzling... I'll re-write it with the 7-seg lib and post it (assuming it still fails), and yeah, more comments == more better – Shane Gadsby Nov 14 '16 at 2:33
  • 2
    I assume you are trying to get the number of elements. The correct use would be (sizeof(digits0)/sizeof(int)) – Milliways Nov 14 '16 at 2:36
  • I didn't get it working how I wanted it to with this library, but it certainly is the better option over all - thanks again for showing me the correct usage of sizeof! – Shane Gadsby Nov 20 '16 at 22:36
1

If, as comments suggest, the problem also occurs when you are using a library, it's possible the problem is hardware related. The 10KΩ base resistors are inordinately large, and are so large the transistors probably are limiting the total current per display to under 50 mA.

When you turn on one of d2 ... d5 (your digit-select drives), at most half a milliamp (5V/10KΩ) will enter the base. If transistor beta is 100, that will allow 50 mA to flow. (Not knowing the transistor type you used, I don't know its range of betas.)

Consider replacing the 10KΩ base resistors with 500-700 Ω resistors.

I see no place in the circuit where capacitors would make any positive difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.