飞道的博客

Arduino文档阅读笔记-WeMos D1 ESP8266 WIFI开发板入门

570人阅读  评论(0)

WeMos D1开发板以ESP8266WIFI开发板为基础,使用Arduino开发板的设计,工作电压为3.3V设计出来的开发板,这个开发板仅仅是使用了Arduino uno的布局设计,并不是Arduino的开发板。

下面是关于这块开发板的说明书:

总结下:

此开发板芯片为ESP8266(32位),缓存比Arduino Uno大,并且包含11个数字IO引脚以及1个模拟输入引脚,使用Micro-B type USB线进行连接。

下面是引脚方面的说明!

所有的引脚都需要跑到3.3V上,并且除了D0口其他口都支持interrupt/PWM/I2C/one-wire。

下面是在Arduino IDE中部署其开发环境

软件需要如下3个:

CH340G USB to UART driver: https://www.wemos.cc/downloads

Python 2.7: https://www.python.org/downloads/release/python-2713/

Arduino 1.8.2: https://www.arduino.cc/en/Main/Software

 

在Arduino的目录下新建2个文件夹esp8266com及esp8266

在Github上下载其库文件:

将压缩包放到esp8266目录下,然后解压:

将里面的文件移到到esp8266中,再将Arduino-master与Arduino-master.zip删掉。

最后变成这个样子即可!

打开CMD然后执行如下命名:

python get.py

此命令将会下载开发板所需要的工具,一切正常,且安装好将会是这样的。

这样就完成了安装!!!

 

使用Arduino IDE时要选中正确的开发板,Toos>Board中选择"WeMos D1 R2 & Mini"即可:

下面是几个示例代码:

Blink


  
  1. /*
  2. ESP8266 Blink by Simon Peter
  3. Blink the blue LED on the ESP-01 module
  4. This example code is in the public domain
  5. The blue LED on the ESP-01 module is connected to GPIO1
  6. (which is also the TXD pin; so we cannot use Serial.print() at the same time)
  7. Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
  8. */
  9. void setup() {
  10. pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
  11. }
  12. // the loop function runs over and over again forever
  13. void loop() {
  14. digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
  15. // but actually the LED is on; this is because
  16. // it is active low on the ESP-01)
  17. delay( 1000); // Wait for a second
  18. digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
  19. delay( 2000); // Wait for two seconds (to demonstrate the active low LED)
  20. }

查看下芯片的ID,这里串口打印频率要选择115200


  
  1. /* Get Chip ID
  2. * wemos.cc
  3. *
  4. *
  5. */
  6. void setup() {
  7. Serial.begin( 115200);
  8. }
  9. void loop() {
  10. Serial.println( "");
  11. Serial.println( "");
  12. Serial.println( "Check ID in:");
  13. Serial.println( "https://www.wemos.cc/verify_products");
  14. Serial. printf( "Chip ID = %08Xn", ESP.getChipId());
  15. Serial.println( "");
  16. Serial.println( "");
  17. delay( 5000);
  18. }

运行一个简单的Web Server


  
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <ESP8266WebServer.h>
  4. #include <ESP8266mDNS.h>
  5. const char* ssid = "........";
  6. const char* password = "........";
  7. ESP8266WebServer server(80);
  8. const int led = 13;
  9. void handleRoot() {
  10. digitalWrite(led, 1);
  11. server.send( 200, "text/plain", "Hello from esp8266!");
  12. digitalWrite(led, 0);
  13. }
  14. void handleNotFound(){
  15. digitalWrite(led, 1);
  16. String message = "File Not Foundnn";
  17. message += "URI: ";
  18. message += server.uri();
  19. message += "nMethod: ";
  20. message += (server.method() == HTTP_GET)? "GET": "POST";
  21. message += "nArguments: ";
  22. message += server.args();
  23. message += "n";
  24. for ( uint8_t i= 0; i<server.args(); i++){
  25. message += " " + server.argName(i) + ": " + server.arg(i) + "n";
  26. }
  27. server.send( 404, "text/plain", message);
  28. digitalWrite(led, 0);
  29. }
  30. void setup(void){
  31. pinMode(led, OUTPUT);
  32. digitalWrite(led, 0);
  33. Serial.begin( 115200);
  34. WiFi.begin(ssid, password);
  35. Serial.println( "");
  36. // Wait for connection
  37. while (WiFi.status() != WL_CONNECTED) {
  38. delay( 500);
  39. Serial.print( ".");
  40. }
  41. Serial.println( "");
  42. Serial.print( "Connected to ");
  43. Serial.println(ssid);
  44. Serial.print( "IP address: ");
  45. Serial.println(WiFi.localIP());
  46. if (MDNS.begin( "esp8266")) {
  47. Serial.println( "MDNS responder started");
  48. }
  49. server.on( "/", handleRoot);
  50. server.on( "/inline", [](){
  51. server.send( 200, "text/plain", "this works as well");
  52. });
  53. server.onNotFound(handleNotFound);
  54. server.begin();
  55. Serial.println( "HTTP server started");
  56. }
  57. void loop(void){
  58. server.handleClient();
  59. }

ssid填写wifi名,password填写wifi密码

 

 

 

 

 

 


转载:https://blog.csdn.net/qq78442761/article/details/105488875
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场