A simple buffer would do. This could be something like two transistors, a logic gate (a single non-inverting one or two inverting ones in series), or a comparator/opamp.
I'd hoped that LED2 would show me the output state of GPIO6 but of course my circuit is bad because when I close the switch, the LED drains straight through GPIO6 without limiting the current. My circuit is complete rubbish but I hope it gives an idea of what I was trying to do
The reason I'm showing you this is just to give you an idea of what I was hoping for - something that shows the input (ie. LED1 when the switch is closed) or the output (LED2).
I'm not sure how the data input to the GPIO would connect to your 3 examples.
Well, 'rubbish' is of course a bit of a particular choice of words - but yes, it's not very effective. And no, it's not entirely clear to me what you're trying to accomplish. It appears to be an attempt to use GPIO6 as an input for a push button, but you refer to it as an output.
If you're trying to use GPIO6 as an input, consider this:
Wire a button between GPIO6 and GND. Nothing else.
Configure GPIO6 to have its internal pullup resistor enabled.
If desired, connect either of the options I suggested to GPIO6 allowing you to monitor the input with the LED.
However, the LED monitor is really pretty much superfluous since in practice reading a button input from a GPIO as described above is totally reliable.
I'm wanting to use GPIO as an input and an output. Within code I'll toggle the pin direction as output or input as well as toggling the output lo/hi state.
So the code would do something like this:
start:
Set Pin Direction to output
Output Hi
(delay 1 sec)
Output Lo
(delay 1 sec)
Set Pin Direction to input
(delay 2 secs)
jump to start:
[Edit: I think I was misunderstanding the requirement when I posted this. I made another post below this one after thinking about the requirements]
Which pins of a ROM chip can be, at different times, input and output? The data out pins will be either active outputs when the chip is selected, or high impendance when it's not selected.
If it was a RAM chip, obviously the data bus pins would be inputs, outputs, or high impedance.
If the pins you want to put LEDs on are being driven by either the GPIO pin or by the thing using the simulated ROM, then can't you just put a series resistor + LED to ground on the pin? Perhaps I misunderstood and you want one LED to illuminate if the GPIO pin is an output, and a different LED to illuminate if the thing connected to the GPIO pin is an output?
I did a project recently using a Nano to simulate ROM and RAM for a Z80 which is on the forum here, but it doesn't use LEDs. The only pins that I needed to swap from input to output were the databus pins (Z80 D7..D0)
Yeah pretty much. It's actually the Pi Pico I'm using but Arduino.. all the same thing really. I'm emulating a ROM, so yes, I'm not really wanting to do input into the ROM on data bus pins. I want to output data on the data bus (pin direction is output) and then set the data bus pins to a high impedance state when the ROM is not selected (pin direction set to input).
One LED is supposed to show simulated data that another device could be asserting on the data bus (eg. CPU or RAM), the second LED was to display the output of the ROM.
I probably don't need to do all of this to be honest. What I was hoping to achieve was a circuit that would illustrate that the "ROM" had indeed set the pin direction to a high impedance state.
The more I've been thinking about it.. I'm wondering if it would be just as easy to pop the multimeter over the GPIO pins, toggle the direction and see if the impedance varies. I don't know if that will work or not.. just been so pushed for time this week to try anything out
Why would you doubt this? If you doubt this, why wouldn't you doubt each and every other instruction the processor executes?
If it's for illustrative/educational purposes, you could just toggle a second GPIO with a LED attached the moment the 'ROM' GPIO goes from high-Z to OUTPUT and vice versa.
If it's for troubleshooting/debugging - well, that's what a debugger is for! I'm not very well at home in the Raspberry ecosystem, but I assume there's a debugger for it, like there is for most controllers.
What is using the simulated ROM? I imagine maybe you have a microprocessor board that normally has a ROM fitted, but you removed the real ROM and are simulating it.
If other things may be driving the databus pins when the ROM's CS isn't active, then it's obviously important for your code that switches the GPIO pin to high impedance to not have a bug that would cause the GPIO pin to be an output when something else is trying to drive the data bus, as you'd have two outputs shorted together.
When I was simulating all the hardware for a Z80, using a Nano, I was concerned about bugs in the logic for when the Nano should drive the data bus vs when the Z80 was driving the databus. I put a 1k ohm reistor between each Z80 databus pin and the corresponding Nano GPIO pin, so that if I wasn't decoding the Z80's control outputs correctly, I wouldn't do any harm.
You got it. I have a 6502 system that I've been fiddling with for the past 2 years on and off. I got sick of removing the ROM, programming it, replacing it etc so I knocked up a level shifter board with a Pi Pico that plugs into the ROM socket.
To answer @rsmls the reason I was doubting what was going on is because I'm using the Pico's PIO assembly code and unlike Arduino sketches I find the whole 'API' rather complex. At the moment I have the "ROM" always asserting the data bus so I was hoping I could knock up a simple program and test circuit to convince myself that I was setting the high impedance state appropriately.
Aha! I just found a logic probe I bought ages ago. That is showing me a definite hi, lo or floating state with the Arduino. I should be able to use this to test the Pico.