Lab 1: Introduction to Arduino and Microcontrollers
实验 1:Arduino 和微控制器简介
Objective
目的
To provide students with a foundational understanding of microcontrollers, introduce the Arduino platform, and familiarize them with its key components.
为了让学生对微控制器有基本的了解,请介绍 Arduino 平台,并让他们熟悉其关键组件。
Microcontrollers Overview
微控制器概述
A microcontroller is a compact integrated circuit (IC) that contains a processor core, memory, and programmable input/output peripherals. It is designed to be a self-contained computing system with the primary function of executing specific tasks within embedded systems.
微控制器是一种紧凑型集成电路 (IC),包含处理器内核、存储器和可编程输入/输出外设。它被设计成一个独立的计算系统,其主要功能是在嵌入式系统中执行特定任务。
Microcontrollers are commonly used in a wide range of electronic devices, providing a cost-effective and efficient solution for controlling various applications.
微控制器通常用于各种电子设备,为控制各种应用提供了一种经济高效的解决方案。
Microcontrollers are a specific type of electronic component, and they can be differentiated from other electronic components based on their functionalities and roles within a system. Here are key points of differentiation between microcontrollers and other electronic components:
微控制器是一种特定类型的电子元件,可以根据 它们在系统中的功能和作用与其他电子元件区分开来。以下是微控制器和其他电子元件之间的关键区别点:
Functionality: Microcontrollers are programmable devices that combine a processor, memory, and I/O peripherals on a single chip to control embedded systems. Other components like resistors, capacitors, transistors, and diodes serve passive or active roles in circuits but lack the computational and programmable abilities of microcontrollers.
功能 :微控制器是可编程器件,将处理器、存储器和 I/O 外设组合在单个芯片上 ,以控制嵌入式系统 。电阻器、电容器、晶体管和二极管等其他元件在电路中起着无源或有源的作用 ,但缺乏微控制器的计算和可编程能力。
Processing Power: Microcontrollers have a processing unit for executing instructions and running programs, providing computational power for embedded applications. In contrast, passive components (e.g., resistors, capacitors) and active components (e.g., transistors) focus on controlling or manipulating electrical signals, not general-purpose computation.
处理能力 :微控制器具有 用于执行指令和运行程序的处理单元 ,为嵌入式应用程序提供计算能力。相比之下,无源元件(例如电阻器、电容器)和有源元件(例如晶体管)专注于控制或纵电信号, 而不是通用计算。
Programmability: Microcontrollers are programmable, allowing developers to write software that defines their behavior. This programmability makes them versatile and adaptable to different applications. Most other electronic components are not programmable. They have fixed characteristics determined by their physical properties, and their functions are defined by their specifications within a circuit.
可编程性 :微控制器是可编程的,允许开发人员编写定义其行为的软件。这种可编程性使它们具有多功能性,并适用于不同的应用。大多数其他电子元件都不是可编程的。它们具有由其物理特性决定的固定特性,其功能由它们在电路中的规格决定。
Integration: Microcontrollers integrate multiple components into a single chip, including a processor, memory, and peripherals. This integration leads to a compact and self-contained computing system. Other electronic components typically serve specific functions within a circuit, and multiple components may be combined to create a complete circuit.
集成度:微控制器将多个组件集成到单个芯片中,包括处理器、内存和外设。这种集成导致了一个紧凑且独立的计算系统。其他电子元件通常在电路中服务于特定功能,多个元件可以组合起来形成一个完整的电路。
Application Focus: Microcontrollers are designed for embedded systems and automation, found in devices like sensors and communication modules. Passive components like resistors and capacitors shape electrical signals, while active components like transistors amplify or switch signals but lack microcontrollers' computational capabilities.
Application Focus 微控制器专为嵌入式系统和自动化而设计 ,可用于传感器和通信模块等设备 。电阻器和电容器等无源元件用于塑造电信号 ,而晶体管等有源元件用于放大或切换信号 ,但缺乏微控制器的计算能力。
Key Characteristics:
主要特点:
Processing Power: Microcontrollers are equipped with a processing unit (CPU) designed to execute instructions and perform computations. The processing power of a microcontroller is tailored to the specific tasks it needs to handle within embedded systems.
处理能力 :微控制器配备了一个处理单元 (CPU), 旨在执行指令和执行计算 。微控制器的处理能力是根据它在嵌入式系统中需要处理的特定任务量身定制的。
Memory: Microcontrollers have two primary types of memory:
内存 :微控制器有两种主要类型的内存:
Flash Memory: Used for storing the program code that the microcontroller executes
Flash Memory:用于存储微控制器执行的程序代码.
RAM (Random Access Memory): Used for temporary data storage and manipulation during program execution
RAM (Random Access Memory):用于程序执行期间的临时数据存储和作.
Input/Output (I/O) Capabilities: Microcontrollers feature configurable I/O pins that allow them to interact with the external environment. These I/O pins can be used for digital I/O, analog input, and communication with other devices.
输入/输出 (I/O) 功能微控制器具有可配置的 I/O 引脚,允许它们与外部环境交互。这些 I/O 引脚可用于数字 I/O、模拟输入以及与其他设备的通信。
Clock Source: Microcontrollers operate based on a clock signal, determining the speed at which they execute instructions. The clock source can be internal or external, influencing the overall performance of the microcontroller.
Clock Source:微控制器基于 clock 信号运行,确定它们执行指令的速度。clock source 可以是内部的,也可以是外部的,影响 microcontroller 的整体性能。
Peripherals: Microcontrollers come with built-in peripherals or modules, such as timers, communication interfaces (UART, SPI, I2C), analog-to-digital converters (ADC), and pulse-width modulation (PWM) controllers. These peripherals enhance the microcontroller's versatility in handling various tasks.
外设 :微控制器带有内置外设或模块,例如定时器通信接口(UART、SPI、I2C)、 模数转换器 (ADC) 和脉宽调制 (PWM) 控制器 。这些外设增强了微控制器在处理各种任务方面的多功能性。
Programmability: One of the defining features of microcontrollers is their programmability. Users can write and upload software to the microcontroller, defining its behavior and enabling it to perform specific functions. Programming is typically done using high-level languages like C.
可编程性 :微控制器的决定性特征之一是其可编程性。用户可以编写软件并将其上传到微控制器,定义其行为并使其能够执行特定功能。编程通常使用 C 等高级语言完成。
Integrated Development Environment (IDE): Microcontrollers are programmed using specialized development environments, such as the Arduino IDE or platform-specific tools. These environments provide a user-friendly interface for writing, compiling, and uploading code to the microcontroller.
集成开发环境 (IDE): 微控制器使用专门的开发环境进行编程,例如 Arduino IDE 或特定于平台的工具。这些环境为编写、编译代码和将代码上传到微控制器提供了一个用户友好的界面。
Introduction to the Arduino Platform
Arduino 平台简介
The Arduino platform originated as an open-source project with the goal of creating an accessible and user-friendly platform for artists, designers, hobbyists, and anyone interested in creating interactive electronic projects.
Arduino 平台最初是一个开源项目 , 旨在为艺术家、设计师、业余爱好者和任何对创建交互式电子项目感兴趣的人创建一个可访问且用户友好的平台。
Arduino was co-founded in the early 2000s by Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis at the Interaction Design Institute Ivrea in Italy. It was created to provide an affordable, user-friendly tool for artists and designers to prototype interactive projects, even without extensive electronics or programming knowledge.
Arduino 由 Massimo Banzi、David Cuartielles、Tom Igoe、Gianluca Martino 和 David Mellis 于 2000 年代初在意大利 Ivrea 交互设计研究所共同创立。它的创建旨在为艺术家和设计师提供一种经济实惠、用户友好的工具 ,即使没有广泛的电子或编程知识 ,也可以制作交互式项目的原型 。
The first Arduino board, Arduino Uno, was introduced in 2005. It featured the Atmel ATmega8 microcontroller and an easy-to-use programming environment.
第一款 Arduino 板 Arduino Uno 于 2005 年推出 。它采用 Atmel ATmega8 微控制器和易于使用的编程环境。
A significant aspect of Arduino's success is its commitment to open-source hardware and software. This philosophy allows users to freely access, modify, and distribute the design files, firmware, and software associated with Arduino boards.
Arduino 成功的一个重要方面是其对开源硬件和软件的承诺。这一理念允许用户自由访问、修改和分发与 Arduino 板相关的设计文件、固件和软件。
Arduino's advantages include beginner accessibility, strong community support, open-source design, and a wide range of available shields and modules, making it popular for diverse applications.
Arduino 的优势包括初学者可访问性 、 强大的社区支持 、 开源设计以及广泛的可用扩展板和模块,使其在各种应用中广受欢迎。
Arduino Board Components
Arduino 板组件
Arduino boards consist of several key components that play essential roles in the functionality and operation of the microcontroller platform.
Arduino 板由几个关键组件组成,这些组件在微控制器平台的功能和作中起着至关重要的作用。
Below is an overview of the typical components on an Arduino board:
以下是 Arduino 板上的典型组件概述:
1. Microcontroller Chip: Typically, the microcontroller chip is located at the center of the Arduino board. The microcontroller is the brain of the Arduino, responsible for executing the program instructions and controlling I/O operations. Common microcontroller chips used in Arduino boards include the Atmel ATmega series.
1. 微控制器芯片: 通常,微控制器芯片位于 Arduino 板的中心。微控制器是 Arduino 的大脑,负责执行程序指令和控制 I/O 作。Arduino 板中常用的微控制器芯片包括 Atmel ATmega 系列。
2. USB Port: A USB port is usually located on the edge of the Arduino board. The USB port serves multiple purposes. It allows for the connection of the Arduino board to a computer for programming (uploading sketches), and it provides a means for the board to communicate with other USB devices.
2. USB 端口:USB 端口通常位于 Arduino 板的边缘。USB 端口有多种用途。它允许将 Arduino 板连接到计算机进行编程(上传草图),并为板子提供与其他 USB 设备通信的方法。
3. Power Connector: The power connector may vary between Arduino models. It could be a barrel jack, a USB Type-C connector, or other power input options. The power connector is where external power is supplied to the Arduino board. It allows the board to be powered from an external power source, such as a battery or a wall adapter.
3. 电源连接器: 电源连接器可能因 Arduino 型号而异。它可以是桶形插孔、USB Type-C 连接器或其他电源输入选项。电源连接器是为 Arduino 板提供外部电源的地方。它允许板由外部电源供电,例如电池或壁式适配器。
4. Reset Button: A small button labeled "RESET" on the Arduino board. The reset button is used to manually reset the microcontroller. Pressing the reset button restarts the program execution from the beginning. This is helpful when re-uploading code or troubleshooting certain issues.
4. 重置按钮:Arduino 板上标有“RESET”的小按钮。reset 按钮用于手动重置微控制器。按下 reset 按钮将从头开始重新启动程序执行。这在重新上传代码或排查某些问题时非常有用。
5. LEDs: Typically, there are one or more LEDs on the Arduino board.
5. LED: 通常,Arduino 板上有一个或多个 LED。
6. Voltage Regulator: A small component near the power input, often labeled with the voltage specifications. The voltage regulator ensures that the voltage supplied to the microcontroller remains within the acceptable range. It regulates the voltage coming from the external power source to a level suitable for the microcontroller.
6. 稳压器: 靠近电源输入的一个小元件,通常标有电压规格。稳压器确保提供给微控制器的电压保持在可接受的范围内。它将 来自外部电源的电压调节到适合微控制器的水平 。
7. Crystal Oscillator: Two small crystals (quartz resonators) near the microcontroller. The crystal oscillator provides a stable clock signal for the microcontroller, allowing it to execute instructions with precise timing.
7. 晶体振荡器: 微控制器附近的两个小晶体(石英谐振器)。晶体振荡器为微控制器提供稳定的时钟信号,使其能够以精确的时序执行指令。
8. Analog and Digital Pins: Arrays of pins along the edges of the Arduino board, usually labeled with numbers and functionalities. Digital pins are used for digital input or output (binary values: HIGH or LOW). Analog pins are used for analog input, allowing the measurement of voltage levels.
8. 模拟和数字引脚: 沿着 Arduino 板边缘的引脚阵列,通常标有数字和功能。数字引脚用于数字输入或输出(二进制值:HIGH 或 LOW)。模拟引脚用于模拟输入,允许测量电压电平。
9. ICSP Header (In-Circuit Serial Programming): A set of six pins arranged in a row. The ICSP header allows for programming the microcontroller in-circuit using a dedicated programmer. This is an alternative programming method to using the USB port.
9. ICSP Header (In-Circuit Serial Programming): 一组排成一行的六个引脚。ICSP 接头允许使用专用编程器对微控制器进行在线编程。这是使用 USB 端口的另一种编程方法。
10. Power Rails: Typically labeled "5V," "3.3V," "GND," and "VIN." These power rails provide fixed voltage outputs (5V, 3.3V) and ground connections. VIN is the voltage input and may be used to read the voltage of the external power source.
10. 电源轨: 通常标记为“5V”、“3.3V”、“GND”和“VIN”。这些电源轨提供固定电压输出(5V、3.3V)和接地连接。VIN 是电压输入,可用于读取外部电源的电压。
Assignment 1
作业 1
Examine the Arduino board and identify its key components. Discuss the function of each component on the board, and highlight the importance of handling electronic parts with care.
检查 Arduino 板并确定其关键组件。讨论板上每个组件的功能,并强调小心处理电子零件的重要性。
Assignment 2
作业 2
Connect the Arduino board to the PC/laptop using USB.
使用 USB 将 Arduino 板连接到 PC/笔记本电脑。
Check whether the Arduino board is identified on your PC/Laptop; you must see something like this (port should be identified):
检查您的 PC/笔记本电脑上是否识别了 Arduino 板;您必须看到如下内容(应标识端口):
Assignment 3
作业 3
Build a simple LED blink circuit using the following components: 3 resistors (22Ω), 3 LEDs, electrical wires, a breadboard, and an Arduino UNO.
使用以下组件构建一个简单的 LED 闪烁电路:3 个电阻器 (22Ω)、3 个 LED、电线、一个面包板和一个 Arduino UNO。
Begin by connecting one LED, with its anode attached to the left side of the breadboard and its cathode to the right side, as illustrated below:
首先连接一个 LED,其阳极连接到试验板的左侧,阴极连接到右侧,如下图所示:
Next, connect a 220-ohm resistor to the LED, with the other end of the resistor connected to the positive or negative side of the breadboard, as shown below:
接下来,将一个 220 欧姆的电阻器连接到 LED,电阻器的另一端连接到试验板的正极或负极,如下所示:
Repeat the same connections for the remaining two LEDs, as illustrated below:
对其余两个 LED 重复相同的连接,如下所示:
Next, connect the anode of the yellow LED to pin 10 on the Arduino Uno board using a jumper wire, as shown below:
接下来,使用跳线将黄色 LED 的阳极连接到 Arduino Uno 开发板上的引脚 10,如下所示:
Afterward, connect the other two LEDs to pins 11 and 12 on the Arduino Uno using jumper wires, as shown below:
然后,使用跳线将另外两个 LED 连接到 Arduino Uno 上的引脚 11 和 12,如下所示:
Next, connect the GND pin of the Arduino Uno board to the negative side of the breadboard, as shown below:
接下来,将 Arduino Uno 板的 GND 引脚连接到面包板的负极,如下所示:
This completes the circuit setup. The next step is programming using the Arduino IDE, which we will cover in detail in the next lab. The following code is designed to perform the task:
这样就完成了电路设置。下一步是使用 Arduino IDE 进行编程,我们将在下一个实验中详细介绍。以下代码旨在执行该任务:
Verify the code by clicking the verify button in the Arduino IDE.
单击 Arduino IDE 中的 verify 按钮验证代码。
Next, connect the Arduino Uno board to the computer using a USB cable, as shown below:
接下来,使用 USB 数据线将 Arduino Uno 板连接到计算机,如下所示:
In the Arduino IDE, navigate to the Tools menu to ensure that the correct Arduino Uno board and the appropriate port for the PC connection are selected, as shown below:
在 Arduino IDE 中,导航到 Tools 菜单,以确保选择了正确的 Arduino Uno 板和 PC 连接的适当端口,如下所示:
Next, click the upload button in the Arduino IDE to run the code. The result will appear as follows:
接下来,单击 Arduino IDE 中的上传按钮以运行代码。结果将如下所示:
Assignment 4
作业 4
• Build the following circuit: Connect the anode of the LED to a resistor, and then connect the resistor to pin 7 on the Arduino Uno board. Connect the cathode of the LED to the GND pin.
• 搭建以下电路:将 LED 的阳极连接到电阻器上,然后将电阻器连接到 Arduino Uno 板上的引脚 7。将 LED 的阴极连接到 GND 引脚。
• Write the corresponding code in the Arduino IDE and observe the result.
• 在 Arduino IDE 中编写相应的代码并观察结果。