Using I/O pins as adhoc Vcc or GND - bad idea or not ?

i have seen some threads that mention getting 5V (on a 5V board) from a pin by "writing it 'HIGH' " and was wondering if writing it 'LOW' would effectively turn it to a GND pin.

i have a small motor driver with a 5-pin male header, 4 logic pins (IN1-4) and GND and want to mount a ProMini directly onto those headers for compact-ness.

the problem is there's a component blocking the position of the ProMini and i cannot place it to reach D5-D2+GND.

would placing it at D9-D6 and then using D5 as "pseudo-GND" be a workaround ?

are there hazardous considerations with the internal circtuitry by doing this ?

Thanks for helping with Safety First ! :slight_smile:

Low indeed makes the pin GND. And it's okay to use that as a GND as long as you mind the current. Aka, if that motor driver only uses that as a reference for the logical inputs it's fine. But it can NOT supply the motor current.

No, this is not good practice - output drivers on the ATmega chip have about 40 ohms of resistance, very roughly,
too high an impedance for anything that takes current and wants a stable rail voltage, which expect a
solid voltage source. Most modules or circuits you might want to power this way have (and need) decoupling capacitors,
so switching them will involve current spikes well in excess of the output pin's 40mA aboslute maximum.

However if you are proposing commoning up several pins (and using direct port manipulation to switch
them simultaneously) you will be mitigating both problems...

Note that many motor driver chips can pull high currents from the logic supply if the motor supply is missing.

septillion:
Low indeed makes the pin GND. And it's okay to use that as a GND as long as you mind the current. Aka, if that motor driver only uses that as a reference for the logical inputs it's fine. But it can NOT supply the motor current.

the thinking was indeed to keep it for only the logical side.

this motor driver doesn't "mix" the supplies with the controller, like the L293/L298 motor shields where you can pipe out the 5V for the microcontroller via the motor shield connection.

it's a "L298 replacement" from eBay(China) which i've tracked down as the MX1515.
the datasheet is in chinese and an english version doesn't seem to be available.

FWIW: this is what the schematic looks like;

Datasheet itself is at;

MarkT:
No, this is not good practice - output drivers on the ATmega chip have about 40 ohms of resistance, very roughly,
too high an impedance for anything that takes current and wants a stable rail voltage, which expect a
solid voltage source. Most modules or circuits you might want to power this way have (and need) decoupling capacitors,
so switching them will involve current spikes well in excess of the output pin's 40mA aboslute maximum.

oh my, i understand the individual words in those sentences, but my grounding in fundamental electronics is weak and can't quite piece it all together.

i was thinking "high impedance" was in MegaOhms, but that was dealing with Arduino input pins.

so, i can't quite get reading 40 Ohm as "high impedance".

MarkT:
However if you are proposing commoning up several pins (and using direct port manipulation to switch
them simultaneously) you will be mitigating both problems...

okay - so it looks like it's time i started learning direct port manipulation.
i see that D4-D7 (and D3) are on the same port (D) - can i use Port D then ?
does this mean i will have to "sacrifice" using the other pins on Port D - D0-D2 inclusive ?
(or handle/cater to them also in the code for the direct port manipulation, i believe one uses bitmasking to leave "other bits as is")

this looks to be a good learning lesson opportunity.

I'd urge you not to use an I/O pin as a "pseudo ground." Cut off the GND pin on your module and solder a short wire in place of it that you can connect to a proper ground somewhere. Use the smallest-diameter wire you have -- it doesn't need to carry much current. Even one strand from a stranded-conductor wire will do if you can insulate it somehow (perhaps with a piece of tape). I use AWG-30 wire wrap wire.

This will maximize the protection of your motors (and what they're connected to) from electrical noise, power on/off and other hard-to-identify-and-fix problems later on.

All just my opinion of course :slight_smile:

i was thinking "high impedance" was in MegaOhms, but that was dealing with Arduino input pins.

so, i can't quite get reading 40 Ohm as "high impedance".

It’s all about context. Ground and VCC are power rails through which total system currents can flow. You’re substituting a connection to one of those rails (internal to the IC) with a mosfet output stage that inserts 40 ohms into the circuit you’re using for the ground connection. That’s a high impedance.

Try looking at it this way:

If you used a certain piece of wire to connect a five volt system to its power supply and you measured a one volt drop in that wire, would you consider that piece of wire to be high impedance?

That one volt drop occurs with just 25 millamps through 40 ohms.

CurtCarpenter:
I'd urge you not to use an I/O pin as a "pseudo ground."
...
just my opinion of course :slight_smile:

and much appreciated, thanks.

avr_fred:
It’s all about context. Ground and VCC are power rails through which total system currents can flow. You’re substituting a connection to one of those rails (internal to the IC) with a mosfet output stage that inserts 40 ohms into the circuit you’re using for the ground connection. That’s a high impedance.

ahh i see.

the pin may be (used as) a path to GND, but it's the components ALONG THAT PATH that make the difference.

okay - i'm convinced this "pseudo-ground" is NOT a good idea.

i'm thinking, by the same token - supplying 5V via a digitalWrite(pin,HIGH) is also NOT best practice.

Thanks, all !

am still wondering about

However if you are proposing commoning up several pins (and using direct port manipulation to switch them simultaneously) you will be mitigating both problems...

how does direct port manipulation address/mitigate the issue ?

BabyGeezer:
am still wondering about how does direct port manipulation address/ mitigate the issue ?

OK, when you use the Arduino IDE to control a "pin", remember that this pin is part of an 8-bit port where the actual command to change a bit involves reading the whole port byte, setting or clearing the corresponding bit, and writing it back to the port as a byte.

Even if as I recall happens in the ATmegas, much of this process occurs in hardware, it still requires several steps and in fact, there are several software steps involved in determining which bit is involved when its location is provided as a variable to the digitalWrite function.

If then you use digitalWrite to set or clear a number of pins, you do this using a "for" loop in which each bit is changed independently. In between say, the first and the last such iteration, you could easily have one or more pin set HIGH and one or more pins set LOW resulting in a short circuit where they are connected in tandem until all pins are set to the same final value.

Direct port manipulation means you set all bits in the register at the same time. You will want to read the preceding data from the register, set or clear all the bits you need to change, then write that whole byte back to the register. As long as you do that - and not digitalWrite - there will never be any incongruity between those pins tied together.

Paul__B:
...
In between say, the first and the last such iteration, you could easily have one or more pin set HIGH and one or more pins set LOW resulting in a short circuit where they are connected in tandem until all pins are set to the same final value.

ahh, i see.

i understood your whole post - Thanks !