Skip to content

don't write INPUT pins in digitalWriteCallback #231

Closed
@soundanalogous

Description

@soundanalogous

This is a long standing issue where pins configured as INPUT are written to each time a digital message is received from a client. This didn't have a negative effect on any boards until the Zero (SAMD) came along. This indicates a potential issue with the SAMD firmware, but the bigger issue for Firmata is I should have migrated to INPUT_PULLUP long ago.

This is where the issue is: https://github.com/firmata/arduino/blob/master/examples/StandardFirmata/StandardFirmata.ino#L352

The best fix is to remove the check for INPUT and only allow OUTPUT here. That way INPUT pins are masked and never written to when writePort is called. However this creates another problem in that many Firmata client libraries are likely writing HIGH to an input pin to enable internal pull-ups. So that would break backwards compatibility.

Here's an initial proposal for a backwards compatible fix:

In digitalWriteCallback, still check for INPUT, but only look for changes. If set to HIGH, set the pin mode for that pin to INPUT_PULLUP, if set to LOW set the pin mode to INPUT. Do not set a mask bit for that pin so it's value is not set when writePort is called. I don't like that I have to add additional logic since I want this function to execute fast. I'll see what I can do to optimize. This would be ripped out in Firmata 3.0 and only OUTPUT pins would written to as of 3.0+

Add an INPUT_PULLUP mode. Client's can check if Firmata version is 2.5 or higher (ugh ConfigurableFirmata will be a mess here in terms of versioning) and if so set the pin mode to INPUT_PULLUP rather than writing 1 to the digital input pin to enable internal pull-ups.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions