NodeMCU

Last modified by Leon Poon on 2021/01/20 22:58

Nodemcu V3 Lua WiFi module integrated ESP8266 + additional 32Mbit FLASH, USB serial port CP2102.

dmesg
[46271.336289] usb 3-7.2: new full-speed USB device number 14 using xhci_hcd
[46271.467461] usb 3-7.2: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 1.00
[46271.467463] usb 3-7.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[46271.467465] usb 3-7.2: Product: CP2102 USB to UART Bridge Controller
[46271.467467] usb 3-7.2: Manufacturer: Silicon Labs
[46271.467468] usb 3-7.2: SerialNumber: 0001
[46271.480537] cp210x 3-7.2:1.0: cp210x converter detected
[46271.482413] usb 3-7.2: cp210x converter now attached to ttyUSB0
platformio.ini
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps = arduino-libraries/NTPClient@^3.1.0

Blink all GPIO pins and NTP (uses https://platformio.org/lib/show/551/NTPClient/): 

main.cpp
#include <Arduino.h>
#include
<ESP8266WiFi.h>
#include
<WiFiUdp.h>
#include
<NTPClient.h>
const char *ssid     = "<ssid>";
const char *password = "<wpa_password>";

WiFiUDP ntpUDP;

NTPClient timeClient(ntpUDP, "ntp-b.nist.gov", 0, 60000);


void f2(void (*f)(uint8_t, uint8_t), uint8_t val) {

// 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;


 for (uint8_t i = 0; i <= 5; i++)
  (*f)(i, val);
 for (uint8_t i = 12; i <= 16; i++)
  (*f)(i, val);
}

void setup() {
  f2(&pinMode, OUTPUT);

 // Serial.begin(115200);

  WiFi.begin(ssid, password);

 while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
   // Serial.print ( "." );
 }


  timeClient.begin();
}


unsigned long t;


void f1(uint8_t hl) {
  timeClient.update();
 unsigned long t1;
 for (; (t1 = timeClient.getEpochTime()) == t; delay(1));

  t = t1;
 // Serial.println(timeClient.getFormattedTime());

  f2(&digitalWrite, hl);

}

void loop() {
  f1(HIGH);
  f1(LOW);
}
Upload log
Configuring upload protocol...
AVAILABLE: espota, esptool
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/ttyUSB0
Uploading .pio/build/nodemcuv2/firmware.bin
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: AA:BB:CC:DD:EE:FF
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 269888 bytes to 199316...

Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 269888 bytes (199316 compressed) at 0x00000000 in 17.6 seconds (effective 122.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...