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
/*
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)
}
查看下芯片的ID,這裏串口打印頻率要選擇115200
/* Get Chip ID
* wemos.cc
*
*
*/
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("");
Serial.println("");
Serial.println("Check ID in:");
Serial.println("https://www.wemos.cc/verify_products");
Serial.printf("Chip ID = %08Xn", ESP.getChipId());
Serial.println("");
Serial.println("");
delay(5000);
}
運行一個簡單的Web Server
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "........";
const char* password = "........";
ESP8266WebServer server(80);
const int led = 13;
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "Hello from esp8266!");
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Foundnn";
message += "URI: ";
message += server.uri();
message += "nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "nArguments: ";
message += server.args();
message += "n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
ssid填寫wifi名,password填寫wifi密碼