3

Good afternoon, I am starting with GPIO and python and the first project I wanted to do is a calendar with a led that illuminates each day of the month. I have been reading on the subject and it seems something apparently very simple, but I find a problem that I do not know how to solve:

The Rpi 1B has only 26 pins and, if I have not misunderstood, I need one pin for each LED, that is, 31 pins (one for each day of the month).

It is right? Can the project be done using only the 25 available pins? If not, can the pins be expanded in any way? In summary, how can the project be approached?

Thank you.

1

2 Answers 2

5

If you want to illuminate a distinct LED for each day you will need more GPIO.

I suggest you add one or more I2C based port expanders such as the MCP23017.

There are plenty of helpful tutorials showing how to use the chip with the Raspberry Pi.

4

This is an excellent opportunity to explore using a multiplexer or MUX. A multiplexer/demultiplexer uses only as many GPIO pins as you need bits to define an address (plus power and control). Since you have, at most, 31 days in a month, you can use 5 bits to count to 32 (or 0..31).

I've used the CD74HC4067 in a package like this one with an Arduino UNO to use 4 I/O pins to address 16 individual inputs. It will work for outputs, too.

Probably, the easiest implementation would be to connect your LEDs through current-limiting resistors to a supply voltage (+5 or Vcc) and to ground them to pins on the MUX. When you output the address of an LED on the GPIO to the MUX, you will turn on the LED corresponding to the address.

This MUX can address 16 LEDs. Two of them can handle 32. You may be able to find a 32 I/O MUX or construct one from components on a breadboard.

3
  • My mentioning the MUX as an option is not intended to detract from the MCP23017 solution. It is an elegant solution and appropriate here. It uses fewer GPIO pins. For me, I2C was not fast enough, so I chose parallel addressing of my 4 address bits.
    – BalooRM
    Commented May 6, 2020 at 21:39
  • Beautiful! I'm researching this way. Thanks.
    – aitor
    Commented May 7, 2020 at 9:10
  • There are multiple ways to solve many problems. Another way, that might be even simpler, is to use a serial-in parallel-out shift register. The 74HC595 is an example. Multiple 74HC595s can be daisy chained for more bits.
    – BalooRM
    Commented May 7, 2020 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.