4. Embedded Programming¶
This week I learned the basic components of microcontrollers and PCBs (printed circuit boards). I learnt how to identify relevant information on a datasheet, which would eventually enable me to choose the right microcontroller for my final project. I also learnt the basics of programming a microcontroller on a PCB (Printed Circuit Board).
Assignments for this week (Feb 12-Feb 18):¶
Group assignment:
1. Demonstrate and compare the toolchains and development workflows for available embedded architectures
2. Document work
Individual assignment:
1. Browse through the datasheet to choose my microcontroller
2. Write a program for a microcontroller, and simulate its operation to interact and communicate
Group Assignment¶
This week’s Group assignment was to demonstrate and compare the toolchains and development workflows for available embedded architectures.
Before the groupwork, I gave more thought to my final project requirements so that I can narrow down which microcontrollers to try.
Requirements:
- Wi-Fi capability
- Microphone (although unsure whether to embed it in my board or use external smart speaker)
- AI speech recognition (also unsure how best to achieve this)
- Long battery life / efficient power consumption
- Easy to sync with Google docs (via API?)
- As low cost as possible
Link to Group Assignment documentation page
My learnings from groupwork:¶
What did I learn from comparing different boards?
- As a beginner in programming I appreciated the user-friendliness of Arduino IDE; it was easier than I feared! Would have liked to try some other development environments as well, for some perspective, such as Thonny, CircuitPython.
- I learnt that ideally I should learn to code and compile my own code as it would enable me to use resources more efficiently.
What is an embedded system?
It is simply defined as any computing system contained within a product that is not described as a computer.Embedded system is designed to perform a specific task and cannot be used like a general computer to run other different computing tasks by other programs.
About microcontroller specs
[Processing power related specs]- Architecture: Harvard (RISC) or Von Neumann (CISC)
- Clock speed/Operating frequency (MHz): How fast the processor can execute instructions within a given time. Also affects power consumption.
- Bus width (bits): Governs the microcontroller’s speed and mathematical precision. 8-bit is basic, while 16-bit and 32-bit typically offer more performance.
[Memory capacity]
- RAM: Data memory (holds variables and data that the microcontroller uses during operation)
- FLASH: Program memory (holds code that the microcontroller executes)
[Other specs]
- I/O Ports: Reads data in from pins and sends signals out from pins.
- Power Requirement (VCC/VDD/AREF/5V,etc): Represents the power supply voltage for the circuit/chip. It can be 3.3V, 5V, or 12V, depending on the device or circuit. If you use a power supply with a voltage that is significantly higher than what a device is designed for, it can cause the device to break or malfunction due to "overvoltage," potentially damaging internal components like transistors, capacitors, or even causing the device to burn out completely.
- Power management options - Some microcontrollers offer capability to operate in low-power states when not actively processing tasks (deep sleep mode)
Reference: intechhhouse, cui.com
Common processor families
- PIC- AVR (ATTiny, ATMega, etc)
- Arm (STM, Raspberry Pi, etc)
- Xtensa /MIPS (ESP)
- RISC-V
...etc
Personal Assignment¶
Browse through datasheet¶
The datasheet outlines the internal architecture of the chip. It contains critical information for choosing the right chip and for making best use of the chips’ capabilities.
Since I felt like I would learn more from starting with comparing a few rather than just one, I selected a few wi-fi compatible chips.
Note: For the RP2040, I looked at the wi-fi enabled SoC offered by Seeed.
Microcontroller | RP2040 (Seeed Wio) | ESP32 | STM32WL |
---|---|---|---|
MPU | 32 bit ARM Cortex-M0+ | 32 bit Xtensa LX6 | 32 bit Arm Cortex-M |
Processing Power | 133MHz Dual core | 160/240MHz Dual core | ~48MHz dual core |
Memory (ROM/SRAM/Flash) | 512kB/264kB/2MB | 448kB/520kB/16MB | 640kB/64-256kB Flash |
GPIO | 28 | 34 | ~72 |
DAC | - | 2ch x 8bit | 1ch x 6 bit |
Touch sensors | - | 10 | - |
Wi-Fi | 2.4GHz | 2.4GHz | LoRA WAN (~148dBm), amazon sidewalk, etc |
Bluetooth | - | 4.2 | - |
Language | C/C++, MicroPython, Lua, Arduino, Thonny | Arduino, C/C++/C#, Python(MicroPython), JavaScript, Lua, mRuby, Lisp | C, Python, STM32CubeIDE |
Price (approx,JPY) | 1,600 | 500 | 1,600 |
Thoughts:
ESP32 is the clear winner here in terms of performance, and I am also biased towards its Arduino compatibility.
However I cannot judge how much performance is enough/too much for my project, and I also want to be considerate of power consumption / battery life, and price.
I decided to look further into different models under the ESP32 family. I also added a Xiao SoC for comparison.
Model | ESP32 | ESP32S3 | ESP32C3 | ESP32C6 | Xiao ESP32C6 |
---|---|---|---|---|---|
Processor | 32-bit Xtensa Lx6 dual core | 32-bit Xtensa LX7 dual core | 32 bit RISC-V single core | 32-bit RISC-V single-core | Same as left |
Clock speed | 240MHz | 240MHz | 160Mhz | 160Mhz | Same as left |
Memory (ROM/SRAM/Flash) | 448kB/520kB/16MB | 384kB/512kB/8MB | 384kB/400kB/external flash | 320kB/512kB/external flash | 512kB/512kB/4MB |
GPIO | 34 | 45 | 16 or 16 | 22 or 30 | 11 |
Analog input | 18 channels | 20 | 6 | 7 | 3 |
Analog output | 2 channels | 2 | - | - | - |
DAC | 2ch x 8bit | 2ch x 8bit | - | - | unknown |
Touch sensors | 10 | 14 | - | - | unknown |
Other | 4 SPI/2 I2S/2 I2C/3 UART | 2 SPI /2 I2S/2 I2C/3 UART | 3 SPI/I2S/I2C/2 UART | 1 SPI/I2S/I2C/2 UART | 1 SPI/I2S/I2C/UART |
PWM | Motor PWM, LED ~16 channels | Motor, LED ~8 channels | Motor, LED ~6 channels | Motor, LED ~6 channels | same |
Power cons. in deep sleep | 10µA | 7µA | 5µA | 7µA | 15µA |
Wi-fi | 2.4GHz Wi-Fi4 | 2.4GHz Wi-fi4 | 2.4GHz Wi-fi4 | 2.4GHz Wi-fi5 | 2.4GHz Wi-fi5, and Zigbee,Thread,IEEE 802.15.4 |
Bluetooth | 4.2 | 5.0 | 5.0 | 5.3 | 5.3 |
Approx Price (JPY) | 1,400 | 1,400 | 787 |
ESP32-C6 seems to have a good balance of low-power consumption and performance.
In order to evaluate the right chip for my project, here are some of the questions I’d like to answer in the coming few weeks;
- What range of CPU/memory is required for smooth voice recording and speech keyword recognition?
- How would a low power consumption of 15µA translate to battery life?
- What are the differences between different connectivity such as Bluetooth 4 and 5, wi-fi 4 and 5?
…etc etc.
Hopefully I will have more clarity in a few weeks!
Programming the ESP32-C6¶
I used Wokwi to simulate ESP32-C6’s LED blinking operation and Serial communication.
1. Study the datasheet¶
I found the pin-out diagram for my ESP32-C6 board on Wokwi, in order to figure out the pin numbers.
2. Prepare the board¶
I thought of a scenario for the user to select Blue light or Red light (like Neo in Matrix😎), and wired the board.
3. Coding¶
This is the code I initially wrote, based on my instructor Nagano-san’s code;
I also tried adding an “if else” code based on Wokwi’s example code.
But I wasn’t able to test it due to server error:(
4. Debugging¶
Not able to debug yet due to server error
Useful links:¶
- How to set up Wi-fi for Xiao ESP-32C3
- How to create a 2 Dollar smart speaker using ESP32 Clova
- Fablab Kochi documentation of Python simulation 1.
- Fablab Kochi documentation of Python simulation 2.
- Wokwi VS Code extention
- Class notes
Reflections:¶
This week I learnt about the key specifications of micro-controllers. I also learnt to write a basic program for a microcontroller, and simulate its operation using Wokwi.
The assignments also helped me crystallise my final project design in terms of chip requirements. At this moment, I am thinking of having 2 main interfaces with separate chips
In the coming weeks, I would like to draw out more specific design requirements for the spice bottle holder and microphone interface, the main one being, “What kind of input sensor would enable me to recognise bottle placement???”.
Hopefully I will find the answer during the “input device” week!
Assignment Checklist:¶
- [x] Linked to the group assignment page
- [x] Browsed and documented some information from my microcontroller’s datasheet
- [] Programmed my simulated board to interact and communicate
- [] Described the programming process(es) I used
- [x] Included my source code
- [ ] Included ‘hero shot(s)’