MobiFlight / MobiFlight-Connector

MobiFlight is an open source project that allows you to create your own home cockpit for your favorite flight simulator in a flexible, affordable and extremely user-friendly way.
https://mobiflight.com
MIT License
229 stars 100 forks source link

Mobiflight allows pins A6 and A7 for digital use on Nano boards #1766

Open JaimeLeon2 opened 2 months ago

JaimeLeon2 commented 2 months ago

Describe the bug Current UI allows assignment of pins A6 and A7 for digital input and output. These pins can only be used for analog input. Reported by user in Discord.

Steps To Reproduce Steps to reproduce the behavior:

  1. Connect a Nano board with MF firmware
  2. Assign button to pin A6 or A7
  3. Assign led to pin A6 or A7
  4. Note this was allowed by the UI but will never work in those pins.

Expected behavior Assignment to digital input or output should not be allowed.

Actual behavior Assignment is allowed.

Details

Additional context None.

JaimeLeon2 commented 2 months ago

Same as #1757

neilenns commented 2 months ago

We should also prevent D13 from being used as an output on Mega boards.

The way to do this is:

  1. Add new properties to the board.json file for the pins, probably analogOnly and outputOnly. By default these should be false so existing files don't need to change, and it doesn't have to be specified on every single pin.
  2. Add those flags to the pins and boards that need it.
  3. For the various module types, when it calls for the list of pins, have it then filter the returned list of pins to exclude pins that don't apply.

Note that this could cause issues with existing configurations that might use these pins in an incorrect way. The code would somehow need to also make sure that the pin shows in the dropdown if it's the current pin, even if it isn't valid per the new rules.

elral commented 2 months ago

The original Arduino MEGA 2560 has an OpAmp connected to Pin D13, means this Pin can be used as Input and Output without any restrictions schematic

image

Clones don't have this OpAmp, so there are some restrictions:

I would not restrict the use of Pin 13 as it's usable on original ones, but clearly state that the above mentioned restrictions apply for clones.

The information that pins A6 and A7 are only useable for analogIn and not digital for the Nanos are also widely spread in the internet. I would do the same as for the Mega, clearly state this restriction.

Now the question is where to do it. At least on the mobiflight homepage where the compatible boards are listed. Addiotiuonal a pinned thread under Hardware on the Discord server.

Maybe we could add an information in the board.json file which gets displayed in the Configured Modules window. This would be shown everytime the board is selected as an additional information.

image

JaimeLeon2 commented 2 months ago

Also Pro Micro does not have a LED on D13, so not applicable to this board.

JaimeLeon2 commented 2 months ago

Wouldn't installing an external pull up resistor on D13 solve the low voltage that causes the bad input readings on this pin?

elral commented 2 months ago

You have to be above > 0.6 Vcc to get a stable H signal and < 0.3 Vcc to get stable L signal.

So for H signal 0.6*5V = 3V is required, Rled is 1K and let's assume LED is ideal (voltage drop 1.5V, no resistor). This means 3.5V must be split up for the 1k resistor and the pullup resistor while the voltage drop for the 1k resistor must be 1.5V to get the stable H signal. That would also be roughly a 1k resistor. Getting the L signal is no problem as you switch directly to GND.

So yes, it should be possible. But my calculation has to be tested before ;)

The build in pullup resistor from the board is 10k. So 3.5V has to be split up 1:10, means voltage drop on Rled is 0.35V. This added to 1.5V from the LED results in 1.85V as input voltage for the ATmega pin which is in the undefined area for input voltage, but "near" 0.3*Vcc=1.5V for L signal. That's why it does not work.

DocMoebiuz commented 2 months ago

Also Pro Micro does not have a LED on D13, so not applicable to this board.

we have individual board json files. So any restriction on the pin would be specific to a single board