From 87cec1c1c34bc3ad71c72c6920cdc0abd8b21335 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Mar 2026 15:45:11 -0500 Subject: [PATCH 1/2] Fix Serial pin reassignment on speed change and document wiring modes In setLowspeedMode() and setHighspeedMode(), calling Serial1.begin() without first calling setRX/setTX could revert to hardware-default pins, causing PIN1 to be used as TX even in LISTEN_ONLY mode (where TX should be routed to the unused PIN5). Fix: explicitly call setRX/setTX before each Serial.begin() call in both speed-change helpers, mirroring the setup() logic. Also update README to clarify that the circuit diagram covers LISTEN_ONLY wiring only, and that non-LISTEN_ONLY (emulation) mode additionally requires PIN1 connected to the LENS7 data line. Fixes #1 --- E-Mount.ino | 8 ++++++++ README.md | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/E-Mount.ino b/E-Mount.ino index 8e18f85..2a46945 100644 --- a/E-Mount.ino +++ b/E-Mount.ino @@ -137,7 +137,11 @@ void setLowspeedMode(){ if(highspeedMode == false) { return; } + // Re-apply pin assignments before begin() to avoid reverting to hardware defaults + Serial1.setRX(0); + Serial1.setTX(LISTEN_ONLY ? 5 : 1); Serial1.begin(750000, SERIAL_8N1); + Serial2.setRX(9); Serial2.begin(750000, SERIAL_8N1); highspeedMode = false; } @@ -146,7 +150,11 @@ void setHighspeedMode(){ if(highspeedMode) { return; } + // Re-apply pin assignments before begin() to avoid reverting to hardware defaults + Serial1.setRX(0); + Serial1.setTX(LISTEN_ONLY ? 5 : 1); Serial1.begin(1500000, SERIAL_8N1); + Serial2.setRX(9); Serial2.begin(1500000, SERIAL_8N1); highspeedMode = true; } diff --git a/README.md b/README.md index 710fb65..5589da7 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,12 @@ To interface with a camera you can construct a jig using a macro extension tube ![Circuit Diagram](/circuitdiagram.png) Appologies for the quality of the above diagram (it's easier than modeling the whole Teensy in Eagle) + +> **Note on pin assignments (see issue [#1](https://github.com/LexOptical/E-Mount/issues/1)):** The circuit diagram above reflects the **LISTEN_ONLY** wiring, where Teensy PIN0 (Serial1 RX) is connected to the LENS7 data line for passive sniffing. +> +> When operating in **non-LISTEN_ONLY mode** (emulating a lens), the firmware also uses **PIN1 (Serial1 TX)** to send data back to the camera body. In this mode, PIN1 must also be connected to the LENS7 data line. The firmware automatically selects the correct TX pin in `setup()` based on the `LISTEN_ONLY` flag in `Config.h`. +> +> | Mode | PIN0 (Serial1 RX) | PIN1 (Serial1 TX) | PIN9 (Serial2 RX) | +> |------|-------------------|-------------------|-------------------| +> | LISTEN_ONLY | LENS7 (lens->body) | unused (routed to PIN5) | Body->lens line | +> | Emulation | Body->lens line | LENS7 (lens->body) | Body->lens line | From 9aefd91ba41e01199b5e23e4c885233d52483b41 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Mar 2026 21:27:51 -0500 Subject: [PATCH 2/2] Extract serial pin numbers into named constants (address review comment) Add PIN_SERIAL1_RX (0), PIN_SERIAL1_TX_ACTIVE (1), PIN_SERIAL1_TX_LISTEN (5), and PIN_SERIAL2_RX (9) to Constants.h, replacing all raw literals in E-Mount.ino. The three existing control-signal constants (PIN_LENS_CS_BODY, PIN_BODY_CS_LENS, PIN_BODY_VD_LENS) were already named; serial pins now match that convention. Co-Authored-By: Claude Sonnet 4.6 --- Constants.h | 14 ++++++++++++++ E-Mount.ino | 18 +++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Constants.h b/Constants.h index 1f390ac..e7f332b 100644 --- a/Constants.h +++ b/Constants.h @@ -1,6 +1,20 @@ #ifndef Constants_h #define Constants_h +// --------------------------------------------------------------------------- +// Serial pin assignments +// --------------------------------------------------------------------------- +// Serial1 carries the lens<->body data line (LENS7). +// RX = PIN_SERIAL1_RX (always reads lens->body direction) +// TX = PIN_SERIAL1_TX_ACTIVE (non-LISTEN_ONLY: sends lens->body) +// TX = PIN_SERIAL1_TX_LISTEN (LISTEN_ONLY: routed to unused pin) +// +// Serial2 carries the body<->lens data line (BODY7). +// RX = PIN_SERIAL2_RX (reads body->lens direction) +const int PIN_SERIAL1_RX = 0; +const int PIN_SERIAL1_TX_ACTIVE = 1; +const int PIN_SERIAL1_TX_LISTEN = 5; // TX routed here when not transmitting +const int PIN_SERIAL2_RX = 9; const String LENS_TO_BODY = "Lens->Body "; const String BODY_TO_LENS = "Body->Lens "; diff --git a/E-Mount.ino b/E-Mount.ino index 2a46945..99815e6 100644 --- a/E-Mount.ino +++ b/E-Mount.ino @@ -44,11 +44,11 @@ void finishMessage() { void setup() { Serial.begin(115200); - Serial1.setRX(0); - Serial1.setTX(LISTEN_ONLY ? 5 : 1); + Serial1.setRX(PIN_SERIAL1_RX); + Serial1.setTX(LISTEN_ONLY ? PIN_SERIAL1_TX_LISTEN : PIN_SERIAL1_TX_ACTIVE); Serial1.begin(750000, SERIAL_8N1); - Serial2.setRX(9); + Serial2.setRX(PIN_SERIAL2_RX); Serial2.begin(750000, SERIAL_8N1); pinMode(PIN_BODY_VD_LENS, INPUT); @@ -138,10 +138,10 @@ void setLowspeedMode(){ return; } // Re-apply pin assignments before begin() to avoid reverting to hardware defaults - Serial1.setRX(0); - Serial1.setTX(LISTEN_ONLY ? 5 : 1); + Serial1.setRX(PIN_SERIAL1_RX); + Serial1.setTX(LISTEN_ONLY ? PIN_SERIAL1_TX_LISTEN : PIN_SERIAL1_TX_ACTIVE); Serial1.begin(750000, SERIAL_8N1); - Serial2.setRX(9); + Serial2.setRX(PIN_SERIAL2_RX); Serial2.begin(750000, SERIAL_8N1); highspeedMode = false; } @@ -151,10 +151,10 @@ void setHighspeedMode(){ return; } // Re-apply pin assignments before begin() to avoid reverting to hardware defaults - Serial1.setRX(0); - Serial1.setTX(LISTEN_ONLY ? 5 : 1); + Serial1.setRX(PIN_SERIAL1_RX); + Serial1.setTX(LISTEN_ONLY ? PIN_SERIAL1_TX_LISTEN : PIN_SERIAL1_TX_ACTIVE); Serial1.begin(1500000, SERIAL_8N1); - Serial2.setRX(9); + Serial2.setRX(PIN_SERIAL2_RX); Serial2.begin(1500000, SERIAL_8N1); highspeedMode = true; }