NodeMCU引脚问题说明

  1. 5 年前
    2

    电路板中引脚的数量并未映射到ESP8266上的引脚数。因此,例如,电路板的引脚D1不映射到ESP8266的GPIO1(它实际上映射到GPIO5)

    因此,正确的引脚映射如下[1] [2](左侧为NodeMCU,右侧为ESP8266):

    D0 = GPIO16;
    D1 = GPIO5;
    D2 = GPIO4;
    D3 = GPIO0;
    D4 = GPIO2;
    D5 = GPIO14;
    D6 = GPIO12;
    D7 = GPIO13;
    D8 = GPIO15;
    D9 = GPIO3;
    D10 = GPIO1;
    LED_BUILTIN = GPIO16(电路板LED的辅助常数,而不是电路板引脚);

    不过这些在官方库里已经定义好了。直接用就可的。

    static const uint8_t SDA = PIN_WIRE_SDA;
    static const uint8_t SCL = PIN_WIRE_SCL;
    
    static const uint8_t LED_BUILTIN = 16;
    static const uint8_t BUILTIN_LED = 16;
    static const uint8_t D0   = 16;
    static const uint8_t D1   = 5;
    static const uint8_t D2   = 4;
    static const uint8_t D3   = 0;
    static const uint8_t D4   = 2;
    static const uint8_t D5   = 14;
    static const uint8_t D6   = 12;
    static const uint8_t D7   = 13;
    static const uint8_t D8   = 15;
    static const uint8_t D9   = 3;
    static const uint8_t D10  = 1;

    示例代码:

    因此,我们将使用定义的D0常数来控制LED,而无需担心映射到实际的ESP8266 GPIO引脚。

    void setup() {
     
      pinMode(D0, OUTPUT); //Declare Pin mode
     
    }
     
    void loop() {
     
      digitalWrite(D0, HIGH);   //Turn the LED on
      delay(1000);              //Wait 1 second
      digitalWrite(D0, LOW);    //Turn the LED off
      delay(1000);              //Wait 1 second
     
    }

或者 后参与话题.