100% found this document useful (1 vote)
667 views78 pages

2024 03 15 Iot Systems With Esp32

The document discusses Espressif Systems, an IoT chip company that leads the market with over 1 billion chip shipments, and their ESP32 and ESP32-S chips which are popular platforms for IoT projects. It also covers programming languages and tools like Rust, C/C++, and ESP-IDF that are used to develop applications for Espressif chips, as well as several open source projects built with ESP32.

Uploaded by

Ramesh Nagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
667 views78 pages

2024 03 15 Iot Systems With Esp32

The document discusses Espressif Systems, an IoT chip company that leads the market with over 1 billion chip shipments, and their ESP32 and ESP32-S chips which are popular platforms for IoT projects. It also covers programming languages and tools like Rust, C/C++, and ESP-IDF that are used to develop applications for Espressif chips, as well as several open source projects built with ESP32.

Uploaded by

Ramesh Nagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

IoT Systems

with
ESP32

2024-03-15
FIT VUT - Brno
Juraj Michálek - Espressif Systems
What is your favorite?
Programming language

Operating system

Editor

IDE

Cloud provider
Espressif System
Espressif Systems is a public multinational, fabless semiconductor company established in 2008, with offices in China, the Czech Republic,
India, Singapore and Brazil.

Espressif Leads the IoT Chip Market with Over 1 Billion Global Shipments

ESP8266 - introduces WiFi

ESP32, ESP32-S - Xtensa cores

ESP32-C, H, P series - RISC-V cores

Open source: https://github.com/espressif


C/C++, Rust - Open source
C/C++ - 229 repositories at https://github.com/espressif

- 12 200+ starts - ESP-IDF


- Espressif Iot Development Framework (CMake based)

Rust - 51 repositories at https://github.com/esp-rs/

- 500+ starts - esp-hal

Arduino - https://github.com/espressif/arduino-esp32

- 12 300+ stars
Elektor Mag

Special Guest Edition

https://www.elektor.com/products/elektor-s
pecial-espressif-guest-edition-2023-pdf-en
Wearables
The Ultimate Guide to Informed Wearable Technology

- book: https://packt.link/01VBv
Developing IoT Projects
with ESP32

https://blog.espressif.com/book-revie
w-developing-iot-projects-with-esp32
-2nd-edition-facdef7545bb
MicroPython Projects
https://www.packtpub.com/product/microp
ython-projects/9781789958034
ESP32-C3 Wireless Adventures a Comprehensive Guide to IoT
https://espressif.github.io/esp32-c3
-book-en/
More books about ESP32
https://www.espressif.com/en/ecosystem/community-engagement/books
Designing Open Hardware - esp-rust-board
KiCad templates

https://github.com/esp-rs/esp-rust-board

ESP32-C3-DevKit-RUST-1

https://www.espressif.com/en/products/devkits
Open Hardware - ESP32-S3-BOX-3
https://github.com/espressif/esp-box

Joystick controller

https://github.com/espressif/esp-box/tree/master/exampl
es/esp_joystick/joystick_controller
Desktop vs. Embedded development
Memory: GB (TB) vs. kB (MB bytes of PSRAM)

CPU Cores: 8 - 64 vs. 1 - 2

CPU Frequencies: GHz vs. 20-240 MHz

Power consumption: 100s of Watts vs. Milliwatts

OS kernel: 61k files vs. 10k files in ESP-IDF

(FreeRTOS kernel: 7 C files)


OSes - C/CPP, Rust
no_std a.k.a. bare metal with Rust - https://github.com/esp-rs/esp-hal (minimalistic)
ESP-IDF (OS based on FreeRTOS) - https://github.com/esp-rs/esp-idf-hal

Zephyr - https://zephyrproject.org/
- EDC22 Day 1 Talk 10: Applications of Asymmetric Multiprocessing with ESP32 Devices -
including Rust on one core - https://youtu.be/oble9ObAqxM

NuttX - https://nuttx.apache.org/ (as app, Linux-like OS)

SVD files: https://github.com/espressif/svd


Programming languages
Active support by Espressif teams

- C/C++
- most common choice - https://github.com/espressif/esp-idf
- Rust
- security and memory guaranties of Rust
- https://github.com/esp-rs
- multi-target support: Xtensa, RISC-V, plus WASM, desktops or mobile
- Arduino - Maker choice
- Arduino IDE 2.x
- note: check the license for production
wokwi.com/rust

Contribute: https://github.com/wokwi

EDC22 Day 1 Talk 9: Your browser is ESP32


- Wokwi - https://youtu.be/TKe4MgD6O8o
Espressif's Matter Demo - https://youtu.be/Jr4Lut_NgqA
Many Problems of Home Automation and IoT
Silos

Fragmentation

Security

UX

Development

Certification


Matter

Repo: https://github.com/project-chip/connectedhomeip

Specs: https://csa-iot.org/developer-resource/specifications-download-request/

Article: https://blog.espressif.com/what-does-matter-mean-to-you-fa3bb53a7793
Matter for end user
No more silos

More automation - device-to-device communication

No more transport silos

More ecosystems

Better security

https://blog.espressif.com/what-does-matter-mean-to-you-fa3bb53a7793
Espressif and Matter
Support for ESP32 is upstream
https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/esp32

esp-matter project - https://github.com/espressif/esp-matter

rs-matter - Rust - https://github.com/project-chip/rs-matter


Matter node
Matter Node - OnOff Cluster Client - 4 endpoints
Simplistic Representation of a Matter Data Model

https://blog.espressif.com/matter-clusters-attributes-commands-82b8ec1640a0
Cluster list
ID; Cluster Name 0x0050 - Mode Select

0x0003 - Identify 0x0508 - Low Power

0x0004 - Groups 0x0503 - Wake On LAN

0x0005 - Scenes 0x003b - Switch

0x0006 - On/Off

0x0008 - Level controlling


Specification: Matter Application Clusters v1.0
0x0045 - Boolean state
Matter - Client - Server
Device-to-device automation
Matter Bridge
Many chips, many boards - quick help
https://products.espressif.com/
IDE
Supported by Espressif:

- VS Code with Espressif Extension - great Rust support


https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/vscode-setup.html
- Espressif IDE - https://dl.espressif.com/dl/esp-idf/

Supported by JetBrains:

- CLion, Rust Rover - https://www.jetbrains.com/


- Wokwi Plugin - https://plugins.jetbrains.com/plugin/23826-wokwi-simulator

Supported by SysProgs

- Visual Studio with VisualGDB - https://visualgdb.com/

Supported by TARA Systems

- Embedded Wizard - https://www.embedded-wizard.de/


Open Hardware - ESP32-S3-BOX-3
https://github.com/espressif/esp-box

Joystick controller

https://github.com/espressif/esp-box/tree/master/exampl
es/esp_joystick/joystick_controller
News: Ferrocene compiler - the major milestone in 2023
Ferrocene is an open source qualified Rust compiler toolchain. Ferrous Systems invested its decade
of Rust experience to make Rust a first-class language for mission-critical and functional safety
systems.

For its first release, Ferrocene 23.06 is a ISO 26262 (ASIL D) and IEC 61508 (SIL 4) qualified version
of the existing open-source compiler, rustc, based on Rust 1.68.

https://ferrous-systems.com/ferrocene/
Why Ferrocene? https://www.youtube.com/live/i06djj0KvB8?si=mxXuuWPMpSs-JC2r
Rainmaker
Rust layer - Linux & ESP

https://github.com/shreyash-b/rainmaker-rs

Cloud connectivity
Time-O-Mat - built at summer camp
https://github.com/vedatori/Time-O-Mat
Grafana

https://grafana.com/blog/2020/06/17/how-to-monitor-a-sourdough-starter-with-grafana/

https://github.com/grafana/diy-iot - Arduino now. We’re not Rust yet :)


ESP Launchpad - https://espressif.github.io/esp-launchpad/
Quick start
esp-matter: https://github.com/espressif/esp-matter

Launchpad for flashing light and light_switch:

- https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-mat
ter/launchpad.toml
Async with Embassy
Embassy: https://github.com/embassy-rs/embassy

Examples of Embassy on ESP32:


- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_hello_world.rs
- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_spi.rs
- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_wait.rs

Async topic author: Juraj Sadel


Busy Looping (not using async)
- Very inefficient, blocking
Interrupts (not using async)
- Driven by hardware
- Pretty complex
Using async
- Don’t have to setting and waiting for interrupt resuming the program
- Async executor can do that for us instead
- Power efficient
Embassy (EMBedded ASYnc)
- We need an EXECUTOR to be able to use async
- Controlling which task should run

- Embassy consists of multiple crates (Executor, HALs, Networking,...)


- no_std
- Can be (relatively) easily extendable/configurable with other public crates
- https://embassy.dev
Multi-target project (PoC) - ESP32 Spooky Maze

https://github.com/georgik/esp32-spooky-maze-game

Idea: sharing business logic in Rust between


multiple targets

Targets: ESP32, ESP32-S2, ESP32-S3, ESP32-C3, M5Stack, Wasm and Desktop


Article:
https://georgik.rocks/rust-bare-metal-application-for-esp32-desktop-android-and-ios/

https://github.com/espressif/esp-box
Rust language support
Talk: Embedded Rust on ESP32 - Juraj Michálek - Rust Linz November 2022

https://youtu.be/0PPPdqoDBQs
IDEs with Rust support
Supported by Espressif:

- VS Code with Espressif Extension


https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/vscode-setup.html

Supported by JetBrains:

- RustRover - https://www.jetbrains.com/rust/
Rust component in C/C++ project
ESP-IDF has notion of components (libraries)

Integration of Rust as a component:

https://github.com/georgik/esp32-idf-no-std-rust-component

Example with NMEA crate

https://github.com/georgik/esp32-idf-nmea-example

idf.py set-target esp32-c3

idf.py -DCMAKE_BUILD_TYPE=Debug build

https://aerorust.org/
Debugging

2 steps:

- start simulator with debugger interface


- start debugging session
Debugging session with Wokwi
Templates for new projects
std

- leverage APIs of ESP-IDF


- pick exact version of ESP-IDF (not master branch)
- cargo generate --vcs none --git https://github.com/esp-rs/esp-idf-template cmake
- https://github.com/esp-rs/esp-idf-template

no_std

- no C dependencies
- https://github.com/esp-rs/esp-template
Starting from template
cargo generate esp-rs/esp-template

cargo build --release


cargo espflash flash --release --monitor
Rust Embedded Graphics

https://github.com/embedded-graphics

embedded-graphics crate + driver (e.g. for SPI display)


Wokwi - VS Code Plugin

Add wokwi.toml and diagram.json


to your project

CTRL+Shift+P - Wokwi: Start Simulator


Example: https://github.com/georgik/esp32-spooky-maze-game
Wire wrap
Quick, safe way how to connect pins and wires

Wire Wrapping for our Projects by Andreas Spiess:


https://youtu.be/L-463vchW0o?si=U96aLAwIsLpsPGTW

picture from Wikipedia: https://en.wikipedia.org/wiki/Wire_wrap


LVGL and Rust

https://github.com/lvgl/lv_binding_rust
Slint UI

https://slint.dev/

2 options:

- bare metal
- ESP-IDF component: https://components.espressif.com/components/slint/slint
Espressif and Matter
Support for ESP32 is upstream
https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/esp32

esp-matter project - https://github.com/espressif/esp-matter

rs-matter - Rust - https://github.com/project-chip/rs-matter


ESP32-C6
Main feature: WiFi 6 support - reduced power consumption

- https://www.youtube.com/watch?v=FA1jqZLig4s

Second important feature:

- Low Power Core - 20 MHz


Wokwi and
Low Power Core simulation
ESP32-C6

https://github.com/wokwi/esp32c6-i2c-lp
Pause button - see state of GPIOs
Wokwi F1 menu (download binary and many more)
Wokwi Logic Analyzer

Hit Stop to download VCD file for PulseView


Wokwi + PulseView - examples of I2C
Custom chips: Rust + e-Paper + ESP32
Simulate your own HW

Wokwi: Getting Started with the Wokwi Custom Chips C API

https://docs.wokwi.com/chips-api/getting-started
https://wokwi.com/projects/366167936725307393
Wokwi Profiler
https://profiler.wokwi.com/
Wokwi CI
https://github.com/wokwi/wokwi-ci-action
Rust STD Training Embedded for ESP32-C3

Material: https://esp-rs.github.io/std-training/

GitHub: https://github.com/esp-rs/espressif-trainings

Developed by Ferrous Systems, Espressif Systems and Community


Async with Embassy
Embassy: https://github.com/embassy-rs/embassy

Examples of Embassy on ESP32:

- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_hello_world.rs
- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_spi.rs
- https://github.com/esp-rs/esp-hal/blob/main/esp32-hal/examples/embassy_wait.rs
Accelerated learning with AI
Rust has steep learning curve

Refactoring is 10x harder

Very good results: Chat GPT 4, GitHub CoPilot

Less accurate results: Chat GPT 3.5, Bard


Other languages and frameworks in context of ESP32
New and noteworthy:

- Ada/Spark - from AdaCore


- Embedded Wizard - DSL and C
- Zig

VM based:

- CircuitPython and MicroPython - Python-like language


- DeviceScript - TypeScript language - Microsoft Research
- Lua
- Mongoose OS
- Nanoframework - C# language
- Toit
- downside: bigger VM
- upside: more robust, comes with OTA and monitoring
Qt for MCU
https://www.qt.io/product/develop-software-microcontrollers-mcu

Qt for MCU supports ESP32-S3

- students license - registration requires just email


Espressif Developer Conference 2023 - recording

Developer Conference 2023 - https://devcon.espressif.com/

https://youtu.be/mR3gUNXMEsM?si=7Rkq7wbClCvnM3pw
Rust language support
Talk: EDC23 - Rust Bare-metal and Async - Scott Mabin, Juraj Sadel - DevConf September 2023
https://youtu.be/QPp4WEjx5jU?si=zJwXPT8WxXOFq8oy

Talk: EDC22 - Rust on Espressif chips - Scott Mabin - DevConf September 2022
https://youtu.be/qeEmJ_-6fPg

Talk: Embedded Rust on ESP32 - Juraj Michálek - Rust Linz November 2022
https://youtu.be/0PPPdqoDBQs
Where you can find us?
https://makerfaire.cz/praha/
Přízova 3, 602 00 Brno
Embedded World 2024
Meet us in Nuremberg, Germany - 9th - 11th April 2024
Visit us in Brno
Espressif Systems (Czech) s.r.o.

Přízova 3, 602 00 Brno

Czechia, Europe

You might also like