# Driving a 3 digit 7 segment LED with MCP23017

#### ilium007

Joined Aug 24, 2013
139
I need to drive a common anode 3 digit 7 segment LED from a microcontroller. The device has one common anode per digit. I will be writing the multiplexing code to control.

I don't want to consume 11 pins on the microcontroller so the obvious choice is some sort of IO expander. I see products using shift registers but I'd like try and use the I2C interface available on the microcontroller.

I'm considering using a single MCP23017 to drive 3 small PNP MOSFETs for the common anode pins and then directly drive the 8 LED segments via current limiting resistors.

I don't see any other way around using the PNP MOSFETs as the MCP23017 has a max 25mA rating per I/O pin sinking or sourcing.

If I ran the LED segments at 5mA each I would be sourcing 45mA on the anode pins (12,9,8 below). I'm not even sure if I could source current from one MCP23017 pin and then sink it into another.

If I used a shift registers such as the 8-bit TPIC6B595 I would need 2 for 11 pins on the display.

I realise there may be LED driver IC's also but liked the idea of I2C control of these little displays.

#### dl324

Joined Mar 30, 2015
14,462
I don't want to consume 11 pins on the microcontroller
How many pins are you willing to use?

#### MrChips

Joined Oct 2, 2009
26,099
You can use a 74LS47 BCD to 7-segment decoder/driver (5V operation) to take 4-bit BCD from your MCU.
This reduces the number of output pins from 10 to 7 (sans decimal point).

Or you can use a serial communication interface which can potentially reduce the number of I/O pins to one.

#### Ian0

Joined Aug 7, 2020
5,137
Do you have time for the software overhead required for multiplexing? If not try the Texas TLC5952. Only 3 GPIO required. Even easier if you have a spare SPI port. Constant current outputs, so no limiting resistors required.

#### djsfantasi

Joined Apr 11, 2010
8,324
What was your reasoning for not using a 74HC595? Only that you want to use I2C?

Because an I2C solution is more complicated device count-wise, power-wise, software-wise (albeit the complexity is hidden and may only affect resources available for the remainder of the functions)…

Joined Feb 20, 2016
4,134
Why do you want to use LEDs?
My choice would be an I2C LCD or OLED display. Way more versatile.
But using the 74LS47 as @MrChips mentioned as the segment driver is a good idea.
The display multiplexing will take a fair bit of your processing time. It could be a good learning project to get it all going well.

#### MrSalts

Joined Apr 2, 2020
1,762
If you're going the I/O expander route with l2C, you may as well use an LED driver chip that woks the same way but allows current control (and possibly switch scanning).
one example is below but shortages limit options.
https://www.mouser.com/ProductDetail/Maxim-Integrated/MAX6955AAX+?qs=1THa7WoU59HHiplILEoAzQ==

That MAX6955 ic is $30.77 AUD !!!! With no stock in Australia. #### MrSalts Joined Apr 2, 2020 1,762 That MAX6955 ic is$30.77 AUD !!!! With no stock in Australia.
There are similar chips, that was just one I've used before and it was about 3 USD at the time. LEDs are an expensive display option these days. As mentioned above, LCD with back light can be cheaper and easier to mount for a hidden until lit effect behind tinted glass or plastic.

#### Ian0

Joined Aug 7, 2020
5,137
TLC5952 would require exactly the same software as 74HC595, and requires only 3 pins.

#### MrChips

Joined Oct 2, 2009
26,099
Here are some options for serial interfaced 7-segment LED displays.

MAX7219 interfaces with common cathode 7-segment LED displays.
MAX6950

TM1637 for common anode 7-segment LED displays

You can buy a completely assembled display module.
TM1637 4-digit LED display module

#### Ya’akov

Joined Jan 27, 2019
5,660
I saw that you said you weren’t interested in an LED driver, but just in case you decide to take an alternate route, the MAX7219 handles 7 segment displays and there is a MicroPython library available.

Just one thing: The price is high if you buy from ”reputable” dealers. Adafruit has them for ~$13 a piece! But, I recently bought 5 8 digit 7-segment display boards with both a MAX7219 and the LEDs for ~13. They work perfectly. The chip is in an SOP so desoldering it wouldn’t be very difficult. You also get bonus display parts if you need or want them. So not as a suggestion to replace your learning project but as a data point should you decide to go a different way, there it is. Thread Starter #### ilium007 Joined Aug 24, 2013 139 There are similar chips, that was just one I've used before and it was about 3 USD at the time. LEDs are an expensive display option these days. As mentioned above, LCD with back light can be cheaper and easier to mount for a hidden until lit effect behind tinted glass or plastic. I’ll look into LCDs. Hadn’t considered them until now. Thread Starter #### ilium007 Joined Aug 24, 2013 139 I saw that you said you weren’t interested in an LED driver, but just in case you decide to take an alternate route, the MAX7219 handles 7 segment displays and there is a MicroPython library available. Just one thing: The price is high if you buy from ”reputable” dealers. Adafruit has them for ~$13 a piece! But, I recently bought 5 8 digit 7-segment display boards with both a MAX7219 and the LEDs for ~13. They work perfectly. The chip is in an SOP so desoldering it wouldn’t be very difficult. You also get bonus display parts if you need or want them.

So not as a suggestion to replace your learning project but as a data point should you decide to go a different way, there it is.
Excellent, I hadn’t thought of reclaiming components from other products like this. The MAX7219 looks perfect.

#### ilium007

Joined Aug 24, 2013
139

#### ilium007

Joined Aug 24, 2013
139
I think I’m going to go for one of the dedicated LED driver ICs.

Joined Feb 20, 2016
4,134
I the past few weeks I’ve had two OLED displays fail (screen so dim they’re unusable) and thought an LED segment display may be more robust. Also the project is running micropython and I’m not sure how big the oled display libraries are.
I wonder why they failed. Did they overheat? If it is a hot environment, LEDs may be bet to stick with.
Just a note, I have had LED displays fail too. (but no OLEDs as yet, other than the 3.3V displays I tried on 5V !!)

You can buy a completely assembled display module.
TM1637 4-digit LED display module

6 off these for \$24AU is not too bad.