Files
tyler parker 28339f198f Add double-click bridge launchers; document ledtest + launchers in READMEs
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.
2026-08-09 21:39:43 +00:00

39 lines
2.2 KiB
Markdown

# Part 1 — Your First Arduino Round-Trip
Code for [*"Godot Isn't Just for Games: Your First Arduino Round-Trip"*](https://codebycandle.com/blog/godot-arduino-led-first-light).
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
1. **Flash** `arduino/LedBasics/LedBasics.ino` to the Uno (Arduino IDE, 115200 baud).
2. **Bridge:** `pip install pyserial`, then start the relay and leave it running — either **double-click `arduino/bridge/start-bridge.bat`** (Windows) / **`arduino/bridge/start-bridge.command`** (macOS), or run `python arduino/bridge/bridge.py` yourself.
3. **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 run `bridge.py` from a double-click, so you skip the terminal each session. On Windows, right-click `start-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.