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

By the end of this lesson you will be able to describe how a call travels across the Bridge, name the four verbs, and say which types can cross it.
So far the two brains have lived side by side without a word between them. This lesson gives them a way to talk. It is the most valuable idea in the whole course, so let’s take it slowly.
Watch this video first, then come back and we will build on it.
At the end of lesson 3 we had the Q Board blinking from the sketch while Python ran a loop of its own. Both sides worked, but neither knew the other existed. Python could not tell the sketch to blink, and the sketch could not tell Python what the sensor said.
The Bridge fixes that.
The Bridge uses an idea called RPC, short for remote procedure call. Think of ordering at a café counter. You do not walk into the kitchen and start cooking. You ask for “a flat white” by name, and the kitchen does the work and hands it back.
RPC works the same way:
Python never needs to know how the sketch turns an LED on. It only needs the name. And either side can be the kitchen: the sketch can provide functions for Python to call, and Python can provide functions for the sketch to call.
Between the two sides sits a Linux background service called the Arduino Router. Think of it as a switchboard. The sketch connects to it, and every Python program connects to it. Nobody talks to anybody directly.
When Python calls a name, the router looks up who provides it, passes the message on and brings the answer back. Because everyone connects to the router, several Linux programs can talk to the sketch at the same time. Linux programs can also call each other through it.
Watch one message travel.
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.
Press Next to step through one call from Python to the sketch, and watch the message on the wire at each step.
Each side has four ways to take part:
| Verb | What it does | Use it when |
|---|---|---|
provide |
Offers a named function to the other side | The function is short, such as storing a value. It runs in the Bridge’s high-priority background thread |
provide_safe |
Offers a named function, run in the main loop() context |
The function uses Arduino APIs such as digitalWrite or Serial |
call |
Calls a named function and waits for the answer | You need the result, or you need to know it finished |
notify |
Calls a named function and does not wait | You only want to send something and move on |
In the sketch these are Bridge.provide, Bridge.provide_safe, Bridge.call and Bridge.notify. In Python you use Bridge.call, Bridge.notify and Bridge.provide after from arduino.app_utils import App, Bridge. Python’s call blocks until the sketch answers and has a timeout (10 seconds by default).
A good rule of thumb: if your sketch function touches pins or Serial, use provide_safe. Lesson 9 shows what goes wrong otherwise.
Here is one call from start to finish:
sequenceDiagram
participant P as Python
participant R as Router
participant S as Sketch
P->>R: call "set_led_state"
R->>S: forward to the sketch
S->>S: run set_led_state
S-->>R: result
R-->>P: result
Under the hood the messages are MessagePack-RPC. A request looks like [0, id, "name", [args]] and the response looks like [1, id, error, result]. You never write these by hand.
Values are converted automatically between the two languages:
| Python | Sketch (C++) |
|---|---|
bool |
bool |
int |
integer types |
float |
float / double |
str |
String |
list |
std::vector |
dict |
std::map |
bytes |
std::vector<uint8_t> |
None |
void |
/dev/ttyHS1 or Serial1 yourself. That serial link is what the router uses to reach the microcontroller. If your own code opens it, you will break the Bridge.Here is Arduino’s own smallest example. Two files, one blinking LED, but this time Python decides.
python/main.py
from arduino.app_utils import *
import time
led_state = False
def loop():
global led_state
time.sleep(1)
led_state = not led_state
Bridge.call("set_led_state", led_state)
App.run(user_loop=loop)
sketch/sketch.ino
#include "Arduino_RouterBridge.h"
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Bridge.begin();
Bridge.provide_safe("set_led_state", set_led_state);
}
void loop() {
}
void set_led_state(bool state) {
// LOW state means LED is ON
digitalWrite(LED_BUILTIN, state ? LOW : HIGH);
}
Walking through it:
Bridge.begin() starts the Bridge. Without it nothing works.Bridge.provide_safe("set_led_state", set_led_state) puts set_led_state on the menu. We use provide_safe because the function calls digitalWrite.set_led_state flips the pin. The LED is active low, so LOW means on.loop() is called repeatedly by App.run(user_loop=loop). Each time round it waits a second, flips led_state and calls Bridge.call("set_led_state", led_state).Run this on the board. LED 3 blinks red once a second, just like lesson 3, but now Python is deciding when. The sketch has no timing at all. Lessons 7 and 8 build the Q Board on this idea.
time.sleep(1) to time.sleep(0.2) in Python only. Run it again. The blink speeds up and the sketch has not changed."set_led_state" to "set_led" in Python. Run it and see what happens. Lesson 9 explains the error. Then put it back.print(led_state) inside Python’s loop() and watch the Python console tab as the LED blinks.Problem: Python reports an error and the LED does not blink.
Solution: Check that the name in Bridge.call("...") matches the name in Bridge.provide_safe("...") exactly.
Why: The router finds the function by name, so a typo means nobody is providing it.
Problem: The sketch never answers.
Solution: Make sure Bridge.begin() is in setup().
Why: Until the sketch calls Bridge.begin(), it is not connected to the router.
Quick quiz 1 of 3
What does the Arduino Router do?
Quick quiz 2 of 3
Which verb should you use for a sketch function that calls digitalWrite?
Quick quiz 3 of 3
Which of these should your own code never do?
Comments