From a51be9a5d30de3aed9c0d216bfeb42f26a4291e7 Mon Sep 17 00:00:00 2001 From: Francois Rainville Date: Tue, 20 Feb 2024 13:11:16 -0500 Subject: [PATCH 1/2] initialize pin.mode when using digital output --- pyfirmata2/pyfirmata2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyfirmata2/pyfirmata2.py b/pyfirmata2/pyfirmata2.py index 67c5d93..fad9ee4 100755 --- a/pyfirmata2/pyfirmata2.py +++ b/pyfirmata2/pyfirmata2.py @@ -287,6 +287,8 @@ def get_pin(self, pin_def): pin.mode = INPUT_PULLUP elif bits[2] != 'o': pin.mode = INPUT + elif bits[2] == 'o': + pin.mode = OUTPUT else: pin.enable_reporting() return pin From 48f97e27bf7050313998c77cad06107a3220aac0 Mon Sep 17 00:00:00 2001 From: Bernd Porr Date: Fri, 23 Feb 2024 16:21:25 +0000 Subject: [PATCH 2/2] Improved code to have a proper fallback to input pin mode. --- pyfirmata2/pyfirmata2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyfirmata2/pyfirmata2.py b/pyfirmata2/pyfirmata2.py index e120a30..d9de871 100755 --- a/pyfirmata2/pyfirmata2.py +++ b/pyfirmata2/pyfirmata2.py @@ -285,10 +285,12 @@ def get_pin(self, pin_def): pin.mode = SERVO elif bits[2] == 'u': pin.mode = INPUT_PULLUP - elif bits[2] != 'o': + elif bits[2] == 'i': pin.mode = INPUT elif bits[2] == 'o': pin.mode = OUTPUT + else: + pin.mode = INPUT else: pin.enable_reporting() return pin