This article is contributed by a netizen. The site owner doesn't know anything about hardware.
Author: Chen Xianda
Original Title: [Introduction to Microcontrollers] (Part 1) A Software Application Developer's Journey into Microcontrollers — Basic Knowledge Introduction
Original Link: https://www.cnblogs.com/1996-Chinese-Chen/p/16786374.html
Introduction
After working for five or six years, I've always focused on software, dabbling in various directions—mobile, PC, web. Then, during the month of the Xi'an lockdown last year, I suddenly realized that hardware also has a lot of fun to offer. Compared to software, tangible things are often easier to appreciate, and creating a finished product gives a greater sense of accomplishment. So during that time, I researched the Raspberry Pi, using Node and C# to control the Raspberry Pi and interact with sensors and other electronic components. If you're interested, you can check out my earlier article: C# Control Raspberry Pi Getting Started - Looking Around - Blog Garden. That article was just an introduction to the Raspberry Pi. In fact, there are commonalities with microcontroller introduction. Next, let's learn the basics of microcontrollers together.
What is a Microcontroller?
A microcontroller is a minimum computer operating system. According to Baidu Encyclopedia, it is an integrated circuit chip that uses ultra-large-scale integration technology to integrate a CPU with data processing capability, random access memory (RAM), read-only memory (ROM), various I/O ports, interrupt systems, timers/counters, and other functions (possibly including display driver circuits, pulse width modulation circuits, analog multiplexers, A/D converters, etc.) onto a single silicon chip, forming a small yet complete microcomputer system widely used in industrial control. From the 4-bit and 8-bit microcontrollers of the 1980s, they have evolved to today's 300M high-speed microcontrollers.
As you can see, a microcontroller can essentially be considered a small computer with storage, computation, input/output, timing, and other capabilities. Of course, our interaction with a complete computer also happens through I/O—using a mouse or keyboard connected to I/O ports for input and output. On ordinary microcontrollers, input/output is performed through the GPIO pins (the pins on the board for communication). The picture below shows an ESP32 microcontroller, which includes many I/O pins collectively called GPIO. What exactly is GPIO? The full name is General-Purpose Input/Output. This microcontroller has a total of 40 GPIO interfaces.
Microcontroller Interfaces
Classification by GPIO:
POWER: Power interface. The development board below has a 3.3V and a 5V power interface that can be used as input or output power to supply the microcontroller, or connected in series to power all electronic components in the entire project.
GND: Ground interface. POWER is the positive terminal; GND is the negative terminal or ground line in the circuit.
GPIO: These can be used as general-purpose input/output interfaces to interact with electronic components. For example, to light up an LED, you can set the GPIO output high or low to supply or cut off current—essentially a switch. We won't explain in detail here; later we will do experiments step by step to help you learn.
ADC: Analog-to-Digital Converter. It converts an input analog signal voltage into a digital value. It converts the input analog voltage or current into a digital representation of that voltage or current. You obtain sampled data and convert it into specific numbers. For example, temperature sensors, pressure sensors, etc., all work by converting the analog signal voltage into specific numbers.
CONTROL: Control pins. The microcontroller usually has an EN button used to reset it. If you connect a wire to this EN pin, you can control the reset of the microcontroller.
UART: A type of serial communication. Universal Asynchronous Receiver/Transmitter (UART). A set of UART has two pins: RX and TX. RX is used to receive data, and TX is used to transmit data. The full name of RX is Receiver, and TX is Transmitter. If we have a USB-to-TTL module, we can use a PC to communicate (send and receive data) with the microcontroller. One more thing: when doing serial communication, the RX pin must connect to the TX pin of the communicating party, and the TX pin to the RX pin. For example, if two microcontrollers A and B need UART serial communication, then A's RX must connect to B's TX, and A's TX must connect to B's RX. A receives data from B's TX, and A's transmission goes from A's TX to B's RX. Unless an electronic component has special modifications, the standard connection is RX to TX and TX to RX.
SPI: Serial Peripheral Interface. It is a high-speed, full-duplex, synchronous communication bus that uses only four wires on the chip:
- (1) MISO – Master Input Slave Output: Data input from master, data output from slave.
- (2) MOSI – Master Output Slave Input: Data output from master, data input from slave.
- (3) SCLK – Serial Clock: Clock signal generated by the master.
- (4) CS – Chip Select: Slave enable signal controlled by the master.
First, SPI has two more lines than UART. Also, SPI supports full-duplex communication with multiple devices, but it is a synchronous bus. Performance-wise, it may not surpass UART, but when connecting multiple devices, SPI offers more selectivity. A single SPI master can send data to multiple slaves via preassigned addresses, using the same SPI line to control several electronic components.
I2C: A multi-master/slave serial bus, also called I2C, invented by Philips. It is a half-duplex synchronous transmission bus. The I2C bus is a very common data bus that can achieve multi-device communication using only two wires: one SCL (clock line) and one bidirectional SDA (data line). The SDA line transmits data, and the SCL line controls data sending/receiving and acknowledgment.
TOUCH: The ESP32 board has ten different capacitive touch pads.
DAC: The reverse of ADC. ADC converts analog signals to digital; DAC converts digital signals to analog voltages.
FLASH: The ESP32 has various memory sizes, and you can also partition it. It seems there are 4MB, 8MB, and 16MB versions, used to store small files or temporary files.
PWM: Pulse Width Modulation. By inputting different waveforms, you can control the speed or modulation of electronic components. This is done by varying the duty cycle of the PWM high/low level.
Above is an explanation of all GPIO functions for the ESP32 series microcontrollers. In the future, I will guide you through interacting with different sensors to obtain data. The purchase link for the microcontroller is at the bottom. I've always bought from this shop—it's not an endorsement, just sharing.
【Phone Taobao】https://m.tb.cn/h.UdRqdqk?tk=MoLs2BOBtEQ CZ3457 「ESP32 Development Board WIFI+Bluetooth 2-in-1 Dual-Core ESP32 Core Board Wireless Bluetooth Development Board」
Microcontroller Conclusion
Actually, for microcontrollers, I think it's about using these GPIO pins to communicate with electronic components, using bus communication methods to send/receive data and messages. Essentially, it's controlling with high/low levels on different pins. In short, microcontroller development requires some basic circuit knowledge; otherwise, it's easy to burn the board or components. If you have money, you can do whatever you want, haha.
Environment Setup
Above, we explained what a microcontroller is and what each pin does. Next, let's go over how to set up the ESP32 development environment in Arduino. Click on "Preferences".

Here you can configure the project folder, the storage location for new projects, and the board settings. In the "Additional Boards Manager URLs" field, enter this URL: https://dl.espressif.com/dl/package_esp32_index.json to configure the ESP32 related development package. Then go to Tools -> Board -> Boards Manager, search for ESP32, and click install. However, you need a proxy to download; otherwise, it will be very slow. You can also download from GitHub and place the unzipped files into a manually created hardware folder under Arduino. The folder path structure must match what I show in the picture; otherwise, the environment configuration will fail and the board won't be recognized.
GitHub download link: https://github.com/espressif/arduino-esp32. After downloading, place the extracted files into the hardware/espressif/esp32 folder. Then run tools/get.exe. It will download the configuration environment; wait until it finishes, and you will find the ESP32 development board. The download speed might be very slow. I will upload all the necessary files, and after a small modification, you can use them.
Download link: http://121.43.235.192:8082/s/Be88gki4eSFSMFs





Conclusion
You can also use VS Code to develop. After configuring Arduino, install the Arduino extension in VS Code to use it. It's up to the developer. Additionally, VS Code development can use native C language directly.
Refer to the official step-by-step guide from Espressif: Get Started - ESP32 - ESP-IDF Programming Guide v4.4.2. This documentation is quite good. Using native C for development is more challenging than using Arduino. I started with this environment and later switched to Arduino, which is simpler and also allows you to search for libraries like NuGet in C#, with examples available. It's relatively easier.
In future articles, I'll play with some simple electronic components. This year, I built three smart cars and bought many electronic components. I'll take you through them one by one. If necessary, I'll also do live streams to make learning easier. Interested friends can continue to follow. If you have questions about the environment, feel free to join this group and ask me. This group is for microcontroller enthusiasts to learn and progress together. Currently, I'm working with ESP boards, but I'll also use 51 or STM series later. Interested parties can study together.
