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

By the end of this lesson you will be able to create an App, say what each file in its folder does, and blink one LED from each brain.
Now let’s build something of our own. We’ll create an App called Q Board and make two LEDs blink, one from each brain. This is Q Board stage 1, and everything else in the course builds on it.
Q Board.App Lab makes a folder of files for you. It lives on the board in /home/arduino/ArduinoApps/, and it is the folder you’ll work in all course.
| File | Role |
|---|---|
app.yaml |
The manifest: the App’s name, icon and Bricks. App Lab manages it |
python/main.py |
The Python side. Mandatory, it is the entry point |
python/requirements.txt |
Optional list of extra pip packages |
sketch/sketch.ino |
Optional C++ for the microcontroller |
sketch/sketch.yaml |
Sketch settings and libraries. App Lab manages it |
README.md |
Optional notes about the App |
You can add other things too, such as an assets/ folder for a web page later.
Why this matters: Python is the core of an App, and the sketch is optional. A sketch without a main.py isn’t an App.
flowchart LR
R["Press Run"] --> C["Compile the sketch"]
C --> F["Flash the microcontroller"]
F --> P["Start python/main.py"]
That is what Run does, every time.
Open sketch/sketch.ino and put this in it.
sketch/sketch.ino
// Q Board, stage 1: the microcontroller blinks LED 3
void setup() {
pinMode(LED3_R, OUTPUT);
pinMode(LED3_G, OUTPUT);
pinMode(LED3_B, OUTPUT);
// These LEDs are "active low": HIGH turns a colour off, LOW turns it on
digitalWrite(LED3_R, HIGH);
digitalWrite(LED3_G, HIGH);
digitalWrite(LED3_B, HIGH);
}
void loop() {
digitalWrite(LED3_G, LOW); // green on
delay(500);
digitalWrite(LED3_G, HIGH); // green off
delay(500);
}
LED 3 belongs to the microcontroller. It has three colour pins: LED3_R, LED3_G and LED3_B. In setup() we make them outputs and turn them all off.
Here is the surprise. These LEDs are active low. LOW turns a colour on and HIGH turns it off, which is the opposite of what you might expect. That is why setup() writes HIGH to all three: it makes sure everything starts off. Then loop() switches green on with LOW, waits half a second, and switches it off with HIGH.
Common mistake: writing HIGH to turn an LED on. You’ll get an LED that is on all the time, or never.
Every App needs a python/main.py, even if the sketch does the real work. This is the smallest valid one.
python/main.py
from arduino.app_utils import App
print("Q Board is starting")
App.run()
App.run() starts the App and keeps your program running. It must be the last line. Code after App.run() never runs.
Press Run. App Lab compiles the sketch, flashes the microcontroller, and starts the Python side. LED 3 blinks green.
At the bottom of App Lab are three console tabs.
print() in main.py. You should see Q Board is starting.Serial.print.So print() in Python shows in the Python tab, and Serial in the sketch shows in the Serial Monitor tab. They are different tabs because they are different brains.
Let’s make the Linux side blink LED 1, at a different speed. Replace python/main.py with this.
python/main.py
import time
from arduino.app_utils import App, Leds
def loop():
Leds.set_led1_color(0, 0, 1) # LED 1 blue (red, green, blue: 1 is on)
time.sleep(0.2)
Leds.set_led1_color(0, 0, 0) # LED 1 off
time.sleep(0.2)
App.run(user_loop=loop)
Leds controls the two LEDs that belong to Linux. Leds.set_led1_color(r, g, b) takes 0 or 1 for each colour, and here 1 means on. That is the opposite of the sketch, because these are a different set of LEDs.
App.run(user_loop=loop) still ends the file, but now it also calls loop() over and over. Our loop turns LED 1 blue, waits 0.2 seconds, turns it off and waits again.
Press Run again. You should see LED 3 blinking green at half-second intervals, and LED 1 blinking blue faster. Two brains, two programs, two speeds.
The box below runs the Python above in your browser. A stand-in sketch blinks LED 3 green, and your Python blinks LED 1.
The simulator needs JavaScript. Without it, read the program above and run it on your board.
Press Run, then change the two time.sleep() values and run it again. The simulator is a stand-in, not the real board: no C++ runs in it, so do try this on your Uno Q as well.
Q Board stage 1 is complete. Notice something: neither side knows the other exists. How would Python tell the sketch to do something? That is the question lesson 6 answers, and in the meantime we’ll use the microcontroller to draw on the LED matrix in lesson 4.
time.sleep() values to 0.5 and see how the two blinks line up over time.Problem: The LED is on when you expect it off, or the other way round.
Solution: Remember LED 3 and LED 4 are active low. Use LOW for on and HIGH for off.
Why: The LEDs are wired so that pulling the pin low turns them on.
Problem: The App won’t run, or Python reports an error about main.py.
Solution: Check python/main.py exists and ends with App.run() or App.run(user_loop=loop).
Why: main.py is the mandatory entry point, and App.run() is what keeps it going.
Problem: Code you added after App.run() never does anything.
Solution: Move it above App.run().
Why: App.run() doesn’t return, so lines after it never run.
Problem: You can’t find your print() or Serial output.
Solution: Look in the right tab. print() goes to Python, Serial goes to Serial Monitor, and compile errors go to App launch.
Why: Each tab shows output from a different part of the App.
Quick quiz 1 of 3
To turn LED 3 green on from a sketch, what do you write?
Quick quiz 2 of 3
What must every main.py end with?
App.run() keeps your Python running. Code after it never runs.Quick quiz 3 of 3
Where does print("hello") in main.py appear?
print() shows in the Python tab. Serial output from the sketch shows in Serial Monitor.
Comments