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.

aitor
  • 165
  • 4
  • related if not dupe: https://raspberrypi.stackexchange.com/q/4749/19949 https://raspberrypi.stackexchange.com/q/14412/19949 https://raspberrypi.stackexchange.com/q/63404/19949 https://raspberrypi.stackexchange.com/q/7499/19949 Some of the answers to those questions might be of interest to you. – Ghanima May 06 '20 at 21:24

2 Answers2

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.

joan
  • 67,803
  • 5
  • 67
  • 102
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.

BalooRM
  • 183
  • 1
  • 6
  • 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 May 06 '20 at 21:39
  • Beautiful! I'm researching this way. Thanks. – aitor May 07 '20 at 09: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](https://www.electronics-tutorials.ws/sequential/seq_5.html). The [74HC595](http://www.ti.com/lit/ds/symlink/sn74hc595.pdf?ts=1588851271400) is an example. Multiple 74HC595s can be [daisy chained](https://www.marginallyclever.com/2017/02/daisy-chain-74hc595n-shift-registers/) for more bits. – BalooRM May 07 '20 at 11:42