RobotGuide

Hardware & electrical · topic E9 · 15 hours

Arduino & the maker ecosystem

The fastest way to build hands-on feel: plug in USB and it runs. Its value is not syntax; it is letting you judge in three days whether you actually enjoy touching hardware. If yes, carry that feel toward STM32; if no, switch tracks early — cheaper than grinding on for half a year.

Foundations stage · Beginner
System software · Aware Embedded & controls · Proficient Mechanical · Aware

Tools
Tools

What to learn

  • The starter trio: digital and analog pins, PWM output, serial printing — enough to build your first moving mechanism
  • The truth about libraries: Servo, Wire, Serial are wrappers someone else wrote; read one layer of source and you know what they did for you
  • Three hard limits in industry: loop() has no real-time guarantee (millisecond-level jitter), libraries abstract the timing away, and there is no memory or version management
  • When you must switch: control period below 10 ms, closed-loop control, encoders or CAN on the wire — any one of these means it is time to migrate

The lesson · plain words

Arduino is the maker world's front door: an LED blinks in five minutes, but one beginner and the next are separated by a single delay(). This page covers the first gate from toy to engineering: non-blocking programming.

delay() is the seed of the beginner trap

During delay(400) the CPU is purely asleep and loop() is stuck — the second task never gets to run. Watch the figure: LED2's box stays empty; it is starved. Fine for a single-task toy, fatal in a robot.

The millis() non-blocking version: record the timestamp of the last action and check «is it time yet» on every loop() pass. The loop runs full speed every pass, and any number of tasks can interleave — this is the embryo of a bare-metal «scheduler».

Interactive figure · drag it and see

What this figure shows: two panels — the delay (blocking) mode, where a gray delay(400) bar pins the CPU to pure sleep and LED2 (yellow) waits forever without lighting, versus the millis (non-blocking) mode, where LED1's 200 ms blink (blue) and LED2's breathing pattern interleave freely; a button switches between the two modes. Takeaway: going from delay() to millis() timestamp polling is the first door from beginner to engineer.

From Arduino to «junior engineer»

Three upgrade moves: ① replace every delay with a millis-based state machine; ② learn interrupts (external encoder signals, timers); ③ give the serial link a real protocol (header + length + checksum — stop sending bare text). Do these three and your Arduino program structure ports straight to STM32.

The Arduino ecosystem's real value is libraries and community: sensor drivers work out of the box. Its engineering shortcomings are equally obvious: no HAL layering, debugging by serial prints, timing by feel. It is scaffolding, not a building.

Where it fits and where it does not

Fits: prototype validation, sensor tests, trade-show demos, education. Does not fit: any product that must run long-term (no watchdog mechanism), complex multi-task logic (move up to an RTOS), fine control (limited PWM resolution and clock accuracy).

Migration path: start on Arduino → logic gets complicated, move to STM32+CubeMX → concurrency needed, add FreeRTOS (E11). Each of the three steps has standalone value; there is no need to skip levels.

How far to go

Be able to write a non-blocking multi-task blink (3 LEDs, different periods, no mutual interference); read an encoder with interrupts and debounce it; design a simple binary serial protocol and communicate both ways. Do these three and you can graduate from the Arduino stage.

Three questions — do you really get it?

1. What is the essential problem with delay(500)?

  • ANot accurate enough
  • BThe CPU idles blocked and every other task starves
  • CHigh power draw
Show answer

B. While blocked, loop stands still. Non-blocking timestamp polling is the only correct answer to bare-metal multitasking.

2. The core of a millis()-based «blink every 200 ms» is?

  • ARecord the last toggle time and compare now-last>=200 in loop
  • Bdelay(200) inside the loop
  • CA timer interrupt
Show answer

A. Timestamp polling. The interrupt version is faster, but polling is lesson one of non-blocking thinking.

3. The habit most worth building in the Arduino stage is?

  • AUse global variables liberally
  • BProtocol-ize the serial link + non-blocking structure
  • CUse floating point wherever possible
Show answer

B. Both habits hold on any MCU platform — the most valuable part of the scaffolding.

Keep going deeper

Links without a marker stay on this site; the rest point to the Chinese edition until its translation batch lands.

How it fails in the field

  • Running a 1 kHz current loop on Arduino: it oscillates no matter how you tune — the algorithm is not wrong, the loop period itself is drifting
  • Believing analogWrite is analog output when it is actually PWM; measuring 2.5 V on a multimeter and thinking you understand it

You have learned enough when

Build a device on one Uno where a button trigger makes a servo move to given angles and back, and explain why it falls short in a 1 kHz closed loop.

The Chinese edition carries the full topic page for Arduino & the maker ecosystem, including the complete outline, depth requirements per career track, and further derivations: robotguide.dev/k/E9/.