Hi
I want to interface 4 digit 7-segment display to my project containing arduino mega. Most of pins of mega are already being used for interfacing with 20x4 LCD, keypad, arduino nano and thermal printer. Now only A0-A12 pins are free on arduino. Now I have different options to interface 7-seg with my mega
1 directly interface 7-seg using arduino library
2 using shift registers and shiftout() function like this
3 using bcd to 7 segment decoder ics
I know all of these can work, but I want to know which one will be more resilient to EMI and sturdy and also less compute expensive for my arduino.
I guess the 4 digit 7 segment display has 12 or so pins
The easiest is to use a MAX7219 or MAX7221 chip especially if your display is common cathode device. Then you don't have to handle multiplexing and you don't have to have current limiting resistors on the segments.
Also you have port multiplier options. You may be able to free some pins by converting your LCD display to I2C with a backpack (only 4 wires including power)
If you haven't yet chosen your 4 digit display, you can get one which includes a driver chip which needs far less pins that connecting the raw display.
It will only need 2 I/O to control. I would also get an I2C backpack for your LCD which would free up more pins on the same 2 I/O as long as they have different I2C addresses.
I'd be looking at the TM1637 IC, which is commonly used with such displays (you can easily buy display modules with that chip in place). Just two I/O pins needed to control the thing, but not I2C.
wvmarle:
Just two I/O pins needed to control the thing, but not I2C.
Which means that with the TM1637, you need one pin per display plus one for all, while with I2C you can easily have eight displays on the same two I2C lines as other devices.
With the MAX7219 (common cathode or common anode does not matter much), three pins to control more than eight.
Paul__B:
Which means that with the TM1637, you need one pin per display plus one for all, while with I2C you can easily have eight displays on the same two I2C lines as other devices.
OP mentions a single 4-digit display, and doesn't mention I2C being in use already. Based on that it appears both solutions will take the same number of pins; with the MAX7219 solution using a pin more. Of course if the 2004 display gets its own I2C backpack the two displays could share the same I2C bus, saving the most pins overall.
I think max7219 option is great. I have written code and simulated in proteus, works ok.
But I have only one question Is this good solution for industrial environment and my display could be 3 feet far from mega
I mean can SPI handle data at low speed upto distance of three feet without using line drivers?
Speed was not big concern. So i am using shiftout function instead of any library or spi hardware
Shielded 22 AWG twisted pair cables have capacitance in the range of 100-240 pF/m. So the maximum bus length of an I2C link is about 1 meter at 100 Kbaud, or 10 meters at 10 Kbaud. Unshielded cable typically has much less capacitance, but should only be used within an otherwise shielded enclosure.
For a given data rate, the maximum number of devices on the bus is limited by the capacitance on the SDA and SCL pins, and is also a function of the pull-up resistance values on the SDA and SCL lines. Using the 4.7k ohms pull-up values, the I2C port is capable of data transfer rates up to 100 kilobits per second with maximum bus loading of 170 picofarads (pF). Adding parallel 3.3K resistors to the SDA and SCL lines brings the equivalent pull-up resistance down to 2K, and allows 100 KHz signaling with bus capacitance as high as 400 pF.
Very different protocol (push/pull signals instead of open collector) so it has its own limitations. Bus capacitance is of course the main parameter, as explained a.o. here.
wolframore:
I thought we were discussing freeing up pins by utilizing I2C? I'm still in the that's the easiest and best solution for this project.
My Main concern was not less pins but solution in which most of multiplexing load is not on microcontroller and is more resilient to noise and I think MAX7219 is best. What do you say?
I ordered the components but got wrong ones, I will test my circuit with MAX7219 and two 4-digit segments and will update its performance in industrial environment with 3 feet cable.