A HERO Board wired to a breadboard of six push buttons with colored caps and a row of LEDs, one lit

C++ or MicroPython: which should you learn on a microcontroller?

Updated

Two languages run on the boards beginners learn with. C++ is what Uno-style boards like the HERO Board run, and what most microcontroller tutorials and libraries are written in. MicroPython is Python, slimmed down to fit on a chip like the one on the Raspberry Pi Pico.

Either one will teach you how code controls hardware. They feel very different to write, though, and they don't run on the same boards. Here is the same program in both, then the trade-offs that actually matter once you're at the desk.

The same program in both

A push button lights an LED for as long as you hold it down. First in C++ on the HERO Board, from the Cogsworth City course. Then in MicroPython on a Raspberry Pi Pico WH, from Neon Realm.

const int buttonPin = 2;  // the push button
const int ledPin = 13;    // the LED

int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {     // the pull-down makes HIGH mean "pressed"
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}
C++ on the HERO Board: Cogsworth City, Day 2 (comments trimmed)
from machine import Pin

led = Pin(15, Pin.OUT)
button = Pin(16, Pin.IN, Pin.PULL_DOWN)

while True:
    if button.value() == 1:
        led.on()
    else:
        led.off()
MicroPython on the Pico WH: Neon Realm, Day 2 (comments trimmed)

Line for line they do the same job: set up a pin for the LED and a pin for the button, then check the button forever and switch the LED to match. Three differences already show:

A fourth difference hides in the wiring. The HERO Board version needs a 10 kΩ pull-down resistor on the breadboard to hold the button's pin LOW until it's pressed. The Pico's chip has pull-down resistors built in, so Pin.PULL_DOWN replaces the part. That one's the board, not the language: the ATmega328P only has built-in pull-ups. Expect a few of those when you switch.

A Raspberry Pi Pico W on a breadboard with red, yellow and green LEDs, two capped push buttons and a photoresistor
The same kinds of parts on a Pico: buttons, LEDs and a light sensor, programmed in MicroPython.

Side by side

To do thisC++ on the HERO BoardMicroPython on the Pico
Make a pin an outputpinMode(13, OUTPUT);led = Pin(15, Pin.OUT)
Turn it ondigitalWrite(13, HIGH);led.on()
Wait one seconddelay(1000);time.sleep(1)
Read a buttondigitalRead(2)button.value()
Read a light sensoranalogRead(A0): 0 to 1023adc.read_u16(): 0 to 65535
Print a valueSerial.println(x);print(x)
Repeat forevervoid loop() { }while True:
Group lines into a blockBraces { }Indentation
Write a comment// like this# like this

The light-sensor ranges differ because the HERO Board's analogRead() is 10-bit, while MicroPython's read_u16() always scales to 16 bits.

Where C++ wins

Where MicroPython wins

Instant feedback. Thonny, the editor the Pico courses use, gives you a prompt connected to the board. Type a line, press Enter, and it runs on the chip straight away, with no compiling and no upload. Wire an LED to GP15 and try it:

>>> from machine import Pin
>>> led = Pin(15, Pin.OUT)
>>> led.on()
>>> led.off()
Typed one line at a time at Thonny's prompt

What stays the same

More than the syntax suggests. Pins as inputs and outputs, reading a sensor, a loop that runs forever, if and else, functions, a variable that keeps count: you learn each idea once. Switching languages later means learning new spelling for ideas you already own, which is far quicker than learning them the first time.

The electronics doesn't change at all. A resistor, an LED and a button behave the same whichever language switches them. The one real difference is the board's voltage, 5 V on the HERO Board and 3.3 V on the Pico, and What resistor do I need for an LED? shows what that does to an LED.

How to choose

Still torn? Write both programs above in the free browser simulator, which runs the HERO Board in C++ and the Pico in MicroPython. Whichever one you'd rather write a second program in is your answer. For the boards themselves side by side, see Uno-compatible or Raspberry Pi Pico.

Cogsworth City: HERO Starter Kit: Learn C++ on the HERO Board: twenty nights, a short film and a build each night, from the board's own light to buttons, light sensors and an RGB LED.

Python Starter Kit: Neon Realm: Learn MicroPython on a Raspberry Pi Pico WH: 20 lessons, from your first blinking light to a temperature page served over Wi-Fi.

Questions

Is Arduino code C or C++?

C++. The Arduino language is C++ with a small library of functions on top, like pinMode(), digitalWrite() and delay(), and a build step that fills in the parts you'd otherwise write yourself.

Can I run MicroPython on an Uno-compatible board?

No. MicroPython needs far more memory than the ATmega328P's 2 KB of RAM and 32 KB of flash. It runs on bigger chips, like the RP2040 on the Raspberry Pi Pico.

Is MicroPython real Python?

It's Python 3: the same syntax and most of the core language, with a smaller standard library and a machine module for pins and hardware. Code that sticks to the core language usually runs on both.

Which is easier for a complete beginner?

MicroPython reads more easily and gives faster feedback. C++ asks more of you up front and catches more mistakes before they run. Both make a fine first language, so choose by what you want to build.

Keep going