14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WeMos D1 (ESP8266) を動かす

Last updated at Posted at 2017-01-07

(参考) ESP-WROOM-02 : ArduinoIDEでSketch書き込み

WeMos D1

  • 見た目はArduino. Flash書き換えをRTS/DTRで自動化しているのでESP-WROOM-02より便利.
Pin Function ESP-8266 Pin
TX TXD TXD
RX RXD RXD
A0 Analog input, max 3.3V input A0
D0 IO GPIO16
D1 IO, SCL GPIO5
D2 IO, SDA GPIO4
D3 IO, 10k Pull-up GPIO0
D4 IO, 10k Pull-up, BUILTIN_LED GPIO2
D5 IO, SCK GPIO14
D6 IO, MISO GPIO12
D7 IO, MOSI GPIO13
D8 IO, 10k Pull-down, SS GPIO15
G Ground GND
5V 5V -
3V3 3.3V 3.3V
RST Reset RST
  • 1 analog input(3.2V max input)
  • All of the IO pins run at 3.3V.
  • Power jack, 9-24V power input.

購入

設定

  • Arduino IDEのBoard Mangerで,"WeMos D1 R2 & mini" を選択
    (https://github.com/esp8266/Arduino)
  • upload speed : 115200bps (921600bpsでは動作しない. cloneだから?)
  • CH340GのシリアルドライバはWindows10だと標準でinstallされる
  • シリアルケーブルに依存するようなので注意! (ダメなシリアルケーブルだと,デバイスは認識するが,teratermなどでportをopenしようとしても失敗する)

CPU Frequency:
80MHz
160MHz

Flash Size:
4M (3M SPIFFS) – 3M File system size
4M (1M SPIFFS) – 1M File system size

sample

  • LED点滅

※ 素の ESP-WROOM-02 では,GPIO2は書き換えのためHIGH固定にしているので注意

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

// the loop function runs over and over again forever
void loop() {
  digitalWrite(2, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because 
                                    // it is acive low on the ESP-01)
  delay(2000);                      // Wait for a second
  digitalWrite(2, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(1000);                      // Wait for two seconds (to demonstrate the active low LED)
}
  • MAC取得
#include <ESP8266WiFi.h>

void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);     // Initialize the LED_BUILTIN pin as an output

  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  Serial.println();
  Serial.println();
  Serial.print("Mac Address: ");
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
    mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
  );
  Serial.println(buf);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);

  digitalWrite(2, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because 
                                    // it is acive low on the ESP-01)
  delay(2000);                      // Wait for a second
  digitalWrite(2, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(1000);                      // Wait for two seconds (to demonstrate the active low LED)
}
  • Wifi接続

Sketch例 -> ESP8266Wifi -> WifiClient の ssidとpasswordを設定して実行するのが一番簡単.

(補足) PCからシリアルがOpenできない問題(解決)

ArduinoIDEで書き換えしようとしても,SerialがOpenできなかった.
考えられる可能性として,

14
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?