Classroom Public page

Week 7: Intro to Microcontrollers and Arduino R4

576 words

Meet the Arduino R4. Install the IDE. Upload your first sketch (the canonical blinking LED). By the end of the week you can describe what a microcontroller is, name the major parts of the R4 board, and have a working development environment that uploads code to the board reliably.


Reading (~45 min)

  • The Arduino R4 quick-start guide that comes with the Classroom Pack
  • Optional: the Renesas RA4M1 chip datasheet introduction (the chip on the R4). Skim only; you do not need datasheet depth this week

Lecture (~2 hr)

  • What a microcontroller is. A small computer on a single chip: CPU, RAM, flash storage, and I/O peripherals all in one package. The R4's chip (Renesas RA4M1) is a 32-bit ARM Cortex-M4 running at 48 MHz with 256 KB of flash and 32 KB of RAM
  • How it differs from a desktop CPU. Less memory; slower clock; no operating system by default; pin-level access to the world. The trade-off: less abstraction, more direct control
  • The R4 board tour. Where the chip is; where the USB port is; where the power input is; where the digital pins are; where the analog pins are; where the LED-builtin lives; where the reset button is
  • The Arduino IDE workflow. Install (Windows / macOS / Linux). Select board (Arduino UNO R4 Minima or WiFi). Select port. Open the canonical "Blink" example. Click upload. Watch the upload progress; watch the LED start blinking
  • The compile-and-flash cycle. Source code (a .ino sketch) → C++ compilation → linked binary → uploaded over USB → flashed to the R4's program memory. The same compile-and-flash pattern you will see in CSA-101 (with FPGA bitstreams) and CON-101 (with embedded firmware)

Lab exercises (~2 hr)

Lab 7.1: Arduino Blink. Install the IDE. Upload the Blink example to your R4. Modify the delay to change the blink rate. Upload again. ~60 minutes.

Lab 7.2: External LED. Wire an external LED to pin 8 (with current-limiting resistor; you know how from week 5). Modify Blink to control pin 8 instead of LED_BUILTIN. ~60 minutes.

Independent practice (~3 hr)

  • Modify Blink to blink at three different rates in sequence (slow, medium, fast). Use multiple delay() calls or a loop with a varying delay
  • Wire three different-color LEDs to three different pins. Modify your sketch to blink them in a pattern (cycle one at a time; or all three on then all three off)
  • Read the Arduino reference page for digitalWrite, delay, and pinMode. The Arduino reference is dense but well-organized; build the habit of consulting it every time you encounter a new function

Reflection prompts

  1. The Arduino R4 runs at 48 MHz; a desktop CPU runs at ~4 GHz. The R4 is ~80× slower in clock speed. What can the R4 still do that justifies its existence?
  2. The compile-and-flash cycle takes a few seconds per change. A desktop CPU's "compile and run" cycle is similar but the run happens on the same machine. Why is the flash step necessary on an embedded device?
  3. Your first sketch ran 24/7 forever (until you uploaded a new sketch or powered off the board). What did the sketch do during the delay()? Was the CPU idle, or busy?

What's next

Week 8 makes digital I/O bidirectional. You add a pushbutton to your circuit; the Arduino reads the button state; based on the button, it turns LEDs on or off. The world starts talking back.