Jump to content

Maximising the use of Arduino nanos - max switch connections possible?


Recommended Posts

Posted

I've been meaning to ask this for a while now, originally as part of my attempts to get round the fact that I couldn't resolve the issues that plagued my RS485 setup. It looked like I would have to use Bodnar boards for switches and encoders as much as possible and connect via USB all the arduinos etc necessary to run the gauges / LED's etc.

Thankfully the RS485 issues were resolved (it was down to a corrupted Arduino IDE installation) so I'm back on track. However I do want to rationalise as much as possible, as clearly the lower the number of devices the simpler the pyhsical setup will be, obviously at the expense of the programming.

So, assuming that I have an Arduino Nano allocated to a particular gauge stepper motor, that leaves a number of unsused pins that could be used for switches, LED's, encoders or potentiometers.

Leaving aside the outputs for LED's, as there aren't that many as they require a voltage output / pin to ground, how many of the remaining pins can be realistically used for switch, encoder or Pot inputs for DCS BIOS? As I see it I have the following pins that can be used, two of which will be given over to stepper STEP and DIR outputs to the stepper driver

A0, A1, A2, A3, A4, A5, A6, A7

D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13

I built a Ferrari 312T4 'dash' to go with my racing Sim a while back (photos below) that used an Arduino to drive some gauges and a stepper motor, and while the schematics stated I could use any of the D pins for the PWM output / input of the devices, I found that it was not the case. The only PWM capable pins are 3, 5, 6, 9, 10 & 11. Using other pins can cause problems, and I also found that pin 3 could not be made to work no matter what, showing it was not as simple as it first looked.

So assuming switches, encoders and Pots all have GND connections, what pins can I reliably use for them? Is there a limit in terms of which pins encoders and Pots can be connected to? And is there a limit to the number of switches that can be connected before it causes issues?

Cheers

 

Les

20210303_070724.jpg

20210303_070734.jpg

20210303_070808.jpg

Posted

At the risk of complicating this question, I  realise that I inadvertently left out one important part of this. 

Is it better (less laggy, less demand on the system, less complicated etc) to have inputs via RS485 where possible rather than use Bodnar boards? They use USB, and I just assumed that the less reliance on USB the better, although the Bodnar boards rate very highly in my experience. I know that when I tried to drive all the Nanos via USB it was terrible and slow, does increasing the reliance on RS485 do the same?

Cheers 

Les

Posted (edited)

With those 20 pins you could create a 10x10 matrix (or something smaller) to give you 100 buttons (the A0-A7 can be used as digital pins). You would only need 100 cheep signal diodes (such as 1N4148) here is an example of the idea with code https://www.baldengineer.com/arduino-keyboard-matrix-tutorial.html)

If you are a little bit creative you can get this to work with 3-way toggle switches too - the center/common pin is in the row with each output pin in a different column

I've used this technique to get 128 buttons using a pro-micro and this library https://github.com/MHeironimus/ArduinoJoystickLibrary doing a read of the matrix every 50ms acts as simple debouncing (don't use delay() see https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay)

 

Edited by bojack
  • Thanks 1
Posted (edited)

Hi Les,

you are right, the Nano's PWM capabilities are limited to digital pins 3, 5, 6, 9, 10 and 11.

As far as I remember, pins A6 and A7 can only be used as analogue (and digital) inputs, but they are still good for connecting switches to GND.

If you are using the RS485 bus, you are loosing pins D0 to D2, if using the I2C bus you additionally loose pins A4 and A5.

Using D13 as an input sometimes can cause problems, as the onboard LED is wired to it.

I can't confirm your trouble with pin D3. Had never problems with it.

To get more inputs / outputs, 8 or 16 bit port expanders could be used.

Here is a good reference to the Nano pinout -> LINK <-

 

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted (edited)
21 hours ago, No1sonuk said:

Maybe check out The Warthog Project.
I think most, if not all of his inputs go via Bodnar boards.
https://thewarthogproject.com/

I like Bodnar boards because they seem to be light on resources and are uber reliable. My problem is that I have four BBI-64 boards already to run the switches and encoders I have. There is a way of making a matrix for the switches that increases the number one board can handle, but not sure that allows use with encoders. Last time I checked (admittedly a while back) Bodnar didn't sell a matrix board but if they did I would be tempted.  The invariable downside is the plates of spaghetti trying to get everything connected to it!

As for Vinc's suggestion of expanders, I'll have to check it out as I'm unfamiliar with them.

As ever, I'm so impressed by the great info and feedback I get when asking my daft questions; always worth asking here!

Cheers 

Les

Edited by lesthegrngo
Spelling
Posted

Guys, just revisiting this for some PCB tidying up 

Can you confirm on a Nano what pins can be used reliably for the LED outputs from DCS bios? I think it is D3 through D12 and pins A0 to A5, correct?

Cheers

 

Les

Posted

Hi Les,

for LED output also D13 should work.

If not connected via RS485, D0 to D2 may work as output too.

-> Pinout <-

Regards, Vinc

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted (edited)

Not a good idea to use D0 and D1 if you plan to program the board with the circuit connected or use USB.

The USB interface is connected to D0 and D1, so you can't use them with serial comms such as DCS-BIOS active.

Edited by No1sonuk
Posted (edited)

This tidy up that I am doing is throwing into sharp relief a load of issues that are of my own making - talk about going down a rabbit hole....

One of the things I was doing was trying to assign as many minor functions to Nanos that are used for the 'bigger' devices.  A good example of this is where I have a Nano driving all three CMSC LCD displays, via I2C driven PCF8574 boards that have assignable addresses. I was very pleased with myself at the time at getting this to work nicely. However the I2C connection takes up only 2 pins, leaving 14 pins for switch, encoder and LED connections. I want to use those to offload other devices, the CSMC does not update that frequently so putting the extra switches and LED's on it won't make any difference to the functioning 

Except that when I went to the hardware, the I2C connection is set to pins A4 and A5, and I can't for the life of me work out a) why those pins and b) where did I set them in the sketch? I supect that the answer is that they are preset somewhere else, but because of my processes at the time, I have no documentation to back up what I did, so I am having to relearn all of this to understand what I have already done.

If someone can point out why pins A4 & A5 are seleted and where that is set I would appreciate it, but also can you advise whether I should be leaving A6 and A7 unused?

Cheers

 

Les

Edited by lesthegrngo
Posted (edited)

Hi Les,

as you already assumed, pins A4 and A5 are preset as I2C bus pins for the Nano and the Uno. Have a look at the pinout in my last posting. They are "hard wired" to the Data channel (A4) and Clock frequency (A5) and can't be changed for that boards.

That is in analogy to No1sonuk' s statement regarding the communication pins D0 and D1.

You may change the pinout or add I2C interfaces by software, have a look at the SoftWire library. But that should slow down the processing speed of the sketch.

 

Have a further look at pins A6 and A7, they exclusively are connected to the Analogue Digital Converter and therefore can be used as physical inputs only (not as outputs). 

Maybe that's a reason why they are missing for the Uno layout.

 

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

Cool, thanks - I knew there must have been a reason, serves me right for not documenting all this stuff at the time. Part of my rationalisation of all this is that I will be making better notes of what I am doing, the amount of time I have wasted covering ground I had already covered before is astounding.

Pinout diagrams, logic charts to show how stuff is all connected together, properly annotated PCB diagrams.... Lots of work to do

Cheers

Les

Posted

I'm happy to limit to a reasonable number of inputs per Nano, simply based on the fact that I'd need around 40 total for all the inputs plus the Bodnar boards

Cheers 

Les

Posted

Hi agian, I'm going to connect the Mega as a slave as I had previously indicated, just want to verify that I have the pin selection correct

I intend to connect the Max487 chip RE pin to the Mega pin 19 (RX) and the DE pin to TX (pin 18, is that correct? There are other RX / TX pins on the Mega and these are selected as that's how I set up the master (pints reversed)

Cheers

 

Les  

Posted (edited)

Hi Les,

Connect the Mega's D0 (RX0) to RO of the RS485 board or Max487 chip, D1 (TX0) to DI and pin D2 to DE and RE. Than TXENABLE_PIN 2 within the slave sketch and that's it for a Mega.

Regards, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...