Controlling multiple 7 segment displays

Hi All,

I am trying to create a digital clock with ability to display Time (HH:MM:SS), Temperature (##), Humidity (##) , day of week (one LED), month and year in DD:MM:YYYY.

I am planning to use the below sensors. (Please let me know if in case there is a better option)

DHT22 - Temperature and Humidity (Prefered this over SHT11 due to its accuracy) DS3231 - RTC (Prefered this over DS1307 due to its accuracy).

Here comes my main question... So for displaying purpose totally it comes to 18 7 segment displays. and 1 LED for displaying the day of the week.

(Plus, ofcourse the 4 pairs of LED for displaying the ":" .. Which is not an issue at the moment)

I have browsed through numerous videos. I see only way to control 1 - 4 7 seg display (By multiplexing/charliplexing). But i am not sure if we can control 18 7 segment displays. Please let me know if this is achievable ?? Have any one tried this before ? ..

I am tring to achieve this with 1 arduino.. I hope the number of input ports for the sensors should be available. But i am not sure about the output ports.

With Regards, S.Sudharsan

Easy way is with 3 MAX7219 chips, each driving up to 8 common cathode displays (24 total, or 18 and lots of individual/pairs of LEDs for : and whatever). Each has 8 data registers, you send the data to each register. The 3 can be daisychained, or each written to individually, with SPI.transfer - SCK, MOSI, CS, CS1, CS2 if using three chip selects. Quite easy to use with no need to get bogged down in a library. Displays can be single digit, dual digit, quad digit. All anode get connected in parallel for a group of up to 8 digits, each digit has its own common cathode. The MAX7219 can decode 0-9, H,E,L,P with built in decoding, or you can use No Decode mode and make your own fonts: 0-9, -, A,b,c,C,d,E,F,g,h,H,i,J,L,n,o,O,P,S,u,U,etc.

4-digit examples: www.kingbrightusa.com/category.asp?catalog_name=LED&category_name=KC4%2DDigit+7%2DSegment+Thru%2DHole+Display&Page=1 The CCxxxxx part numbers are the common cathode parts.

Thanks CrossRoad.. !!

I think you have answered almost of my question.. Thanks for the extra tips !! :)

At this point I am eagerly awaiting for my gear. Let me try what ever you have said..and circle back in case of any problem

Thanks & Regards, S.Sudharsan

Friends,

I got a bit confused today by a video. (may be my bad interpretation of it)

First let me tell you what I am trying to achieve. I am buying an arduino with the intention of using it as a programmer to program other chips. (bought a PIC16F873A (28 pin) ). My intention is to program this chip and permanently solder it to the circuit. Then will use a fresh PIC16F873A to burn a different program for different purpose.

So now my questions are…

  1. I see videos mentioning to use AVR. Does AVR and PIC are completely different.? I see them constantly mentioning that AVR is from Amtel and PIC is from MicroChip. So does that mean Arduino cannot be used to program a PIC microcontroller ??

  2. What is the difference between an Arduino and a PIC KIT 2 ?

  3. Does bootloader necessarily have to be flashed into an PIC to make it usable ? if NO, then what is the advantages of flashing a boot loader and not ?

  4. When I am still waiting for my gear to arrive, I am expecting that the arduino that I am buying is going to have the arduino boot loader flashed. But wanted to know if there is a way to verify if it is flashed properly ?

  5. Once ISP sketch is flashed into arduino, how to revert back ? (Meaning, using the arduino as a programmer, how to use it as a old arduino to interface with various shields.)

Thanks in advance !

I have 2 more questions..

  1. If I am multiplexing ~20 7 segment displays, will it incur flickering or dullness ?

  2. Does multiplexer and shift registers are same or they are different ??

Can somebody kindly clarify my questions ?

Regards, S.Sudharsan

harisudharsan: 1. I see videos mentioning to use AVR. Does AVR and PIC are completely different.?

Yes, they are different.

harisudharsan: I see them constantly mentioning that AVR is from Amtel and PIC is from MicroChip. So does that mean Arduino cannot be used to program a PIC microcontroller ??

Correct, it cannot be used. Theoretically, a person who was highly expert in both AVR and PIC could achieve this, but I'm not sure why they would want to.

harisudharsan: 3. Does bootloader necessarily have to be flashed into an PIC to make it usable ? if NO, then what is the advantages of flashing a boot loader and not ?

I don't know about PIC bootloaders, but I can answer the same question for AVR/Arduino. No, you can program an AVR chip that has no bootloader. You must use a separate programmer for this such as USBasp or another Arduino running the ArduinoISP sketch. The advantage of having a bootloader is that you do not need a separate programmer, you can use an ordinary USB-TTL adaptor, which you will probably need anyway to communicate with the chip when you have uploaded the program. Most Arduino have a USB-TTL converter built-in. Some do not, such as Pro Micro.

harisudharsan: 4. When I am still waiting for my gear to arrive, I am expecting that the arduino that I am buying is going to have the arduino boot loader flashed. But wanted to know if there is a way to verify if it is flashed properly ?

Try uploading a simple sketch like "Blink". If you cannot upload, the bootloader may not have been properly flashed.

harisudharsan: 5. Once ISP sketch is flashed into arduino, how to revert back ? (Meaning, using the arduino as a programmer, how to use it as a old arduino to interface with various shields.)

If you mean the ArduinoISP sketch, remove the reset-blocking capacitor and upload your new sketch.

harisudharsan: 6. If I am multiplexing ~20 7 segment displays, will it incur flickering or dullness ?

If you design and code it correctly, it will not be dull or flicker. If you do not design and code it correctly....

harisudharsan: 7. Does multiplexer and shift registers are same or they are different ??

They are different. For example on a multiplexer, only one output at a time will be active. On a shift register, any combination of outputs can be active. However, some circuits could be designed with either type of chip to perform some (but not all) functions.

Paul

Hi Paul,

Thank you very much for the reply !

Can you kindly provide more info / a comprehensive link on how to multiplex multiple 7 seg displays ?

In all the examples i see, they do it with only 1 7seg displays. I am unable to figure out how to do the same thing in case of multiple 7 segment.

Thanks in advance and Regards, S. Sudharsan

harisudharsan: Can you kindly provide more info / a comprehensive link on how to multiplex multiple 7 seg displays ?

I would give the same advice as Crossroads gave to you. Use several max7219 chips. You seemed happy with that advice before. Is there a now a reason that you cannot use these chips?

Hi harisudharsan

I'll suggest a book that is available in India

"The AVR Microcontroller and Embedded system" by Muhammad ali Mazidi,Sarmad Naimi,Sepehr Naimi released by Pearson.In that book a separate chapter for interfacing MAX7221 with AVR microcontroller is explained nicely.I learn my AVR assembly and everythink form that book.If you find time try to refer this book.You will understand the concept clearly.

I think that in ebay it costs about 125 rupees but If you visit in richie street(Mount road,Chennai),you will surely get this chip and also will be cheaper that 125 rupees.Either you buy a MAX7221 or MAX 7219.It's okay.

Hi Paul,

I am still happy with that advise. I was looking for some connection diagram to connect multiple 7 seg displays.

Now, in my today's search in my local market I found that MAX7219 is not available.

On my quick google ing, I have seen many people trying out similar thing with 74HC595. But unfortunately 74LS595 is only available to me. Looks like there is a speed lag in LS (Low speed).

So now I am confused between MAX7219 vs 74HC595 vs 74LS595 . Which would be a better option ?

I see all 3 of them are available online. But it is gonna take some time for shipment too. Can you kindly let me know if it would be really worthy waiting the time ? or the difference between them is not significant ?

I understand that the programming part will have to change depending on what chip i opt to use.

Regards, S.Sudharsan

Get the max7219.

74ls/hc595 can be used (both are much faster than needed for displays) but neither chip is a good choice for displays because their current capabilities are low, especially if you are multiplexing. These chips are general purpose logic chips and were not designed for displays. If you used them, you would need more components like series resistors for the segments and transistors for the digit connections on the displays. Also your code becomes much more complicated because the Arduino must perform the multiplexing.

By contrast, max7219/7221 was designed especially for displays so has a higher current capability, minimises the number of extra components needed and keeps your sketch simple by performing the multiplexing so that the Arduino does not have to do this.

Hi Paul,

Thanks for your Inputs and your patience to answer my question !! :slight_smile:

In the below link, it is mentioned that the length of wire should not go beyond 10cm as it might cause error. Is that because of the internal resistance offered by the wire ??

http://playground.arduino.cc/Main/MAX72XXHardware

And I assume the difference between 7219 and 7221 is ONLY the EM interference it is going to cause in case of the audio ckts. ? . I do not have to worry about it if the project i am working is not a audio based project or any thing that involves sensitive decices ?? Please let me know if it is not.

Thanks in advance,
S. Sudharsan

You can use either max7219 or 7221, it does not matter. 7219 are more common and usually cheaper.

Its not the resistance of the wires but their capacitance. The link you posted does not say you cannot go beyond 10cm, it says that it is possible there could be some problems. You must experiment to find out. Begin with sort wires, then increase the length until you reach your desired length or problems begin. If you have problems, you can try 2 techniques. One technique is to slow down the data rate. The second is to add line driver chips. How long do your wires need to be?

Hi Paul,

Thanks for you reply. I do not intend to go beyond 10 cm at this point of time because currently i am trying out breadboard circuits. But I personally felt 10cm is too short. Because if we do any circuit, the loops wire required for mounting the components will be more than 10cm quite often. So wanted to confirm if there is any problem.

When i am waiting for the 7219 to arrive, I bought a 74HC595 from a local shop and tried to drive the 7 segment display. I tried to have 2 individual 7 seg display counting 0-9. One with 500 ms delay and another with 1000 ms delay.

Now three more things :slight_smile:

  1. To do that, do i need 2 595 or I can achieve this through single chip itself ? (I just wanted to use only 3 lines from arduino latch, data and clock.)

  2. I tried out the below program to control 7 seg display. It works like a charm. I tried removing them. As expected the ckt stopped working. But one thing that i cannot understand is we manipulate the latch pin to high and low. But we do not do any manipulation with clock and data pins. How is it working here ??

int latchPin=2;
int dataPin=3;
int clockPin=4;

int animate[9]={63,95,126,125,63,111,119,123,63};
int hello[5]={9,6,71,71,64};
int n;
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  animation();
  hellog();
}
void hellog()
{
 for (n=0; n<=4; n++)
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 127);
    digitalWrite(latchPin, HIGH);
    delay(50);
    
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, hello[n]);
    digitalWrite(latchPin, HIGH);
    delay(1000);
  } 
}
void animation() {
  for (n=0; n<=8; n++)
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, animate[n]);
    digitalWrite(latchPin, HIGH);
    delay(200);
  }
}
void loop()
{

//0
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 64);
  digitalWrite(latchPin, HIGH);
  delay(1000);
//1
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 121);
  digitalWrite(latchPin, HIGH);
  delay(1000);

  //2
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 36);
  digitalWrite(latchPin, HIGH);
  delay(1000);
//3
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 48);
  digitalWrite(latchPin, HIGH);
  delay(1000);
//4
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 25);
  digitalWrite(latchPin, HIGH);
  delay(1000);

//5
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 18);
  digitalWrite(latchPin, HIGH);
  delay(1000);

//6
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 2);
  digitalWrite(latchPin, HIGH);
  delay(1000);
//7
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 120);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  //8
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 0);
  digitalWrite(latchPin, HIGH);
  delay(1000);
//9
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 24);
  digitalWrite(latchPin, HIGH);
  delay(1000);
}
  1. This is even more interesting… I compiled the program and ensured it is working 2 days back. Once I see it working, i switched off the complete ckt and my laptop. After 2days (today) i was expecting the ckt to work on just giving the power. But it do not. I flashed the same program again and it started working (without doing any kind of hardware changes). Up to my understanding, arduino do not forgets the program on power off.

Any suggestions of why this happens so.??

Regards,
S.Sudharsan

harisudharsan: ...the loops wire required for mounting the components will be more than 10cm quite often. So wanted to confirm if there is any problem.

There could be a problem, but I think there will probably not be a problem.

harisudharsan: 1. To do that, do i need 2 595 or I can achieve this through single chip itself ? (I just wanted to use only 3 lines from arduino latch, data and clock.)

You can drive 2 digits with one shift register, but you will need 2 more Arduino outputs and 2 transistors (+ base resistors). Your sketch will need to perform multiplexing.

If you don't want to use more than 3 pins, you can use a second shift register, chained to the first shift register. Then you can drive both digits directly and your sketch will not need to perform multiplexing.

harisudharsan: 2. I tried out the below program to control 7 seg display. It works like a charm. I tried removing them.

Removing what?

harisudharsan: we manipulate the latch pin to high and low. But we do not do any manipulation with clock and data pins.

The shiftOut() function manipulates the clock and data pins for you.

harisudharsan: 3. This is even more interesting.. I compiled the program and ensured it is working 2 days back. Once I see it working, i switched off the complete ckt and my laptop. After 2days (today) i was expecting the ckt to work on just giving the power. But it do not. I flashed the same program again and it started working (without doing any kind of hardware changes). Up to my understanding, arduino do not forgets the program on power off.

You are correct, it should not require re-flashing. Do you have another Arduino to try? Maybe it is faulty.

Hi Paul,

Thanks again for helping me out. Sofar it was appearing to be working good as expected.

Now stuck with a bigger issue. To make my program cleaner, i tried to use the port 1 (or 0. not sure ). Apparently it seems to be RX TX. On exploring the error I got, it loos like i am not suppose to use it on an ordinary case.

Now, the problem is, earlier my program i had on the arduino was to control 7 segment display. After doing the above mentioned mistake, i see now the 7 segment are working. But the segments are glowing in unintended fashion. Also, i am unable to get new program flashed and also the arduino is not getting detected.

Can you kindly help. Below is the error message i am getting.

Sketch uses 1,600 bytes (4%) of program storage space. Maximum is 32,256 bytes.
Global variables use 47 bytes (2%) of dynamic memory, leaving 2,001 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20

Regards, S.Sudharsan

Hi again.

Reading back from the start of this thread, i don't think you have said what type of Arduino you are using. Also i am not sure what chips you are using. Did you get the max chips yet or are you still using '595s?

The errors you are seeing are because the IDE cannot get a response from the Arduino. It may be a wiring problem or perhaps the Arduino is faulty. Please provide more details of the hardware. A picture may help, if the wiring is neat and can be followed in the picture. Do you still have any part of the circuit connected to the tx/rx pins? Could you have damaged those pins? Have you selected the correct type of Arduino in the ide menu settings?

Hi Paul,

I am using arduino UNO. At this point of time i am using 595. I started off with the exploration to understand how to control the 7 seg display. So wanted to complete the understanding before i move on to next. I shall provide you the photo of connection soon.

I have ensured that I have selected correct arduino type in the IDE. The pins are not physically damaged. I soft handle the gear.

I do not have any pins connected to RX/TX any more. Just had it connected for a moment. The moment I realized the RX TX LEDs on, I unplugged it from the USB.

What ever sketch I had earlier is still intact and working. The problem now is; On connecting the arduino to the USB, PC is unable to recognize the new device. But the 7 segment starts working (as the circuit is getting powered on).

My doubt is if the boot loader is corrupted. But if so, i am not sure how the previous sketch is still working. If i have to re-flash the boot loader again, how to do that when the device itself is not getting recognized.

Regards, S. Sudharsan

harisudharsan: The pins are not physically damaged. I soft handle the gear. I do not have any pins connected to RX/TX any more. Just had it connected for a moment. The moment I realized the RX TX LEDs on, I unplugged it from the USB.

I was more concerned about electrical damage. However, if you connected the tx/rx pins only to the clock, data and latch pins of the '595, I am certain there could not be any damage due to that mistake.

harisudharsan: My doubt is if the boot loader is corrupted. But if so, i am not sure how the previous sketch is still working. If i have to re-flash the boot loader again, how to do that when the device itself is not getting recognized.

Can you borrow a second UNO that is known to be working? Also lend your UNO to a friend and ask them to test it with a circuit that is known to be working, if possible. Also try your UNO on another PC. Try another USB cable.

But I seem to remember there was a suspected problem with your UNO before. Was that you? You said that it did not retain its program after power disconnection, and it was necessary to re-flash each time. Is that no longer the case?