博文

目前显示的是标签为“ESP32”的博文

What are the main languages used to program microprocessors?

图片
  Here’s a breakdown of the main languages, from the most common to the more specialized, along with the contexts in which they are used. 1. C: The Unquestioned King of Embedded Systems C  is the dominant, most widely used language for programming microprocessors and microcontrollers , especially for bare-metal and RTOS-based programming. Why it's used: Proximity to Hardware:  It allows for direct memory access through pointers and precise control over hardware registers, which is essential for configuring peripherals like timers, UART, and ADCs. Efficiency:  C compilers produce highly optimized machine code that is fast and has a small memory footprint—critical for resource-constrained devices. Portability:  While used for low-level programming, C is standardized and portable across different processor architectures (ARM, AVR, PIC, x86, etc.). The same code can often be recompiled for different targets. Maturity:  A vast ecosystem of compilers (GCC, Clang...

How does Arduino board communicate with Python?

图片
  Arduino and Python can communicate seamlessly , and this is one of the most popular ways to control hardware from a PC or log sensor data for analysis. Here’s the breakdown: 1. The Communication Channel Arduino boards usually communicate with a computer through a USB cable . That USB port is internally a serial (UART) interface , exposed as a COM port (Windows) or /dev/ttyUSB0 / /dev/ttyACM0 (Linux/Mac). So the key mechanism is serial communication . 2. Arduino Side On Arduino, you write a sketch that uses the built-in Serial library: void setup () { Serial. begin ( 9600 ); // Start serial at 9600 baud } void loop () { int sensorValue = analogRead (A0); Serial. println (sensorValue); // Send data to Python delay ( 100 ); } Serial.begin(9600) sets the baud rate. Serial.print() / Serial.println() sends data. Serial.read() / Serial.parseInt() can receive commands from Python. 3. Python Side On the Python side, you use...

How does a microcontroller serial port receive data of variable length?

图片
 A UART/serial port only gives you a stream of bytes—no built-in “message length.” To receive variable-length data you add a framing rule in software (and sometimes use hardware features to help). Here are the proven patterns and how to implement them on MCUs. The Four Common Framing Strategies Delimiter-terminated (e.g., newline \n ) Sender ends each message with a unique byte/sequence ( \n , \r\n , 0x00 , etc.). Receiver collects bytes until it sees the delimiter. Pros: simple; works with text protocols. Cons: delimiter cannot appear in payload unless you escape it. Length-prefixed (binary packets) Message starts with a header that includes LEN , then exactly LEN bytes of payload (often with a checksum/CRC). Pros: fast, no searching for delimiters, great for binary. Cons: you must trust the header (add CRC + bounds checks). Start/End markers with escaping (SLIP/COBS-style) Use a start (and/or end) byte (e.g., 0x7E ), and escape th...

How do I use GPIO pins?

图片
  Using   GPIO (General-Purpose Input/Output) pins   is fundamental in embedded systems and microcontroller projects. Below is a   step-by-step guide   on how to use them for both   input   and   output   operations, with examples for popular platforms like   Arduino , ESP32, and Raspberry Pi . 1. Understanding GPIO Basics GPIO pins  can be configured as: Digital Input  (read a button or sensor). Digital Output  (control an LED or relay). Analog Input  (read sensors like potentiometers, ADC required). PWM Output  (dim LEDs, control servo motors). Special Functions  (I2C, SPI, UART for communication). 2. Setting Up GPIO Pins A. Arduino (AVR/ARM) Digital Output (Control an LED) cpp void setup ( ) { pinMode ( 13 , OUTPUT ) ; // Set pin 13 as output } void loop ( ) { digitalWrite ( 13 , HIGH ) ; // Turn LED ON delay ( 1000 ) ; digitalWrite ( 13 , LOW ) ; // Turn LED OFF delay ( ...