Hi, all.
The project in MagPi 67 to put a Pi in a ZX Spectrum case sounds fun. (Unfortunately, the keyboard is the only part of my venerable Speccy that doesn't work; though my Interface 1 is duff too )
I'm a little baffled as to why there are diodes on the 'address' lines connected to the keyboard, though. Wouldn't it be possible to program the relevant GPIO pins as open-drain outputs? (The inputs would be programmed to have pull-ups.) Then the address lines could be shorted together harmlessly.

Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

Diodes are usually used on a keyboard matrix to allow detection of multiple keys at once.

If the Spectrum uses the address bus directly to scan the keyboard then diodes would be important to prevent multiple keys shorting address lines together, which would be a very bad thing. Are the diodes you mention a legacy of the Spectrum or part of the Pi interface?

I looked up the article.https://www.raspberrypi.org/magpi-issues/MagPi67.pdf
I agree the diodes aren't strictly necessary, but it might be preferabl to just configure column gpios as outputs and set themes high and low rather than having to tristate them )reconfigure as inputs in the idel state) . In that case you don't want to risk shorting columns together as that risks damage to the gpio.

Are the diodes you mention a legacy of the Spectrum or part of the Pi interface?

Part of the Pi interface. Effectively they're converting totem-pole outputs to open-drain ones... but you can effectively program the GPIOs to be open-drain outputs. Admittedly, adding the diode removes the possibility of a low output being connection to a high output due to a programming error.

Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

Admittedly, adding the diode removes the possibility of a low output being connection to a high output due to a programming error.

Not just a programming error. Running any other gpio program on that hardware which configures those gpio as output risks damage. If the hardware is dedicated to a single task it's not a problem, but having a keyboard hints at a more general purpose approach. The diodes are not essential but they seem to me to be a reasonable safety measure. 100R resistors would work as an alternative, just limiting short circuit current. It's a good idea to never connect a switch contact between two outputs. It's no bad thing to put a resistor in series with a switch to GND or VCC for the same reason. The gpio you intended to always be an input might get configured as an output of opposite polarity and result in an over-current condition.

Although... with the keyboard plugged in, if you press 2 keys on the same address line at the same time, that shorts together 2 of the 'data' GPIOs. So, by the same logic, you should have diodes on those lines too

Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

Although... with the keyboard plugged in, if you press 2 keys on the same address line at the same time, that shorts together 2 of the 'data' GPIOs. So, by the same logic, you should have diodes on those lines too

Making it indestructible does get a bit ridiculous for such a cheap SBC. It wouldn't be unreasonable to connect it directly and accept the small risk that you later do something that kills something on the Pi.

First line of defence can be the pins you know will be set as outputs. If you are a cautious or pessimistic person (or prone to mash the keyboard in frustration when your gpio experiments aren't working) why not put diodes or resistors on the rows as well?

The diodes are not essential but they seem to me to be a reasonable safety measure.

OK. You've convinced me.

I'm less convinced. Diodes may provide protection for the GPIO driving rows but there's no equivalent protection for reading columns.

I am less inclined to believe the author added them for protection against unexpected circumstances than I am in believing the author may simply have not been aware of the open-drain mode of use which avoids the need for diodes.

The diodes are needed, as noted, if the rows are always driven high and low, are a necessity to avoid damage, and I think that's why they are there. Looking at the source code will show how the author implemented their scan routine, whether it mandates diodes or not.

The diodes are needed, as noted, if the rows are always driven high and low, are a necessity to avoid damage, and I think that's why they are there. Looking at the source code will show how the author implemented their scan routine, whether it mandates diodes or not.

Indeed. My first paying job was designing embedded computers, so it still seems weird to me to use unnecessary components. (I was told my first product would retail for £100. "Oh, that's OK," I thought... then they told me what a pitiful fraction of that I could spend on components!)