软件复位 ESP8266

This tutorial shows hot to software reset ESP8266 in Arduino IDE. This sketch/example shows software reset using simple command ESP.restart() or ESP.reset().

Software reset for ESP8266 is required when you get trouble to connect WiFi router.

Lets see the use of software restart. This example program will show you software reset in a loop before it reaches to its max value.

ESP.reset() is a hard reset and can leave some of the registers in the old state which can lead to problems, its more or less like the reset button on the PC.

ESP.restart() tells the SDK to reboot, so its a more clean reboot.

/*
 * circuits4you.com
 * ESP8266 software reset demo
 * This program counts from 1 to 20
 * and resets at 6 count before completing counting
*/
#include <ESP8266WiFi.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);
  pinMode(2, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  int i;
  
  for(i=0;i<20;i++)
  {
    digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);                       // wait for a second
    digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
    delay(500);                       // wait for a second
    Serial.print("count");
    Serial.println(i);

    if(i==6)
    {
      Serial.println("Resetting ESP");
      ESP.restart(); //ESP.reset();
    }
  }
}

 Upload above program. after uploading open serial monitor you will find below reset

 ESP software reset results

You will notice that it resets the ESP but wont start the program again. this is small but it is caused after only serial upload.

the boot mode:(1,7) problem is known and only happens at the first restart after serial flashing. if you do one manual reboot by power or RST pin all will work.

ESP8266 Software Reset Working after manual reset

After manual reset the program will work fine as expected.

 

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值