简介:三种方式手动重启Arduino
- Arduino板上重新编写代码时,Arduino将重新设置
- Arduino软件中打开串行终端,同时将Arduino板连接到计算机。打开串行终端时,Arduino会自动重置
- 按下复位按钮
详情见:
https://www.theengineeringprojects.com/2015/10/upload-bootloader-atmega328.html
方法一:使用Arduino板上的RESET引脚
以编程方式重新设置Arduino,就是利用一个数字口,代码运行到那的时候就将REST置低
这里利用数字口D2
int Reset = 2;
void setup() {
digitalWrite(Reset, HIGH);
delay(200);
pinMode(Reset, OUTPUT);
Serial.begin(9600);
Serial.println("How to Reset Arduino Programmatically");
delay(200);
}
void loop()
{
Serial.println("A");
delay(1000);
Serial.println("B");
delay(1000);
Serial.println("Now we are Resetting Arduino Programmatically");
Serial.println();
delay(1000);
digitalWrite(Reset, LOW);
Serial.println("Arduino will never reach there.");
}
方法2.不使用任何硬件引脚
Arduino有一个名为resetFunc()的内置函数,我们声明函数地址为0,当我们执行此功能时,Arduino将自动重置。
说明:
- In this method, we are not gonna use any hardware pin, instead we will do everything in programming.
- Arduino has a builtin function named as resetFunc() which we need to declare at address 0 and when we execute this function Arduino gets reset automatically.
- So, no need of doing anything in hardware and simply upload the below code in your Arduino board.
void(* resetFunc) (void) = 0;
void setup() {
Serial.begin(9600);
Serial.println("How to Reset Arduino Programmatically");
delay(200);
}
void loop()
{
Serial.println("A");
delay(1000);
Serial.println("B");
delay(1000);
Serial.println("Now we are Resetting Arduino Programmatically");
Serial.println();
delay(1000);
resetFunc();
Serial.println("Arrduino will never reach there.");
}
原文链接:https://blog.csdn.net/y511374875/article/details/77845240
方法3. 设置外部复位按钮
如果您无法访问Arduino板的重置按钮,或者板顶部放置了障碍物,则需要设置外部重置按钮。您只需要一个面包板、一个按钮和一对跳线以及您的 Arduino 板。
根据数据表,向RESET引脚施加至少2微秒的低电压将重置Arduino UNO,这意味着您需要使用按钮向RESET引脚施加低电压。
为此,您需要将按钮连接在常开状态下,一侧连接到RESET引脚,另一侧连接到GND。在其正常位置,RESET引脚将处于高电平,但是一旦按下按钮,它将连接到GND引脚,因此将处于低逻辑电平。
该技术将重置Arduino,而无需将任何代码上传到开发板。访问此网站以获取有关为 Arduino 板设置外部重置按钮的更详细指南。
---------------------
作者:蔚蓝慕
来源:CSDN
原文:https://blog.csdn.net/acktomas/article/details/102776270
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件