Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JaimeLeon2 opened this issue Apr 21, 2024 · 7 comments
Open

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

JaimeLeon2 opened this issue Apr 21, 2024 · 7 comments
Assignees

Comments

@JaimeLeon2
Copy link

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

  • MobiFlight Version: 10.2.2
  • FlightSim: irrelevant
  • AddOn: irrekevant

Additional context
None.

@JaimeLeon2
Copy link
Author

Same as #1757

@neilenns neilenns self-assigned this Apr 21, 2024
@neilenns
Copy link
Contributor

neilenns commented Apr 21, 2024

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
Copy link
Contributor

elral commented Apr 22, 2024

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:

  • D13 as Input works only if the switch is connected to +5V (not GND, so reversed polarity)
  • D13 as output is limited in max. current by current the onboard LED requires.
    image

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
Copy link
Author

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

@JaimeLeon2
Copy link
Author

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

@elral
Copy link
Contributor

elral commented Apr 25, 2024

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants