By Kevin McAleer, 7 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to recognise a Bridge deadlock, fix it, and use the error messages and a checklist to find the common Bridge bugs.
Good news: Bridge problems are not a mystery. There are only a handful of mistakes, nearly everyone makes them, and each one has a clear sign. Once you know the signs, you can fix most problems in a minute.
Let’s start with the nastiest one, and watch it happen before it happens to you.
This step-through needs JavaScript. In short: Python packs the call into a message, the Arduino Router passes it to the sketch, the sketch runs the function, and the answer comes back the same way.
Step through it with Next. You will see a Serial.println() inside a Bridge.provide() function, why that hangs the conversation, and how provide_safe() fixes it.
Here is a small sketch with exactly that mistake in it. It is wrong on purpose.
sketch/sketch.ino
#include <Arduino_RouterBridge.h>
void set_led(bool on) {
digitalWrite(LED3_G, on ? LOW : HIGH);
Serial.println(on ? "LED on" : "LED off"); // printing inside a provide() callback
}
void setup() {
pinMode(LED3_G, OUTPUT);
Serial.begin(9600);
Bridge.begin();
Bridge.provide("set_led", set_led);
}
void loop() {
}
A function registered with provide() runs in the Bridge’s own background thread, while the Bridge is busy answering. Printing, or starting another call, from there means starting a new conversation while still in the middle of one. Arduino’s documentation puts it plainly: do not use Bridge.call() or Monitor.print() inside functions registered with Bridge.provide(). Initiating a new communication while responding to one causes system deadlocks. Use provide_safe() instead.
The fix is one word.
sketch/sketch.ino
#include <Arduino_RouterBridge.h>
void set_led(bool on) {
digitalWrite(LED3_G, on ? LOW : HIGH);
Serial.println(on ? "LED on" : "LED off"); // fine now: this runs inside loop()
}
void setup() {
pinMode(LED3_G, OUTPUT);
Serial.begin(9600);
Bridge.begin();
Bridge.provide_safe("set_led", set_led);
}
void loop() {
}
provide_safe() does not run the function in the background thread. It waits, and runs it in the main loop() context, where Arduino calls such as digitalWrite and Serial.println are fine.
An honest note. Some of Arduino’s own example apps print inside provide(), and you may well get away with it. It can work for a long time and then hang on an unlucky moment, which is the worst kind of bug to track down. provide_safe() is the rule that always works.
| What the function does | Register it with |
|---|---|
| Only stores a value (copies memory, sets a variable) | provide |
Anything else (pins, Serial, Monitor, other Arduino APIs) |
provide_safe |
If in doubt, use provide_safe. In lesson 7, draw only copies memory, so it uses provide. set_status writes to pins, so it uses provide_safe.
What if the sketch does not answer? A good Python program expects that and carries on. This main.py goes with the fixed sketch above.
python/main.py
import time
from arduino.app_utils import App, Bridge
led_on = False
def loop():
global led_on
led_on = not led_on
try:
Bridge.call("set_led", led_on, timeout=2)
print("LED is", "on" if led_on else "off")
except TimeoutError:
print("The sketch didn't answer within 2 seconds")
except ValueError as error:
print("The sketch refused the call:", error)
time.sleep(1)
App.run(user_loop=loop)
Run it and the green LED 3 blinks once a second.
The key line is Bridge.call("set_led", led_on, timeout=2). The timeout is how many seconds to wait for an answer, and the default is 10. Wrapping the call in try means one bad moment prints a message instead of stopping your program.
| Error | What it means |
|---|---|
Python ValueError |
The sketch answered with an error. Most often nothing provides that name: a typo, or the sketch was not flashed yet. The message tells you more. |
Python TimeoutError |
No answer arrived within timeout (10 seconds by default). |
Python ConnectionError |
The connection dropped while waiting. |
Python RuntimeError |
Bridge.call() was used inside a provided handler. Nested calls are not supported. |
Python AppError at start |
The router could not be reached within 5 seconds. Check the arduino-router service. |
Sketch: .result(x) returns false |
The call failed. The RpcCall object has isError(), getErrorCode() and getErrorMessage() for the detail. |
| Sketch: a message vanishes | A message over 256 bytes is dropped. |
This table is this lesson’s Common Issues. Come back to it whenever the Python tab shows something you do not recognise.
Also remember: never open /dev/ttyHS1 on Linux or Serial1 in the sketch. The router owns them, and your own code opening them will get in its way.
When names and code look right but nothing works, check the router. It is the Linux service that carries every Bridge message. These commands are typed in a terminal on the board. Lesson 10 covers how to get one, using an ADB shell or SSH, so for now just read them.
Is it running?
systemctl status arduino-router
Watch its log live while you run your App (press Ctrl+C to stop watching):
journalctl -u arduino-router -f
Restart it if it looks stuck:
sudo systemctl restart arduino-router
Work down this list in order. It fixes most problems.
provide versus provide_safe for each function.flowchart TD
A["Something is wrong"] --> B{"Did the sketch compile?"}
B -->|No| C["Fix the error in App launch"]
B -->|Yes| D{"What does the Python tab say?"}
D -->|"ValueError"| E["Check names match on both sides"]
D -->|"TimeoutError"| F["Check provide vs provide_safe"]
D -->|"AppError"| G["Check the router service"]
"set_ledd"). Run it and read the error. It is a ValueError, and now you know the sign.Bridge.provide_safe(...) line in the sketch, press Run, and watch the Python tab. Which error do you get, and what does the table say it means? Put the line back afterwards.draw, set_status, get_limit, on_reading), write which side provides it, and whether the sketch ones should be provide or provide_safe, and why.Quick quiz 1 of 3
Why can printing inside a Bridge.provide() function cause a deadlock?
Bridge.call(), Monitor.print() and Serial.print() inside provide() functions. provide_safe() runs the function in loop() instead.Quick quiz 2 of 3
A function only stores a number in a variable. Which should you use?
provide_safe is the rule that always works.Quick quiz 3 of 3
Python raises ValueError when it calls "set_led". What is the most likely cause?
ValueError means the sketch answered with an error. A timeout would show as TimeoutError instead.
Comments