Arduino UNO R3开发板入门教程:从硬件到Hello World程序
Arduino UNO R3开发板入门教程:从硬件到Hello World程序
本文是一篇关于Arduino UNO R3开发板的学习笔记,内容涵盖了开发板的概述、重要引脚介绍、开发环境配置、编程环境介绍以及实操步骤。文章结构清晰,从基础概念到实际操作都有详细的讲解,适合初学者学习使用。
Arduino UNO R3开发板学习
开发板概述
Arduino UNO 是一款基于Atmega328P 的微控制器开发板。它有 14 个数字输入/输出引脚(其中6个可用作PWM 输出),6个模拟输入,16MHz晶振时钟,USB 连接,电源插孔,ICSP接头和复位按钮。只需要通过USB数据线连接电脑就能供电、程序下载和数据通讯。
本次测试采用的是uno r3创客改进版,颜色板子为深蓝色,升级版芯片328P,刻字清晰,兼容性强功能强大性能稳定做工精致。
主要功能简介:
开发板实拍照片:
主控芯片实拍:
重要引脚介绍
供电引脚:开发板可提供3.3V和5V电压输出,Vin 引脚可用于从外部电源为开发板供电。
模拟输入引脚:开发板可读取外部模拟信号,A0A5为模拟输入引脚。数字引脚:UNOR3拥有14个数字输入输出引脚,其中6个可用于PWM(脉宽调制)输出(数字 3,5,6,9,10,11)。数字引脚用于读取逻辑值(0或1),或者作为数字输出引脚来驱动外部模块。标有“”的引脚可产生PWM。
TX和RX引脚:标有TX(发送)和RX(接收)的两个引脚用于串口通讯。其中标有TX和RX 的LED灯来连接相应引脚,在串口通讯时会以不同速度闪烁。13号引脚:开发板标记第13引脚,连接板载LED灯,可通过控制13 引脚来控制LED 灯亮灭。上传测试程序,板载灯都会闪烁,可辅助检测开发板是否正常。
在传程序之前,需要确保电脑安装有CH340串口驱动。
配置开发环境
安装 Arduino IDE
1.登陆Arduino官方网站软件
下载页
编程环境介绍
Arduino 介绍
使用ArduinoDE编程的时候,简单常用的传感器需要用到的库都已经在安装软件的时候安装到ArduinoDE软件的库中,不需要再重复加载相关的库文件,只有一些被特殊处理的传感器或模块需要将其对应的库加载到ArduinoIDE软件的库中,当然,也可以不加载,只是在编程的时候将这些库放在相应的工程文件夹下即可。
实操
照例编写hello world程序,测试板子功能。
连接
Arduino UNO 板上有一个USB 串口,所以第一个程序不需要连接其他设备,只需要Arduino UNO 直接连接 PC 和 USB 线。
选择程序
打开arduino ide,新建项目,选择对应的开发板。原生库里有对应的板子,直接选择即可,如下图:
程序代码
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); //通讯端口频率115200
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello World");
delay(1000);
}
编译和执行
点击屏幕左上角的对号,开始预编译,完成会显示内存占用等相关信息,如:
Global variables use 200 bytes (9%) of dynamic memory, leaving 1848 bytes for local variables. Maximum is 2048 bytes.
没有错误提示,点击右箭头,开始编译烧写:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\86131\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : COM26
Using Programmer : arduino
Overriding Baud Rate : 115200
AVR Part : ATmega328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino
Hardware Version: 3
Firmware Version: 4.4
Vtarget : 0.3 V
Varef : 0.3 V
Oscillator : 28.800 kHz
SCK period : 3.3 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\86131\AppData\Local\arduino\sketches\B356D101F2F440F41808DCDA2B21AF2D/hello.ino.hex"
avrdude: writing flash (1634 bytes):
Writing | ################################################## | 100% 0.25s
avrdude: 1634 bytes of flash written
avrdude done. Thank you.
正常烧写无错误提示,可以打开串口监视器观察实验效果。这里选用LLCOM串口工具,选择开发板所在的COM口,频率115200,得到了输出:hello world
也可以用IDE自带的串口工具:
串口工具显示:
总结
1.了解arduino uno板的基本组成;
2.编译和执行的基本流程;
3.hello world点亮开发板。
课后练习
修改代码关键信息,尝试不同的执行效果。