Problems using analogue pins as digital inputs from flight simulator radio stack

Hi all, my first post here.

I’m using an Arduino Uno to simulate a multi-function radio stack that will eventually be used for X-Plane. The hardware consists of three 4-digit 7-segment I2C displays which I actually reference as 2 6-digit displays in software, two mechanical rotary encoders for coarse and fine adjustment of the various radio and autopilot values, a push button for flipping between active and standby radio frequencies or resetting autopilot values back to 0, and a 12 position rotary switch of which I use 7 positions for selecting various radios and autopilot modes like COM1, COM2, Autopilot heading, etc. (there are eight positions I recognise with the last being for the LED brightness when none of the other positions are lowering input lines into the Arduino - this is poor and I’m going to fix it by adding another line from the rotay switch to a spare input pin for the brightness mode).

Everything works perfectly if I use digital pins 8 to 13 and pin 7 for the rotary switch (I need 7 input lines). But I need to add an Ethernet shield to the Uno and I think that uses some of those pins so I need to use others but there aren’t enough digital pins left (the rotary encoders and push button take up 5 pins and since I use serial for debugging I can’t use the first two digital pins). So I tried using the analogue pins instead of digital pins 8 to 13 (I can still use digital pin 7), but I get problems.

Changing the code to use the analogue pins A0-A5 instead in digital pins 8-13 is easy and it’s in the attached program (please excuse the mess, it’s my first real try). I reference them as 14-19 rather than A0-A5 but I’ve tried both ways and they exhibit the same issues.

When the program is running the Arduino will hang whenever I select the switch positions attached to analogue pins A4 or A5. Swapping between all the other inputs is fine - I can turn the switch and swap between A0 and A1, or between A1 and A2, A2 and A3, or back and forward again, but every time A4 or A5 go low (every PIN is set INPUT_HIGH) then the Arduino hangs.

I’m trying to set a watchdog timer to store the stack value in EEPROM when it hangs which I can then read off when it resets, but it’s proving tricky. Some of that code is in the program and the reset works but the EEPROM bit doesn’t yet.

Does anyone know if there’s some well-known problem that I’m missing in using analogue pins instead of digital pins for this type of simple selection?

I’m considering ditching the Uno for this and getting a Mega with more digital pins, and keeping the Uno for my next project which is a Stewart platform which needs 6 analogue outputs :slight_smile: What do you think about using analogue pins as digital inputs in general - is that a bad idea, because if it is I’ll stop trying to debug this problem and just do the upgrade.

I’ll draw up a schematic if that helps anyone willing to help me debug this.

All the very best, and Merry Christmas.

Ken

XP_stack_3_analogue_ino.ino (18.6 KB)

Can you give me Which are Digital pins are used ??
How many Interface device you have??

Can you put in table with actual setup??

bit confusing

#define ASPD_PIN  7     // Autopilot speed mode pin
#define MODE_ASPD  7    // Autopilot speed

#define MODE_AALT  6    // Autopilot altitude

#define FLIP_PIN  6     // Flip/reset pin

can you share datasheet???

What do you think about using analogue pins as digital inputs in general - is that a bad idea,

No, it is a perfectly good idea but the clue might be in the fact that pins A4 and A5 are used by the Wire library as data and clock pins respectively so if you use the library, which you do, you cannot also use those pins as digital, or indeed, analogue inputs.

I never realised. Thanks for that. So I'm going to have to go to a Mega now anyway.

That was great advice :slight_smile:

Cheers,

Ken

You would be wise to use the Ax names in your program because that makes it portable between board types unlike the pin numbers which differ between board types.

Hi AMPS-N,

The situation for both is the same. ASPD_PIN is the input pin which will be set low when the rotary switch has selected Autopilot Speed mode. When the code is working out which pin is low it's looking into an array, and for this mode the lookup returns MODE_ASPD for use in the case statement on what to do next. It's just chance that they numbers for the pin and the mode are the same in these cases.

Cheers,

Ken

AMPS-N:
Can you give me Which are Digital pins are used ??
How many Interface device you have??

Can you put in table with actual setup??

bit confusing

#define ASPD_PIN  7     // Autopilot speed mode pin

#define MODE_ASPD  7    // Autopilot speed

#define MODE_AALT  6    // Autopilot altitude

#define FLIP_PIN  6    // Flip/reset pin




can you share datasheet???

I'll do that in future. Thanks,

Ken

UKHeliBob:
You would be wise to use the Ax names in your program because that makes it portable between board types unlike the pin numbers which differ between board types.