KevsRobots Learning Platform
100% Percent Complete
By Kevin McAleer, 9 Minutes
Youâve completed the Arduino to MicroPython course! You now understand the key differences between Arduino C++ and MicroPython, and youâve built two complete projects demonstrating IoT and robotics applications.
Letâs review what youâve learned and where to go next.
Core Concepts:
Hardware Control:
Communication:
Projects:
Basic Syntax:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
int x = 10; |
x = 10 |
No type declaration, no semicolon |
float voltage = 3.3; |
voltage = 3.3 |
Type inferred automatically |
String msg = "Hello"; |
msg = "Hello" |
Use str type |
bool flag = true; |
flag = True |
Capital T! |
// comment |
# comment |
Different comment symbol |
Control Flow:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
if (x > 10) { } |
if x > 10: |
Colon and indentation |
else if (x > 5) { } |
elif x > 5: |
Use elif |
else { } |
else: |
Colon and indentation |
for (int i=0; i<10; i++) |
for i in range(10): |
Use range() |
while (x < 100) { } |
while x < 100: |
Colon and indentation |
&& |
and |
Logical AND |
|| |
or |
Logical OR |
! |
not |
Logical NOT |
Functions:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
void setup() { } |
Not required | Just write code at top level |
void loop() { } |
while True: |
Explicit infinite loop |
int addNumbers(int a, int b) |
def add_numbers(a, b): |
No types, use def |
return value; |
return value |
No semicolon |
Digital I/O:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
pinMode(13, OUTPUT) |
led = Pin(13, Pin.OUT) |
Create Pin object |
pinMode(2, INPUT_PULLUP) |
btn = Pin(2, Pin.IN, Pin.PULL_UP) |
Pin object with pull-up |
digitalWrite(13, HIGH) |
led.on() or led.value(1) |
Call method on Pin |
digitalWrite(13, LOW) |
led.off() or led.value(0) |
Call method on Pin |
digitalRead(2) |
btn.value() |
Returns 0 or 1 |
Analog I/O:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
analogRead(A0) |
adc = ADC(Pin(26))adc.read_u16() |
16-bit (0-65535) |
analogWrite(9, 128) |
pwm = PWM(Pin(9))pwm.duty_u16(32768) |
16-bit (0-65535) |
| Value: 0-1023 (10-bit) | Value: 0-65535 (16-bit) | Higher resolution |
| PWM: 0-255 (8-bit) | PWM: 0-65535 (16-bit) | Higher resolution |
Timing:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
delay(1000) |
time.sleep(1) |
SECONDS not milliseconds! |
delay(100) |
time.sleep(0.1) |
Convert ms to seconds |
delayMicroseconds(10) |
time.sleep_us(10) |
Microseconds |
millis() |
time.ticks_ms() |
Milliseconds since boot |
micros() |
time.ticks_us() |
Microseconds since boot |
currentMillis - previousMillis |
time.ticks_diff(current, previous) |
Handles wrap-around |
Serial/Print:
| Arduino C++ | MicroPython | Notes |
|---|---|---|
Serial.begin(9600) |
Not required | Just use print() |
Serial.println("Hello") |
print("Hello") |
Simpler! |
Serial.print(value) |
print(value, end="") |
No newline |
Serial.print("Value: " + String(x)) |
print(f"Value: {x}") |
F-strings |
Common Conversions:
# Arduino delay to MicroPython
delay(1000) â time.sleep(1) # 1 second
delay(500) â time.sleep(0.5) # 0.5 seconds
delay(100) â time.sleep(0.1) # 0.1 seconds
delayMicroseconds(10) â time.sleep_us(10) # 10 microseconds
# Arduino PWM to MicroPython
analogWrite(pin, 0) â pwm.duty_u16(0) # Off
analogWrite(pin, 64) â pwm.duty_u16(16384) # 25%
analogWrite(pin, 128) â pwm.duty_u16(32768) # 50%
analogWrite(pin, 191) â pwm.duty_u16(49152) # 75%
analogWrite(pin, 255) â pwm.duty_u16(65535) # 100%
# Arduino ADC to voltage (5V, 10-bit)
voltage = (analogRead(A0) / 1023.0) * 5.0
# MicroPython ADC to voltage (3.3V, 16-bit)
voltage = (adc.read_u16() / 65535) * 3.3
1. Milliseconds vs Seconds
# WRONG - waits 1000 seconds!
time.sleep(1000)
# RIGHT - waits 1 second
time.sleep(1)
# If you're thinking in milliseconds:
time.sleep_ms(1000) # 1000 milliseconds = 1 second
2. Boolean Values
# WRONG - lowercase won't work
flag = true
# RIGHT - capitalize
flag = True
3. Indentation Errors
# WRONG - inconsistent indentation
if x > 10:
print("Big")
print("Really big") # Error!
# RIGHT - consistent 4 spaces
if x > 10:
print("Big")
print("Really big")
4. Pin Numbers
# Different boards use different pin numbers!
# Pico / Pico 2W - use GP numbers
led = Pin(25, Pin.OUT) # GP25
# Pico W - built-in LED is special
led = Pin("LED", Pin.OUT)
# Arduino Nano ESP32 - use Arduino numbers
led = Pin(13, Pin.OUT) # D13
5. ADC Resolution
# Arduino gives 0-1023
# MicroPython gives 0-65535
# Don't compare directly!
# Convert MicroPython to Arduino range:
arduino_value = adc.read_u16() >> 6 # Shift right 6 bits
Use MicroPython when:
Use Arduino C++ when:
Both work great for:
Best MicroPython Boards:
Continue your MicroPython journey:
Official Documentation:
Community:
Tools:
Books:
Save this as your starting point for new MicroPython projects:
"""
Project Name: [Your Project Name]
Description: [Brief description]
Hardware: [Board type and components]
"""
from machine import Pin, PWM, ADC
import time
# Configuration
LED_PIN = 25
BUTTON_PIN = 14
# Hardware setup
led = Pin(LED_PIN, Pin.OUT)
button = Pin(BUTTON_PIN, Pin.IN, Pin.PULL_UP)
# Global variables
running = True
def setup():
"""Initialize hardware and print status"""
print("=" * 50)
print("Project: [Your Project Name]")
print("=" * 50)
# Startup blink
for i in range(3):
led.toggle()
time.sleep(0.2)
led.off()
print("Ready!")
def loop():
"""Main program loop"""
while running:
# Your code here
if button.value() == 0:
led.on()
else:
led.off()
time.sleep(0.1)
def main():
"""Main program entry point"""
try:
setup()
loop()
except KeyboardInterrupt:
print("\nStopping...")
finally:
led.off()
print("Cleanup complete")
if __name__ == '__main__':
main()
Youâre now equipped to:
Remember:
The biggest advantage of MicroPython?
You can type commands directly to your hardware and see instant results. No compile, no upload - just immediate feedback. This makes learning and debugging dramatically faster than traditional Arduino development.
Try building one of these:
Lesson 1: Why choose MicroPython vs Arduino C++ Lesson 2: Syntax basics - variables, types, comments Lesson 3: Control flow - if/elif/else, loops, no braces Lesson 4: Functions - def keyword, no setup/loop required Lesson 5: Pin control - Pin class, digital I/O Lesson 6: Analog and PWM - ADC and PWM classes Lesson 7: Timing - seconds vs milliseconds (critical!) Lesson 8: Serial and REPL - print() and interactive debugging Lesson 9: IoT project - WiFi temperature monitor Lesson 10: Robot project - Motor control and sensors Lesson 11: This lesson - reference guide and next steps
Thank you for completing this course! Youâve taken a big step in expanding your microcontroller programming skills. MicroPython opens up new possibilities for rapid prototyping, IoT development, and creative projects.
Keep learning, keep building, and most importantly - have fun!
If you found this course helpful, consider exploring other courses on this site and joining the maker community. Share your projects, ask questions, and help others learn.
Happy Making!
You can use the arrows â â on your keyboard to navigate between lessons.
Comments