More mA from Arduino pins, configured on the fly

I have already made a DB-9 joystick tester used to test various retro computer joysticks, based on Arduino ( Bitbucket ). As there are many DB-9 pin configurations (see the source code) , 9 Arduino pins that I use for this are configured on the fly - sometimes they are analog or digital inputs, sometimes they are VCC or GND for joystick electronics. And it was all fine until I wanted to add support for more power hungry devices. Now, for some of them, the current that Arduino can give to power them isn't enough.

So, here is the problem: I have 9 pins connected to DB-9 connector, that must be configured on the fly, as the device is used, depending on the type of joystick that is tested. When a pin is configured as output, low or high, I need to be able to add additional current on those and only those pins. When a pin is configured as input, the additional current must be disconnected.

I have looked at various datasheets, and from what I found, something like a tri-state buffer that can provide around 100mA with individually controlled high impedance on output pins would be the solution. But, all I have found so far are the ones that can do this only for all or half of their outputs, not individually. I have also found 4066, but it seems to me that the current it can give is even smaller that that of Arduino.

Similar problem was discussed in https://forum.arduino.cc/index.php?topic=92701.0 , but without solution that could be useful to me.

I hope I'm not trying to solve XY, but looking for a solution to the problem. It is not crucial to be solved, some devices simply would not be supported and that's it, but it would be nice...

I don’t really understand what you want to do but in particular I don’t understand the Idea of only wanting ‘additional current’ on some pins in some configurations. I suspect, but can’t be sure, that you are confused about how current works. The connected load takes the current it needs, the pin just needs to be able to supply the current. If some device will take 100mA (or whatever the maximum is) then build circuits able to supply 100mA on every pin.

Ok, I'm still not sure if I have understood properly but having had a shower and thought some more about your question.

Allocate 3 Arduino pins to each DB9 pin you are interested in. Of the 3 pins one will always be an input and 2 will always be an output. Connect each DB9 pin to its own input. Connect each output via a tri state buffer to a DB9 pin. Connect the other output pin to control the Tri state buffer. You can now make any DB9 pin an input by turning off its associated buffer or an output by turning on the buffer.

It's a long time since I used Tri state buffers, I am not sure if they exist where you can control each buffer individually.

And if I have misunderstood what you are really asking then sorry!

The idea of using the half bridges in a L293 motor driver chip, mentioned in the quoted link, could work if it presents a sufficiently high impedance in the disabled state so as not to disturb the function of the Arduino pin when it is used as an input.

  1. You would need 9 additional free pins to enable each half bridge if the Arduino pin is to be defined as a output. Use a port multiplier if necessary.
  2. You’d have to be very careful in the code that, in the case the pin is an output pin, that it does not conflict with the half bridge. Your “on the fly” pin function change code and any setup code would have to respect that.

Edit
Crossed with @PerryBebbington

sometimes they are analog or digital inputs, sometimes they are VCC or GND for joystick electronics. And it was all fine until I wanted to add support for more power hungry devices. Now, for some of them, the current that Arduino can give to power them isn't enough.

I don't believe any joystick would need to draw a significant current through any other pins than Vcc and ground. You would not connect those to Arduino pins. You would connect them to an appropriate power source and ground (common with Arduino ground). So I don't get your problem.

Hi,
Is this project associated with this?

Tom.. :slight_smile:

@PerryBebbington, @6v6gt
Yes, that is something that I maybe can use... The problem is that I have no pins left on Arduino, but I'll try to make for one pin just for testing. I already have an OLED, optical encoder, analog multiplexer and DB9 connector connected to it, here it is in action:

@PaulRB
Then you haven't seen a lot of them. My collection of retro peripherals (joystick, mice, etc) has over 300 pieces. For example, some PC Gameport joysticks, MSX mice and trackball, Commodore 1351, just to name a few, need more current to work than what Arduino can give. The thing is that I'm making an universal retro joystick/mice tester, so I cannot just connect some pins to VCC and GND, as I have 24 different pin layouts that are supported, all different, and what pins are VCC and GND for them is all different, see here for example:

    DB-9 Joystick pinouts
    ---------------------

    5 4 3 2 1                                   Pot  - Analog input, potentiometer
   -----------      Joystick connector view     Sel  - Select line for additional read
   \O O O O O/                                  NC   - Not connected/used
    \O O O O/                                   Fire - Fire, Button
     -------                                    UDLR - Directions
     9 8 7 6

    Type/Pin    1       2       3       4       5       6       7       8       9

    2600 Joy    Up      Down    Left    Right   NC      Fire    NC      GND     NC
    7800 Joy    Up      Down    Left    Right   FireR   Fire    VCC     GND     FireL
    Atari8bit   Up      Down    Left    Right   NC      Fire    VCC     GND     NC
    C64  Joy    Up      Down    Left    Right   NC      Fire    VCC     GND     NC/Fire2
    Amiga Joy   Up      Down    Left    Right   Fire3   Fire1   VCC     GND     Fire2
    At ST Joy   Up      Down    Left    Right   NC      Fire1   VCC     GND     Fire2

    C64  Paddle NC      NC      FireX   FireY   PotY    NC      VCC     GND     PotX
    2600 Paddle NC      NC      FireA   FireB   PotB    NC      VCC     GND     PotA
    Amiga Padd  Fire3   NC      Fire1   Fire2   PotX    NC      VCC     GND     PotY

    CPC         Up      Down    Left    Right   Fire3   Fire1   Fire2   Se1/GND Se2/VCC
    CPC         Up      Down    Left    Right   Fire3   Fire1   Fire2   Se1/VCC Se2/GND

    MSX         Up      Down    Left    Right   VCC     Fire1   Fire2   GND/NC  GND

    Sega Master Up      Down    Left    Right   VCC     Fire1   NC      GND     Fire2

    ZX+2+3      NC      GND     NC      Right   Up      Fire    Left    GND     Down

    Vectrex     Fire1   Fire2   Fire3   Fire4   PotX    PotY    VCC     GND     -VCC

    Videopac    GND     Up      Right   Down    Left    Fire    NC      NC      NC

    Amiga Mse   V-Puls  H-Puls  VQ-Puls HQ-Puls FireM   FireL   VCC     GND     FireR
    At ST Mse   XB      XA      YA      YB      NC      FireL   VCC     GND     FireR

    Apple IIc   Fire1   VCC     GND     NC      Pad0    NC      Fire0   Pad1    NC

    Sega Gen3B  Up      Down    GND     GND     VCC     FireA   Sel/GND GND     Start
    Sega Gen3B  Up      Down    Left    Right   VCC     FireB   Sel/VCC GND     FireC

    TI-99/4A    NC      Se2/VCC Up      Fire    Left    NC      Se1/GND Down    Right
    TI-99/4A    NC      Se2/GND Up      Fire    Left    NC      Se1/VCC Down    Right

    ColecoV     Up      Down    Left    Right   Se1/VCC FireL   QuadA   Se2/GND QuadB
    ColecoV     Key1    Key2    Key3    Key4    Se1/GND FireR   NC      Se2/VCC NC

@TomGeorge
Yes, that is the same project, that was so stupid mistake to make and I was too tired to notice it for a while :slight_smile:

P.S. I just noticed that forum glued parenthesis to my first link, this is the correct one:
https://bitbucket.org/zzarko/joysticktester/src/master/JoystickTester/

EDIT: Thanks TomGeorge, and sorry for not following the rules right away...

Hi,
Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What mode Arduino are you using?

Thanks.. Tom.. :slight_smile:

For this project I'm using Arduino Nano, as it was just enough up until I wanted to include more exotic/power hungry devices... (I have around 200 bytes left and code occupies more that 80% of FLASH). I'll see what to do, maybe something should be left for next version. I have certainly learned a lot in the past two months while tinkering with this one.

The code runs mostly from 400Hz interrupt now (main loop just calls u8g2 for screen drawing and decides what to do with optical encoder inputs), ADC is triggered directly without analogRead (I have also shortened its sampling period), all digital inputs are also read directly form ports, port configurations (input/output) can change on every interrupt, depending on the joystick that is tested (mostly used for various select lines), I made my own menu and graphics drawing using u8g2 (for speed I update only the changed parts), implemented a help system and Snake game, settings are stored in EEPROM, etc. My biggest Arduino project so far...

With relays you can switch whatever you like into joystick pins.

With relays, I guess I would need two of them per joystick line, one to select Arduino or VCC/GND, and another one to select VCC or GND. That could in fact work perfectly and solve all electrical isues... I'll see if there are some small relay modules. But on the other hand, that means 18 relays and much more control lines in my project, probably another IC/Arduino just to controll all that... But, a clean solution to the problem, I agree. Also, I'm trying not to deviate too much from previous form factor and running on battery.

Use a tpic6b595 to provide a high-current ground connection to any of 8 connector pins. Use mic5891 to provide Vcc to any of 8 pins. If you can't get mic5891, or it drops too much voltage, maybe use 74hc595 and either TBD62083 or TBD62387.

Your connections grid is very useful. Use that to figure out 1 pin that is never ground, and 1 pin that is never Vcc, that looks possible. Also work out how many pins ever need to be analog. Hopefully there are no more than 6 of those. Nano has 6 analog pins which can also be digital inputs. It has 2 more analog pins which cannot be digital inputs, so use them for any pins which are only either analog or NC. Hopefully you will no longer need the analog multiplexers, which will simplify your circuit and free up Nano pins.

The tpic6b595/mic5892/74hc595 can share the same pins, and 2 of those can maybe be shared with your display, if that has spi interface. If your display has i2c interface, maybe swap with a version with spi so that those pins can be shared. SPI is faster than i2c, so will speed up your code and free up 2 more analog/digital pins.

An MCP23017 board provides 16 GPIO that can source 25mA each and is controlled by the I2C bus that you already use for the OLED display.

You could have up to 4 outputs at 100mA if you use respectively 4 outputs in parallel the double with a second module.

The other advantage is that, if something gets wrong, the damage will be limited to the MCP23017 board that sells below 2$

Of course the ports can be set to input as well

Huh, the connections I gave were just a part of it, not the whole package, sorry for not clearly mentioning that. My current situation is that I have 24 different configurations of pinouts, that also include DB-15 connector used for PC Gameport and BBC B joysticks. Before involving DB15, I spent a lot of time looking at all connections to fit them so that in every combination analog input could go to analog pin. I haven't released new version of the project for now, I'm still not satisfied how the code looks, but it will be GPL'ed eventually.

Adding PC Gameport was easy, as many pins aren't meant to be read. But, I wanted to add BBC B too (because it uses the same connector), and BBC B joystick reading is the main culprit for involving analog multiplexer because I ran out of analog inputs, and BBC pinout is mostly pin-incompatible with PC Gameport. So I had to connect BBC B analog pins to multiplexer, and that multiplexer in turn outputs its signal to only one of two analog input that I had left, and I had to use 2 digital pins to control the multiplexer. And now I have this, with only 1 unused pin, A7:


Yeah, I know it's a mess...

This is the interface:

Thank you PaulRB and RIN67630 for the suggestions about tpic6b595 and MCP23017, they sound promising, I didn't even know that circuits like that exist. I'll look at those!

I have ordered some parts, and I’ll try them as soon as they arrive (at the moment, the most promising to me is MCP23017, as it doesn’t need additional control lines besides I2C that I already use). I want to thank you all for your suggestions, I’ll wrote those down as they can be useful in next project and I’ll try to think differently from the start as I have learned a lot from this.

And it was all fine until I wanted to add support for more power hungry devices. Now, for some of them, the current that Arduino can give to power them isn't enough.

Should probably identify the max current needed at each pin.

However, I'm suspecting the power (current) problem is the 9V battery itself because most are very limited to the max current draw they can supply. Also, the 7805 regulator without heat-sink can barely provide 100mA before going into thermal shutdown mode.

Temporarily do some tests with a 5V regulated supply (1A+) to see if there's a difference.

You may try this. There will be some voltage drop (~ 0.5 V) on either rail but it is simple and needs no extra pin.

Mosfet gate driver ICs can supply a lot of current. You can drive them from Arduino but output voltage can be higher. Most of them have small package so they cannot handle much power, but they are good for on or off type drive.