Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 9개 있습니다.)

New NodeMCU v3 아두이노 호환 보드의 기본 개발 환경 구성

예전에 .NET Micro Framework이 올라간 넷두이노 플러스를 테스트한 이후,

.NET Micro Framework - 넷두이노 플러스
; https://www.sysnet.pe.kr/2/0/1392

자유도가 좀 더 높은 Raspberry PI도 만져 보고,

윈도우즈 사용자를 위한 라즈베리 파이 제로 W 모델을 설정하는 방법
; https://www.sysnet.pe.kr/2/0/11372

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드 및 마우스로 쓰는 방법 (절대 좌표, 상대 좌표, 휠)
; https://www.sysnet.pe.kr/2/0/11369

이제는 (아는 분께서 선물로 주신) 아두이노 마이크로 보드를 테스트해 보게 되었습니다. ^^ "LiLon New NodeMCU v3"라고 적혀 있는 걸로 봐서 호환 보드인 것 같은데 보드 뒤에 자그마한 글씨로 다음과 같이 써져 있습니다.

1. Install CH340G driver
2. Use 9600bps baud rate
3. Connect to WiFi

검색해 보니, 다음의 다운로드가 있습니다.

CH340 Drivers for Windows, Mac and Linux
; https://sparks.gogo.co.nz/ch340.html
; https://sparks.gogo.co.nz/assets/_site_/downloads/CH34x_Install_Windows_v3_4.zip

설치 후, 장치 관리자에 가보면 다음과 같이 CH340 장치가 COM3로 잡혀 있습니다. (그런데, 굳이 저 드라이버 설치하지 않아도 장치 관리자에 CH340이 잡히긴 했습니다. 따라서 어쩌면 설치하지 않아도 됩니다.)

nodemcu_v3_2.png




자, 그럼 이제 Arduino IDE를 다운로드하고,

Arduino IDE
; https://www.microsoft.com/ko-kr/p/arduino-ide/9nblggh4rsd8?ocid=badge

"Tools" / "Board: ..." 메뉴에 "Arduino/Genuino Uno"라고 잡힌 것을 볼 수 있습니다.

nodemcu_v3_1.png

"Tools" / "Port: COM[n]" 메뉴를 통해 장치 관리자에서 본 대로 "COM3"로 설정한 후, "Tools" / "Get Board Info" 메뉴를 실행해 보면 다음과 같은 정보가 나옵니다.

BN: Unknown board
VID: 1A86
PID: 7523
SN: Upload any sketch to obtain it

장치 인식은 되었으니, 코드를 실행해 봐야겠죠. ^^ 이를 위해 "File" / "Examples" / "01.Basics" / "Blink" 예제를 선택하고 "Sketch" / "Upload"를 선택했는데 다음과 같은 오류가 발생합니다.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

혹시나 "Tools" / "Board: ..." 메뉴에서 "Arduino/Genuino Micro"를 선택해도 이번엔 다음과 같은 오류가 발생합니다.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Micro"

Build options changed, rebuilding all
Sketch uses 4130 bytes (14%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "≪"; type = y
    Software Version = ®.

흠... 아직 뭔가 있어야 하나 봅니다. 검색 결과 다음의 링크를 찾았습니다.

Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)
; http://www.instructables.com/id/Getting-Started-With-ESP8266LiLon-NodeMCU-V3Flashi/

위의 글에 실린 아래의 그림이 제가 가진 보드와 정확히 일치합니다. ^^

nodemcu_v3_0.jpg

Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106
Operating Voltage: 3.3V
Input Voltage: 7-12V
Digital I/O Pins (DIO): 16
Analog Input Pins (ADC): 1
UARTs: 1
SPIs: 1
I2Cs: 1
Flash Memory: 4 MB
SRAM: 64 KB (가용 50K+)
Clock Speed: 80 Mhz
Wi-Fi: IEEE 802.11 b/g/n:
    Integrated TR switch, balun, LNA, power amplifier and matching network
    WEP or WPA/WPA2 authentication, or open networks

따라서 저 글을 따라 하면 되겠군요. 그래서 "NodeMCU Flasher Master"와 "NodeMCU Firmware"를 다운로드하고,

NodeMCU Flasher Master
; https://github.com/nodemcu/nodemcu-flasher/archive/master.zip

NodeMCU Firmware
; https://github.com/sleemanj/ESP8266_Simple/raw/master/firmware/ai-thinker-0.9.5.2-115200.bin

"NodeMCU Flasher Master"를 압축 해제한 폴더의 하위에 있는 "\nodemcu-flasher-master\Win64\Release"의 "ESP8266Flasher.exe" 파일을 실행합니다. (펌웨어 업그레이드 동안에는 Arduino IDE를 종료해줍니다.) 그럼 다음과 같이 뜨는데,

nodemcu_v3_3.png

보는 바와 같이 제 경우에는 "COM3"로 잡혔기 때문에 위와 같이 COM Port를 설정해 주었습니다. 또한 "Config" 탭으로 다운로드했던 "NodeMCU Firmware" 파일 (ai-thinker-0.9.5.2-115200.bin)을 설정합니다.

nodemcu_v3_4.png

그다음 "Advanced"에서는 Baudrate을 (보드에 적힌 속도를 무시하고) 115200으로 잡았습니다.

nodemcu_v3_5.png

설정을 마쳤으면 다시 "Operation" 탭으로 가 "Flash" 버튼으로 펌웨어를 업그레이드합니다. 완료 후, 이제 Arduino IDE를 다시 실행하고, "File" / "Preferences" 메뉴를 실행하면 뜨는 대화창에서 "Additional Boards Manager URLs:" 항목에 다음의 URL을 적어 줍니다.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

그다음, "Tools" / "Board: ..." / "Boards Manager..."를 선택하면 뜨는 대화상자에서 "esp8266"으로 검색한 항목을 선택하고 "Install" 버튼을 누릅니다.

nodemcu_v3_6.png

마지막으로 "Tools" / "Board: ..." 메뉴를 펼치면 이제 "NodeMCU 1.0 (ESP-12E Module)"이라는 항목이 나타납니다. 그것을 선택해 주면 설정 끝입니다.




자... 그럼 다시 "Sketch" / "Upload"를 하면 다음과 같은 메시지와 함께 보드에 있는 LED가 깜빡이며 잘 업로드가 됩니다.

Archiving built core (caching) in: %LOCALAPPDATA%\Temp\arduino_cache_95172\core\core_esp8266_esp8266_nodemcuv2_CpuFrequency_80,FlashSize_4M1M,LwIPVariant_v2mss536,Debug_Disabled,DebugLevel_None____,FlashErase_none,UploadSpeed_115200_4f8635a0650ea7b7a41882d7d1a6a6e1.a
Sketch uses 246331 bytes (23%) of program storage space. Maximum is 1044464 bytes.
Global variables use 32288 bytes (39%) of dynamic memory, leaving 49632 bytes for local variables. Maximum is 81920 bytes.
Uploading 250480 bytes from %LOCALAPPDATA%\Temp\arduino_build_903540/Blink.ino.bin to flash at 0x00000000
................................................................................ [ 32% ]
................................................................................ [ 65% ]
................................................................................ [ 97% ]
.....                                                                            [ 100% ]

그런데, 분명히 아무런 문제가 없는데 Blink 프로그램이 동작하지 않습니다. 즉, 보드에 있는 LED가 전혀 깜빡이지 않는 것입니다. 그래도 혹시나 해서, Serial 통신 코드를 추가하고,

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  Serial.println(100);
}

업로드 후, "Tools" / "Serial Monitor"를 통해 "100" 메시지가 찍히는 것을 확인했습니다. 검색해 보면,

Does the Node MCU v3 (LoLin) not have a builtin led?
; https://arduino.stackexchange.com/questions/38477/does-the-node-mcu-v3-lolin-not-have-a-builtin-led

"Node MCU v3" 제품의 경우 기본 LED가 2번이라고 합니다. 따라서 LED_BUILTIN 상수가 (대개의 arduino 제품들에 해당하는) 13번이므로 동작을 안 하던 것입니다. 따라서 다음과 같이 코드를 바꾸면 LED blink 테스트가 잘 됩니다.

void setup() {
  pinMode(2, OUTPUT);
}

void loop() {
  digitalWrite(2, HIGH);   // turn the LED off (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(2, LOW);    // turn the LED on by making the voltage LOW
  delay(1000);                       // wait for a second
}

그래도 가장 중요한 것은, WiFi 동작 유무이므로 "Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)"에 있던 예제를,

#include<ESP8266WiFi> 

const char* ssid = "Tenda"; //your WiFi Name
const char* password = "12345678";  //Your Wifi Password
int ledPin = 03; 
WiFiServer server(80);

void setup() 
{
  Serial.begin(115200);
  delay(10); 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW); 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid); 
  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.println("WiFi connected"); 
  server.begin();
  Serial.println("Server started");
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/"); 
}

void loop() 
{
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  } 
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush(); 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); 
  client.println("");
  client.println("");
  client.print("Led is : "); 
  if(value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }  client.println("");  
  client.println(" On ");
  client.println(" Off ");  
  client.println(" ");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println(""); 
} //code copied from link(http://internetofthinking.blogspot.com/)

실행해 봐야 합니다. 이걸 빌드하려면, "Sketch" / "Include Library..." 메뉴를 통해 "ESP8266WiFi"를 선택해 줘야 합니다. 그럼 다음과 같은 위치에 헤더 파일 및 소스코드들이 다운로드됩니다.

%USERPROFILE%\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi\src

이와 함께 include 헤더 파일이 다음과 같이 확장됩니다.

#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiUdp.h>

#include<ESP8266WiFi> 

이 중에서 "#include<ESP8266WiFi>" 코드는 "Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)" 예제 코드에서 사용했던 것이므로 그냥 주석 처리하거나 삭제해 버립니다.

#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiUdp.h>

그다음, 자신의 환경에 맞게 WiFi의 ssid와 암호를 입력하고,

const char* ssid = "Tenda"; //your WiFi Name
const char* password = "12345678";  //Your Wifi Password

빌드 후 업로드를 하면 "Serial Monitor" 도구에서 다음과 같은 출력을 확인할 수 있습니다.

...
WiFi connected
Server started
Use this URL to connect: http://172.30.1.1/

이제 웹 브라우저를 이용해 저 주소로 접근하면 다음과 같은 결과를 보게 되고.

nodemcu_v3_7.png

이 정도면, 일단 기본적인 개발 환경 테스트는 완료됩니다. ^^




"Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)" 예제를 "Sketch" / "Include Library..."를 통한 라이브러리 구성 없이 컴파일하면 다음과 같은 오류가 발생합니다.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

F:\cloud_drive\Dropbox\articles\arduino_micro\sketch_jul10a\sketch_jul10a.ino:1:23: fatal error: ESP8266WiFi: No such file or directory

 #include<ESP8266WiFi> 

                       ^

compilation terminated.

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.




Firmware 업그레이드 시 동작이 안 되고, "Log" 탭에 다음과 같은 메시지가 남는다면,

Error:Serial port connect failed, please check it.

현재 실행 중인 Arduino IDE가 있는 경우 COM 포트 경합 문제일 수 있으므로 종료해 줍니다.




만약 COM 포트가 틀리면 "Sketch" / "Upload" 메뉴 실행 시 다음과 같은 오류가 발생합니다.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x09
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

또한, "Tools" / "Get Board Info" 메뉴를 선택해도 "Native serial port, can't obtain info"라는 오류 메시지만 나옵니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/15/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  [11]  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13352정성태5/12/20233651.NET Framework: 2121. C# - Semantic Kernel의 대화 문맥 유지파일 다운로드1
13351정성태5/11/20234127VS.NET IDE: 185. Visual Studio - 원격 Docker container 내에 실행 중인 응용 프로그램에 대한 디버깅 [1]
13350정성태5/11/20233377오류 유형: 859. Windows Date and Time - Unable to continue. You do not have permission to perform this task
13349정성태5/11/20233729.NET Framework: 2120. C# - Semantic Kernel의 Skill과 Function 사용 예제파일 다운로드1
13348정성태5/10/20233635.NET Framework: 2119. C# - Semantic Kernel의 "Basic Loading of the Kernel" 예제
13347정성태5/10/20234000.NET Framework: 2118. C# - Semantic Kernel의 Prompt chaining 예제파일 다운로드1
13346정성태5/10/20233851오류 유형: 858. RDP 원격 환경과 로컬 PC 간의 Ctrl+C, Ctrl+V 복사가 안 되는 문제
13345정성태5/9/20235192.NET Framework: 2117. C# - (OpenAI 기반의) Microsoft Semantic Kernel을 이용한 자연어 처리 [1]파일 다운로드1
13344정성태5/9/20236427.NET Framework: 2116. C# - OpenAI API 사용 - 지원 모델 목록 [1]파일 다운로드1
13343정성태5/9/20234266디버깅 기술: 192. Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법
13342정성태5/8/20234211.NET Framework: 2115. System.Text.Json의 역직렬화 시 필드/속성 주의
13341정성태5/8/20233949닷넷: 2114. C# 12 - 모든 형식의 별칭(Using aliases for any type)
13340정성태5/8/20233987오류 유형: 857. Microsoft.Data.SqlClient.SqlException - 0x80131904
13339정성태5/6/20234676닷넷: 2113. C# 12 - 기본 생성자(Primary Constructors)
13338정성태5/6/20234177닷넷: 2112. C# 12 - 기본 람다 매개 변수파일 다운로드1
13337정성태5/5/20234699Linux: 59. dockerfile - docker exec로 container에 접속 시 자동으로 실행되는 코드 적용
13336정성태5/4/20234508.NET Framework: 2111. C# - 바이너리 출력 디렉터리와 연관된 csproj 설정
13335정성태4/30/20234608.NET Framework: 2110. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성 - Windows Forms파일 다운로드1
13334정성태4/29/20234254Windows: 250. Win32 C/C++ - Modal 메시지 루프 내에서 SetWindowsHookEx를 이용한 Thread 메시지 처리 방법
13333정성태4/28/20233709Windows: 249. Win32 C/C++ - 대화창 템플릿을 런타임에 코딩해서 사용파일 다운로드1
13332정성태4/27/20233799Windows: 248. Win32 C/C++ - 대화창을 위한 메시지 루프 사용자 정의파일 다운로드1
13331정성태4/27/20233809오류 유형: 856. dockerfile - 구 버전의 .NET Core 이미지 사용 시 apt update 오류
13330정성태4/26/20233460Windows: 247. Win32 C/C++ - CS_GLOBALCLASS 설명
13329정성태4/24/20233673Windows: 246. Win32 C/C++ - 직접 띄운 대화창 템플릿을 위한 Modal 메시지 루프 생성파일 다운로드1
13328정성태4/19/20233326VS.NET IDE: 184. Visual Studio - Fine Code Coverage에서 동작하지 않는 Fake/Shim 테스트
13327정성태4/19/20233754VS.NET IDE: 183. C# - .NET Core/5+ 환경에서 Fakes를 이용한 단위 테스트 방법
1  2  3  4  5  6  7  8  9  10  [11]  12  13  14  15  ...