NodeMCU手把手入门:配置NodeMCU ESP8266开发板环境及点亮LED灯(持续更新)

之前一直在玩树莓派,最近实验室买了些NodeMCU就想着玩一玩,没想到挺有意思的。其实树莓派能实现的功能,它大部分也可以,价格比派也便宜不少,舍不得买派的同学可以先买这个开发板玩一玩。

本文主要介绍了一下如何配置NodeMCU的开发环境,开发环境只需配置一次。配置完成后,使用代码实现NodeMCU上自带LED的闪烁。过程很简单,初学者可以通过这几个简单步骤,先了解一下NodeMCU的基本操作。

本文主要包括以下三个模块:

一、NodeMCU介绍及所需设备

二、配置NodeMCU的开发环境

三、点亮NodeMCU上的LED灯

一、NodeMCU介绍及所需设备

(一)NodeMCU,是一个开源的物联网平台,包括固件和开发板,即运行在 esp8266Wi-Fi SoC芯片之上的固件,以及基于ESP-12模组的硬件。我们可以使用它来连接传感器以获取环境数据,并操作相应的执行设备(如水泵等)。它具有体积小,扩展性强的特点,在物联网应用领域迸发出了强大的能量。

(二)所需设备

NodeMCU ESP8266

USB-microUSB线

使用数据线将NodeMCU与电脑连接,插上后会自动下载驱动,并且可以在电脑的设备管理器中查看到。

注意:如果插上线没有反应,不一定是NodeMCU损坏,很有可能是因为你的数据线只能充电而不能传数据。请换一根数据线尝试。

二、配置NodeMCU的开发环境

1. 下载Arduino IDE

下载地址:https://www.arduino.cc/en/Main/Software,根据自己的电脑系统下载相应版本(Windows、Mac OS X和Linux)的IDE即可。

开源Arduino软件(IDE)主要是用来编写代码并上传到开发板,之前玩过Arduino的同学很容易上手NodeMCU。

2. 配置环境,打开Arduino IDE

(1)File(文件)-preferences(首选项)-Additional Boards Manager URLs(附加开发板管理器网址)-粘贴-OK(好)-OK(好)https://arduino.esp8266.com/stable/package_esp8266com_index.json

(2)Tools(工具)-开发板-开发板管理器-输入“ESP8266”-安装(因为我已经安装过了所以显示的是卸载)-关闭

(3)安装完成后,Tools(工具)-开发板-选择“Generic ESP8266 Module”-

(4)Tools(工具)-Port(端口)-COM9(即设备管理器显示的端口号,不同设备的NodeMCU端口号不同)

 

三、点亮NodeMCU上的LED灯

(1)新建文件,输入如下代码并上传。

/*
  ESP8266 Blink by Simon Peter
  Blink the blue LED on the ESP-01 module
  This example code is in the public domain

  The blue LED on the ESP-01 module is connected to GPIO1
  (which is also the TXD pin; so we cannot use Serial.print() at the same time)

  Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

(2)直接使用示例文件

File(文件)-Examples(示例)-ESP8266-Blink

打开后是给Arduino Uno提供的示例文件,但同样适用于NodeMCU。

点击上传即可。

注意:“Leaving... Hard resetting via RTS pin...”并不是报错,程序是正常运行,已经上传成功,意思是esptool会在上传后迅速重置重置esp8266。

如图为LED闪烁效果。

大功告成~

猜你喜欢

转载自www.cnblogs.com/hilary0614/p/esp8266.html