Arduino Mega with double 7 segment display

Hello everybody!
I am Daniele, a completely new user of Arduino and programming in general. Probably I haven't choose the easyest project to work on as a starting point but I like new challenges and learning with experience.

I have got an Arduino Mega 2560 and I am trying to connect it to a double 7 digit display in order to display some values that from a determined website. Obviously before entering the "go on the internet and print me this value" part on the code I would be please if I could at least make the arduino display any predetermined double digit value on the display. So far through tutorial I have only managed to work on 1 digit at the time to display values from 0 to 9, now its time to step it up. I am attaching a list of specs and my connections.
Basicly I am considering each segment as a separate LED and connecting it through a 220Ω resistor to an arduino Pin. I am aware there is probably a way simplier approach through the use of other transistor or chips but since my knowledge of eletronics and coding is absolutely zero I though about trying to use less components as possible.

Can someone give me some guidelines on where I should start the coding for this?
I imagine I will need to define what segment to turn on in order to display each number but besides that I am pretty lost, expecially once I pass number 9.

Thanks a lot to whoever can help me out!

ieee488:
http://www.hobbytronics.co.uk/arduino-4digit-7segment

That is a bad example in my opinion. It uses no series resistors and claims that by using pwm they are not needed. It is also badly written code.

Daniele, i can help you with some code tomorrow evening, if you still need it.

Paul

PaulRB:
That is a bad example in my opinion. It uses no series resistors and claims that by using pwm they are not needed. It is also badly written code.

Daniele, i can help you with some code tomorrow evening, if you still need it.

Paul

There's probably a better one out there.

The point is to do some research by Googling.

PaulRB:
That is a bad example in my opinion. It uses no series resistors and claims that by using pwm they are not needed. It is also badly written code.

Daniele, i can help you with some code tomorrow evening, if you still need it.

Paul

That would be amazing Paul, in the meantime I am also trying a different layout in which all same segments of each digit are connected to each other and then to the arduino. Basicly trying to replicate this layout (check attachment). Let me know which one do you think would be the easiest to code!

ieee488:
There's probably a better one out there.

The point is to do some research by Googling.

I tried googling but I have been struggling with finding a clear example with a double digit display, most of them are single or 4 digit and only act as counters or clocks.

Screen Shot 2016-02-23 at 00.52.27.png

That method will work. If you cycling thru all 14 segments one at a time, then you just need 2 current limit resistors on the 2 common cathode pins.
The code checks for a1 on, cathode 1 on, etc thru a7 on, cathode 1 on, then b2 on , cathode 2 on etc thru b7.

So, just to clarify to whoever is going to help me, these are the 2 design I am working with. Which one do you recon will be easier to code? Please bare in mind that for the final project I will have to effectivly double everything as I need to connect a second DOUBLE digit display.

Thank you very much guys!

"Data sheet":


You have not actually told us which type of display you have. The above diagram shows two versions: common cathode and common anode. Your designs below indicate you have common anode. Is that correct?

Design 1:


(You made a mistake there. You need to connect the common pins to 5V, not Ground)

Design 2:

Rovers:
So, just to clarify to whoever is going to help me, these are the 2 design I am working with. Which one do you recon will be easier to code? Please bare in mind that for the final project I will have to effectivly double everything as I need to connect a second DOUBLE digit display.

Your first design is easier to code because it does not involve multiplexing. The downside is that it uses almost twice as many Arduino pins.

Your second design uses fewer pins but will make the code more complex because multiplexing will be needed. Also, the display will be significantly dimmer, because the multiplexing ratio will be 1:8 (i.e. each segment will be on for only one eighth of the time. You can compensate a little for this by reducing the value of the series resistors, but you must not go so low that the Arduino pins have to source more than 40mA (30mA would be better in the long term).

For 4 digits, your first design will require 32 arduino outputs, but the code will still be simpler. Your second design will only require 12 outputs.

There are other options too. Chips and modules are available which will perform the multiplexing for you, and/or reduce the number of Arduino outputs needed. These include 74hc595, tpic6*595, max7219, saa1064...

Thanks for the reply Paul, everything is starting to make sense. At this point I think I might go with the first design since it will be easier to code. I am not worried about the number of pins since the Arduino mega has plenty of them. I just double checked and my display is the LB-602MK2 so it is COMMON CATHODE according to this datasheet. http://rohmfs.rohm.com/en/products/databook/datasheet/opto/led_display/numeric/lb-602ak2.pdf

I tried to correct the first design for a common cathode display, does this look right?

I considered the multiplexing option because I read somewhere that powering a total of 4 digit display would drain to much power from the arduino, are you saying I should actually be fine with multiplexing?

Thanks again!

Oh, so you're up to 4 digits now? Then a MAX7219 to control them would be easier to code for. It takes care of the multiplexing, you just put data into 1 for 4 registers with simple commands, such as SPI.transfer(), or shiftOut():

digitalWrite (csPin, LOW);
SPI.transfer (addressRegister); // 1 to 8 for digit select
SPI.transfer (dataToDisplay); // built in font decode handles 0-9, -, blank, H,E,L,P, or send your own
digitalWrite (csPin, HIGH);

$3 at www.taydaelectronics.com, add 0.1uF cap and 10uF cap, 10K current limit resistor.
MAX7219 drives high on the common segment pins, and one common cathode low at a time, to turn a digit on.

Your Rev3 design will work as well, be sure to observe the current limit per pin (20mA) and per port:

Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady
state conditions (non-transient), the following must be observed:
ATmega640/1280/2560:
1)The sum of all IOH, for ports J0-J7, G2, A0-A7 should not exceed 200mA.
2)The sum of all IOH, for ports C0-C7, G0-G1, D0-D7, L0-L7 should not exceed 200mA.
3)The sum of all IOH, for ports G3-G4, B0-B7, H0-H7 should not exceed 200mA.
4)The sum of all IOH, for ports E0-E7, G5 should not exceed 100mA.
5)The sum of all IOH, for ports F0-F7, K0-K7 should not exceed 100mA.
If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current
greater than the listed test condition.

As Crosroads says, the design is ok but as you suspect, there is potential to use quite a lot of current. But this can easilly be adjusted down using the right value series resistors. 5mA per segment might be enough. The forward voltage of your green segments is 2.1V, so series resistors should be around (5 - 2.1) / 0.005 = 500R so 510R is the closest common value.

Do you still need some help with code?

PaulRB:
The forward voltage of your green segments is 2.1V, so series resistors should be around (5 - 2.1) / 0.005 = 500R so 510R is the closest common value.

Do you still need some help with code?

Isn't (5 - 2.1) / 0.005 = 580? Should I use 510Ω or 580Ω resistor? I have 220 and 330, is it entire blasphemy putting them in series to get 550Ω? I am just wondering since I had to order them from the internet as I couldn't find a place around here to buy them for a decent price.

Yes, help with the code would be much appreaciate!
Thanks

Sorry, yes, i must have been tired, its 580R. Yes, you can use 330+220R, or just use 330 R for now. 330R will mean (5-2.1)/330=8.7mA per segment and 281mA overall for 4 digits (including decimal points). This will be ok for the Mega as long as you spread the load around as per Crossroads' extract from the data sheet. You can experiment with series resistors from around 100R and 1K to see how bright you want the display, but with lower values, watch those currents!

So for now it will just be 2 digits? Connect it up and post the pin numbers you have used for segments "a" to "g" for each digit. I will try to give you a bit of starter code this evening (assuming my internet connection does not go down for half the evening like it did yesterday!).

Ok, since I won't be using the decimal points in any of them I'll stick with the 330R for now as they seem the right brightness. I think yes for now I'll stick to only 2 digits to make life easier, do you think adding 2 more digits later will be manageble just by tweaking the code?

Here is the updated diagram with the connection between segments and arduino pin. I added a little switch to the grounds so that I can just turn everything ON and OFF. Let me know what you think!

Thanks

Give this a try (1st attempt!):

#define DIGITS 2

const byte segmentPin[DIGITS][7] = {
  {8,7,6,5,4,3,2},
  {15,14,13,12,11,10,9}
};

const byte digitPattern[10] = {
  0b1111110,
  0b0110000,
  0b1101101,
  0b1111001,
  0b0110011,
  0b1011011,
  0b1011111,
  0b1110000,
  0b1111111,
  0b1111011
};

void setup() {
  //set all segment pins as outputs
  for (byte digit=0; digit<=DIGITS; digit++) {
    for (byte segment=0; segment<=7; segment++) {
      pinMode(segmentPin[digit][segment], OUTPUT);
    }
  }
}

void loop() {
  
  //Show all values from 00 to 99 in turn for 1 second each
  for (int value=0; value<=99; value++) {

    //take a copy of the value to be displayed
    int tempValue = value;

    //Set all digits to show the required value
    for (byte digit=0; digit<=DIGITS; digit++) {

      //Calculate the digit
      byte thisDigit = tempValue % 10;
      //look up the segment pattern needed to display the digit
      byte thisPattern = digitPattern[thisDigit];
      //Calculate remaining digits of the number to be displayed
      tempValue /= 10;

      //Set the segments for this digit
      for (byte segment=0; segment<=7; segment++) {
        digitalWrite(segmentPin[digit][segment], bitRead(thisPattern, segment));
      }
    }
    delay(1000);
  }
}

Is this the first sketch you ever uploaded to the Mega?

The sketch has no errors, but the upload to the Mega is failing.

EDIT: Oh, your post disappeared! Hopefully you are having another go. Did you select the correct Port from the Tools menu?

Yes I deleted the post because I figgure out the problem, wrong USB port on my laptop it seemed.
Anyway I am getting the display to light up but not making much sense at the moment. I am getting numbers and partial numbers in random order or even random segments.

EDIT: I have done a little video to show you but its too large to upload as an attachment...

Can you post ot to youtube or somewhere and post the link here?

Otherwise, change the delay(1000) to delay(10000) and take a picture of the first set of segments that show and post that here.