Go Down

Topic: Arduino Mega with double 7 segment display (Read 7401 times) previous topic - next topic


Feb 24, 2016, 06:40 pm Last Edit: Feb 24, 2016, 06:50 pm by Rovers
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!



Feb 24, 2016, 07:19 pm Last Edit: Feb 24, 2016, 08:05 pm by PaulRB

Give this a try (1st attempt!):
Code: [Select]
#define DIGITS 2

const byte segmentPin[DIGITS][7] = {

const byte digitPattern[10] = {

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));


Feb 24, 2016, 08:24 pm Last Edit: Feb 24, 2016, 08:31 pm by PaulRB
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?


Feb 24, 2016, 08:38 pm Last Edit: Feb 24, 2016, 08:44 pm by Rovers
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.


Feb 24, 2016, 08:57 pm Last Edit: Feb 24, 2016, 09:08 pm by Rovers
Here it is! my filmmaking masterpiece! Obviously with the delay at 1000.



Feb 24, 2016, 11:07 pm Last Edit: Feb 24, 2016, 11:09 pm by PaulRB
Hmm.. some odd things happening there. Suspect i made some errors in my code, but also some of those things could have been caused by wiring errors. Have you checked them all?

Try this change:
Code: [Select]

const byte segmentPin[DIGITS][7] = {


Feb 24, 2016, 11:23 pm Last Edit: Feb 25, 2016, 12:08 am by Rovers
here is second result: https://youtu.be/mfvT7jgPM4c
I'll double check all the connections but I am pretty confident in those.
It is supposed to count from 00 to 99 correct?

EDIT: Wait a moment! I found a mistake in my wiring and with the second change the display counts "almost" right, here is the video: https://youtu.be/f_T6SmO-Chs


Feb 25, 2016, 12:17 am Last Edit: Feb 25, 2016, 12:21 am by PaulRB
Can you describe it, I'm having problems with youtube this evening for some reason.

EDIT: i can see the latest video now. Very strange!


Feb 25, 2016, 12:35 am Last Edit: Feb 25, 2016, 12:45 am by Rovers
It's weird because all numbers are light up in the correct way at at least one moment, so the wiring must be right now. But then it loses it every so often, especially the left digit.

EDIT: Also I just tried to change the delay and now differents number are wrong and right from the original delay.


Feb 25, 2016, 07:32 am Last Edit: Feb 25, 2016, 08:06 am by PaulRB
Curious. There's no way the delay value should change the segments that are lit.

We need to try some things to try to work out what's happening. The Mega has lots of digital outputs, so choose a different set of 16 and try those. Can you see how to change the code for the new pins?

Another possibility is memory corruption because of a coding error.  But I've read through the code carefully and can't see where that could be happening. Any other forum members watching this thread? We could do with another pair of eyes on this.


Feb 25, 2016, 12:26 pm Last Edit: Feb 25, 2016, 12:56 pm by Rovers
I tried the system with all 3 arduino mega board I got, one of which is R3, and the result is the same. Now I'll try moving the I/O around, I should be able to change the code by myself. I got these board from ebay so I don't have the 100% guarantee that are fully functional but 3/3 with the same errors seems like a constant. Altrough I have to say the boards are all "slightly different" from each others in terms of colour, white text on the board (just the aesthetic layout, positions is exactly the same) and credit at the back of the board.

Now a newbie question: since the project I am working towards is not actually making the arduino count to 99 is it worth moving forward knowing that the digits are correctly wired and, let's say, if I need to display a certain number (01,02,03,04,05,06,07,08,09,10,11,12,13 etc...) the board "knows" what to light up?

EDIT: Changing the I/O, now from 16 to 29, outputs differents errors like when changing the delay.
I am getting more and more confused.


New development:
I redone the system on https://123d.circuits.io/ and run the same exact code so everything seems to be counting fine!!!! So now I am scared, are all my 3 boards corrupted? Is there anything I can do?


New development:
I redone the system on https://123d.circuits.io/ and run the same exact code so everything seems to be counting fine!!!! So now I am scared, are all my 3 boards corrupted? Is there anything I can do?
Normally we get the opposite problem. People using 123d circuits complain here that they can't get their sketch to run correctly, we try the same sketch on a real Arduino and it is works fine. For once, we seem to have the opposite problem.

Do you have any other (real) Arduino to try? If not, I may get time this evening to knock up the same circuit using a Nano 3.


I have an Ethernet Shield that I was going to use for the next part of the project. I only has limited I/O but I should be able to test 1 digit at the time, just need to figgure out how to load the code through Micro Sd as I have never done it.

Go Up