start-bridge.bat (Windows) and start-bridge.command (macOS/Linux, +x) sit next to bridge.py in both parts so readers can start the bridge with a double-click. READMEs now cover the launchers and the ledtest.py debug path.
2.2 KiB
Part 1 — Your First Arduino Round-Trip
Code for "Godot Isn't Just for Games: Your First Arduino Round-Trip".
A button in a Godot 4 scene reaches down a USB cable — through a Python-to-UDP bridge — and lights a real LED on an Arduino Uno.
Contents
arduino/
LedBasics/LedBasics.ino # reads L1/L0 off serial, drives the LED on D13
bridge/bridge.py # serial <-> UDP relay (run this, leave it running)
bridge/start-bridge.bat # Windows: double-click to start the bridge
bridge/start-bridge.command # macOS/Linux: double-click (or ./) to start the bridge
bridge/ledtest.py # standalone LED command test, no Godot (see Debugging)
godot/
ArduinoGodot/ # Godot 4 project: one styled toggle button
Wiring
D13 → 220 Ω resistor → LED long leg (anode); LED short leg (cathode) → GND. No breadboard? The Uno's onboard LED is already on D13.
Run it
- Flash
arduino/LedBasics/LedBasics.inoto the Uno (Arduino IDE, 115200 baud). - Bridge:
pip install pyserial, then start the relay and leave it running — either double-clickarduino/bridge/start-bridge.bat(Windows) /arduino/bridge/start-bridge.command(macOS), or runpython arduino/bridge/bridge.pyyourself. - Godot: open
godot/ArduinoGodot/in Godot 4, press Play, click the button.
The bridge auto-detects the board and reconnects if the cable pops out.
Tip — one-click launch: the
start-bridge.*files just runbridge.pyfrom a double-click, so you skip the terminal each session. On Windows, right-clickstart-bridge.bat→ Send to → Desktop (create shortcut). On macOS, if double-clicking opens it in an editor instead of running, mark it executable once:chmod +x start-bridge.command.
Debugging
If the LED won't light and you can't tell whether it's Godot or the bridge, run python arduino/bridge/ledtest.py L1 with the bridge running. It fires an L1/L0 command straight at the bridge's command port, exactly like Godot does. LED lights → the Arduino and bridge are fine, so the fault is on Godot's side. Stays dark → the problem is the bridge or the wiring, and Godot is off the hook.