4. Program for Embedded Machines¶
This week I learned about the basic components of PCBs (printed circuit boards) and microcontrollers. 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 onto a PCB.
Assignments for this week (Feb 12-Feb 18):
Group assignment:
1. Demonstrate and compare the toolchains and development workflows for available embedded architectures
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:¶
Our goals for this week to demonstrate and compare the toolchains and development workflows for available embedded architectures.
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 not only provides an intuitive programming environment, but it offers a huge range of libraries, and facilitates compiling and uploading of the codes (sketches) onto the board.
- I would have like to compare the Arduino IDE with other development environments, such as Thonny, CircuitPython, to get some perspective.
- I learnt that ideally I should learn to code and compile my own code as it would enable me to use resources (especially energy) 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.
What are the main specifications of Microcontrollers?
[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 Deep sleep mode, which are low-power states when not actively processing tasks
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 devices, such as microcontrollers, PCBs, etc. It contains critical information for choosing the right device and for making best use of its capabilities.
Before deciding on which devices’ datasheets to browse through, I gave more thought to my final project requirements so that I can narrow down on several options.
My requirements:
- Wi-Fi capability
- Microphone (although unsure whether to embed it in my board or make use of a separate 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
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.
After comparing these different options, I came up with further questions to hopefully 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 the ESP32-C6 microcontroller to execute LED blinking and Serial communication.
1. Study the datasheet¶
First, I looked at the pin-out diagram for my ESP32-C6 board on Wokwi, in order to figure out the pin numbers needed for programming.
2. Create the circuit¶
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¶
During the local session, Rico-san gave us a brief overview of coding for microcontrollers. Since I am totally new to coding, this was a really helpful introduction.
For this part of individual assignment, I started by transcribing my instructor Nagano-san’s code. Tsuchiya san calls this “写経 (copying of sutras)” and recommends not simply copying and pasting, but rewriting the codes letter by letter in order to really understand the content.
I then tried adding an “if else” code based on Wokwi’s example code.
I wasn’t able to test it within the week because of overwhelming demand from FabAcademy, but I was later able to get it to blink.
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
- Blog about Multiplexer
- Seeed Studio XIAO ESP32C3のI/O割り付けに注意
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, one for operating the rack, and one for interfacing with the user via a Smart speaker.
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
- [x] Programmed my simulated board to interact and communicate
- [x] Described the programming process(es) I used
- [x] Included my source code
- [ ] Included ‘hero shot(s)’