30. Embedded Systems (Integrated Systems) between the classic fundamentals and modern artificial intelligence tools (practical training track)

مدة القراءة 9 دقائق

First: The Fundamentals You Cannot Do Without (Even with the Most Powerful AI)

Mastering C Language — Not Just Learning It

  • Deep understanding of pointers (pointer arithmetic, pointers to functions, double pointers).
  • Understanding struct, union, enum, and bitfields (essential for memory optimization).
  • Manual memory management (malloc/free are prohibited in most embedded systems; you will mostly use static allocation only).
  • The volatile keyword (to prevent the compiler optimizer from removing reads of hardware-related variables).
  • Understanding interrupt service routines (ISRs) and how to write them in C.
  • inline assembly (rarely needed, but important in some situations).

Understanding Basic Electronics (At a Practical Level)

  • Resistors: Ohm’s Law, voltage divider, pull-up/pull-down resistors.
  • Capacitors: filtering (decoupling capacitors), timing (RC circuits).
  • Transistors (BJT/MOSFET): used as electronic switches (for driving motors or high-power LEDs).
  • Op-Amps: as comparators and simple amplifiers (for sensor signal processing).
  • ADC: understanding resolution (8-bit vs 12-bit), sampling rate, and reference voltage (Vref).
  • DAC: for generating audio signals or analog control signals.
  • Internal pull-up and pull-down resistors in microcontrollers.

Working with a Real Microcontroller (Choose One and Master It)

ARM Cortex-M (Best Industrial Choice)

  • Start with the STM32F103 Blue Pill (very cheap, huge community support).
  • Or the STM32F411 Black Pill (more powerful, also supports Arduino IDE).
  • Understand the Cortex-M core:
    • Thread and Handler modes.
    • NVIC (Nested Interrupt Controller).
    • SysTick timer.

AVR (Only for Basic Beginners)

  • Arduino Uno (good for beginners, but do not stay on it for too long).

ESP32 (For Connected Projects)

  • ESP32-C3 (supports Wi-Fi, Bluetooth, and RISC-V).
  • ESP32-S3 (supports lightweight AI acceleration).

Mastering Core Communication Protocols (and Implementing Them Manually)

GPIO

  • Reading buttons with hardware/software debouncing.
  • Generating PWM (for LED dimming or motor control).
  • Emulating simple protocols like OneWire using GPIO.

UART (The Simplest and Oldest)

  • Sending and receiving data.
  • Working with FIFO buffers.
  • Implementing a simple protocol on top of UART (frame start/end).

SPI (For Displays and Fast Sensors)

  • Understanding the 4 wires:
    • MOSI
    • MISO
    • SCLK
    • CS
  • Working with multiple devices on the same bus.
  • Using DMA with SPI for high-speed data transfer.

I2C (For Sensors and EEPROM)

  • Understanding addressing and ACK/NACK.
  • Working with devices that use different addresses.
  • Handling clock stretching.

Advanced Protocols (Later)

  • CAN (automotive systems).
  • USB (computer-connected devices).
  • Ethernet (industrial systems).

Second: What the AI Era Added to the Field

TinyML = Running AI on Microcontrollers with Less Than 256KB RAM

Why TinyML?

  • Ultra-fast response (no network latency).
  • Privacy (data never leaves the device).
  • Very low power consumption.
  • Low cost (no cloud servers required).

Where TinyML Is Used Today

  • Wake-word detection (“Hey Google”).
  • Sensor pattern recognition (abnormal vibration detection).
  • Motion classification (walking, running, falling).
  • Lightweight computer vision.

AI Models Suitable for Microcontrollers

  • Simple DNNs.
  • Small CNNs.
  • Decision Trees and Random Forests.
  • K-Means clustering.

How to Start Practically

  • Go to Edge Impulse and choose “Classify Motion”.
  • Connect your ESP32 or smartphone.
  • Train a model (it generates ready-to-use C code).
  • Deploy the code to the microcontroller and run inference offline.

Using AI as Your Personal Assistant (Not Inside the Device)

GitHub Copilot

  • Write:
    // Initialize UART2 with baud 115200, 8N1
  • Copilot generates the function automatically.
  • Useful for:
    • ISR generation.
    • Sensor driver functions.
    • Boilerplate embedded code.

Cursor

  • AI-powered editor based on VS Code.
  • Can modify entire projects based on prompts.

ChatGPT Plus and Claude

Useful for:

  • Explaining datasheets.
  • Generating error-handling code.
  • Debugging ISR freezes.
  • Optimizing Cortex-M performance.

Perplexity.ai

Useful for:

  • Researching rare embedded bugs.
  • Finding updated TinyML references.

Modern Tools You Should Know

TensorFlow Lite Micro

  • Runs TensorFlow models on microcontrollers.
  • Extremely small runtime (<20KB).
  • Supports ARM Cortex-M, RISC-V, and ESP32.

CMSIS-NN

  • Optimized neural-network kernels for Cortex-M.
  • 4–5x faster than naive implementations.

Neuton.ai

  • Converts AI models into pure C code without external libraries.
  • Excellent for extremely memory-limited devices.

Third: Suggested Practical Projects (From Beginner to Advanced)

Project 1: Temperature & Humidity Reader with LCD

Components

  • STM32 or Arduino.
  • DHT22 sensor.
  • 16×2 I2C LCD.

Skills Learned

  • Sensor reading.
  • LCD text output.
  • Timing management.

Project 2: Motion Alarm System

Components

  • ESP32.
  • PIR sensor.
  • Buzzer.
  • LED.

Skills Learned

  • Interrupts.
  • Timers.
  • Alarm logic.

AI Upgrade

Replace PIR logic with TinyML-based sound classification.


Project 3: TinyML Sound or Motion Detection on ESP32

Components

  • ESP32.
  • INMP441 microphone or MPU6050 sensor.

Workflow

  1. Record audio or motion samples.
  2. Upload data to Edge Impulse.
  3. Train a small CNN model.
  4. Deploy to ESP32.
  5. Trigger LED based on predictions.

Project 4: Industrial Motor Fault Prediction

Components

  • STM32F4.
  • Vibration sensor.
  • OLED display.

Goal

Classify:

  • Normal vibration.
  • Damaged bearing.
  • Unbalanced shaft.

AI Models

  • Decision Tree.
  • Small DNN.

Project 5: Smart Irrigation with AI Prediction

Components

  • ESP32-C3.
  • Soil moisture sensor.
  • Temperature sensor.
  • Water pump.

Skills Learned

  • ADC reading.
  • MOSFET control.
  • MQTT communication.

AI Feature

Predict soil dryness instead of fixed-time irrigation.


Project 6: Fall Detection for Elderly People

Components

  • Seeed XIAO BLE Sense
  • Battery.

AI Task

Detect:

  • Walking.
  • Sitting.
  • Falling.

Features

  • Real-time signal processing.
  • BLE alerts to smartphone.

Fourth: Extremely Important Advice in the AI Era

Do Not Fully Depend on AI for Code Generation

Generated code often:

  • Ignores memory limitations.
  • Violates real-time constraints.
  • Assumes Linux instead of bare metal.
  • Uses unsupported libraries.

Golden Rule

Use AI to generate 70% of the code, then manually review and optimize it.


Learn to Read Datasheets Yourself

AI often fails with:

  • Timing diagrams.
  • Complex I2C/SPI sequences.
  • Hardware-specific nuances.

Practice by manually programming simple sensors before relying on AI.


Focus on the Four Types of Optimization

Code Size

Use:

-Os

Speed

Use:

-O3

and DMA whenever possible.

Power Consumption

  • Sleep modes.
  • Disable unused clocks.
  • Dynamic frequency scaling.

Latency

  • Short ISRs.
  • Tail-chaining on Cortex-M.

Use Simulators Before Buying Hardware

Wokwi

  • Browser-based.
  • Supports Arduino, ESP32, STM32, RP2040.

QEMU

  • Full system emulation.

Proteus

  • Advanced electronics simulation.

  • ESP32-C3 — Best low-cost beginner option.
  • STM32 Black Pill — Best for professional embedded learning.
  • Seeed XIAO ESP32-S3 — Excellent for TinyML.
  • Raspberry Pi Pico — Great for learning C and MicroPython.
  • Arduino Nano 33 BLE Sense — Perfect TinyML learning board.
  • ESP32-S3-EYE — Good for lightweight computer vision.

Sixth: Best Books and References

  • Making Embedded Systems
  • TinyML
  • Embedded Systems with ARM Cortex-M

Final Practical Learning Roadmap

Phase 1 (2 Months) — Fundamentals Without AI

  • Learn C from K&R.
  • Study basic electronics.
  • Practice on ESP32-C3:
    • LED blinking.
    • Button debouncing.
    • UART “Hello World”.
    • Reading DHT11.

Phase 2 (1 Month) — Using AI as an Assistant

  • Install GitHub Copilot.
  • Rebuild previous projects with AI support.
  • Compare generated code with your manual implementations.

Phase 3 (2 Months) — Enter TinyML

  • Complete the Edge Impulse TinyML introduction course.
  • Build the motion detection project.
  • Read the first chapters of the TinyML book.

Phase 4 (2 Months) — Build a Full Project

Choose a real project:

  • Motor fault prediction.
  • Smart irrigation.
  • Fall detection.

Collect your own data, train multiple models, compare results, and publish everything on GitHub.


Phase 5 (Continuous Learning)

Learn:

  • FreeRTOS
  • Zephyr RTOS
  • RISC-V architecture.
  • Embedded Rust.