Skip to content

Fix RS485Utils examples and platformio projects for ESP32 - #4

Merged
aphelps-claude-bot merged 4 commits into
mainfrom
get-rs485utils-example-code-working-on-an-esp32
Jul 27, 2026
Merged

aphelps-claude-bot merged 4 commits into
mainfrom
get-rs485utils-example-code-working-on-an-esp32

Conversation

@aphelps-claude-bot

@aphelps-claude-bot aphelps-claude-bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Sketch fixes (RS485Utils/examples/):

  • Guard `#include <SoftwareSerial.h>` with `#ifdef AVR` in SocketTestMaster and SocketTestSlave (SoftwareSerial is AVR-only)
  • Replace `#if 1` / `#else` hardcoded pin blocks with `#ifndef` guards so `-DPIN_RS485_RECV` etc. from build flags take precedence without redefinition warnings
  • Track `RS485SocketTool/RS485SocketTool.ino` (was untracked)

PlatformIO projects (platformio/):

  • `RS485SocketTool`: fix broken `src_dir = .`, add `[env:esp32]` (Serial2, GPIO 16/17/18) and `[env:nano]`, add `monitor_speed = 115200`
  • `SocketTestMaster` / `SocketTestSlave`: add `[env:esp32]`, update `src_dir` to point directly at examples, add `monitor_speed = 115200`

All 6 environments (3 sketches × esp32 + nano) build with zero warnings.

Test plan

  • `pio run` in RS485SocketTool, SocketTestMaster, SocketTestSlave — all SUCCESS (esp32 + nano)

🤖 Generated with Claude Code

aphelps and others added 2 commits July 21, 2026 00:08
- Guard #include <SoftwareSerial.h> with #ifdef __AVR__ in both
  SocketTestMaster and SocketTestSlave (SoftwareSerial is AVR-only)
- Replace #if 1 / #else hardcoded pin blocks with #ifndef guards so
  -DPIN_RS485_RECV etc. passed via build flags take precedence cleanly
  without redefinition warnings

With -DRS485_HARDWARE_SERIAL=2 both sketches now build cleanly for ESP32.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- RS485SocketTool/platformio.ini: fix broken src_dir (was "."), add
  [env:esp32] with Serial2/GPIO16-18, [env:nano], monitor_speed=115200
- SocketTestMaster/platformio.ini: add [env:esp32], update src_dir to
  point at examples (src symlink already pointed there), monitor_speed
- SocketTestSlave/platformio.ini: same
- Track RS485Utils/examples/RS485SocketTool/RS485SocketTool.ino (was
  previously untracked; required by the fixed RS485SocketTool src_dir)

All 6 environments (3 sketches × esp32 + nano) build clean.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@aphelps-claude-bot aphelps-claude-bot changed the title Fix SocketTest examples for ESP32 compatibility Fix RS485Utils examples and platformio projects for ESP32 Jul 21, 2026
- Timer comparison was inverted: `now - SEND_PERIOD >= last_send_ms` wraps
  on uint32 and sends every 10ms instead of every 1s; fix to `now - last_send_ms >= SEND_PERIOD`
- Socket address was `(DEBUG_LEVEL != 0)` (= 1) instead of ADDRESS (128),
  so targeted replies to addr 128 would be dropped

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up self-review after fixing two bugs found in the previous review pass.

Previous findings addressed:

  • ✅ Timer comparison corrected to now - last_send_ms >= SEND_PERIOD (was uint32 underflow, sent every 10ms)
  • ✅ Socket address corrected to ADDRESS (was (DEBUG_LEVEL != 0) = 1, not 128)

Remaining known limitation: lib_dir is an absolute path in all three platformio.ini files — consistent with the rest of the ArduinoLibs ecosystem; install.sh handles symlinks on new machines.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of cc656c1 (trailing newline fix only).

  • ✅ All prior findings addressed (bugs fixed in f88b410, newline fixed here)
  • No new issues introduced

PR is clean and ready to merge.

@aphelps-claude-bot
aphelps-claude-bot merged commit b2a8a93 into main Jul 27, 2026
@aphelps-claude-bot
aphelps-claude-bot deleted the get-rs485utils-example-code-working-on-an-esp32 branch July 27, 2026 01:17
aphelps-claude-bot added a commit that referenced this pull request Aug 20, 2026
* add RS485SocketTool ESP32 hardware testing guide

Self-serve TESTING.md for bringing up the RS485SocketTool example on an
ESP32: parts list, ESP32<->transceiver<->bus wiring (pins/flags matching the
esp32 platformio env), build/flash steps, single-node smoke test and two-node
send/receive test with the exact serial strings the sketch emits, plus a
troubleshooting table. Carries the deferred hardware Testing Required from
the RS485-on-ESP32 example work (ArduinoLibs #4).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix RS485 guide: received payload hex is hidden at DEBUG_LEVEL=1

Self-review finding: the guide showed '* Received data 2: 54 01', but
print_hex_buffer emits the bytes via DEBUG4_HEXVAL, which compiles out below
DEBUG_LEVEL=4; both envs build at level 1, so the real line is
'* Received data 2:' with no hex. Correct the expected output (a tester would
otherwise think reception failed), note how to see the hex (-DDEBUG_LEVEL=4)
and the count-lag, and spell out the nano env's default AVR pins (7/4/2).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* rs485 guide: drop the fabricated debug-level-4 hex example

Re-review nit: the illustrative '* Received data 2:  54  02' didn't match
Arduino HEX formatting (no zero-pad, per-byte leading space). Describe the
DEBUG_LEVEL=4 payload as space-separated hex ('T'=54 then the counter) and
note the no-zero-pad quirk, rather than showing a wrong literal.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: aphelps-claude-bot <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants