Skip to content

Instantly share code, notes, and snippets.

@adi-g15
Created November 30, 2022 11:09
Show Gist options
  • Save adi-g15/de41e96079a5b63045e86dc7c8c5c87e to your computer and use it in GitHub Desktop.
Save adi-g15/de41e96079a5b63045e86dc7c8c5c87e to your computer and use it in GitHub Desktop.
Using arduino / arduino-cli with NodeMCU (esp8266)

After a lot of searching over the network, this is what I have ended up with. This is intentionally made such that even a absolute beginner is able to follow, so uses fixed paths.

Note: I am not using the --additional-urls flag since it didn't work for me back then, you may try it.

Step 0

First ensure that your PC is detecting the NodeMCU atleast.

arduino-cli board list

This should output something like:

Port         Protocol Type              Board Name FQBN Core
/dev/ttyUSB0 serial   Serial Port (USB) Unknown             

Step 1

Create a file named .cli-config.yml with the below content.

By default, arduino searches for this file in /usr/local/bin/.cli-config.yml, but I don't recommend you creating such a file in the root partition. You can create it anywhere you want, we just need the path to that file.

board_manager:
  additional_urls:
    - http://arduino.esp8266.com/stable/package_esp8266com_index.json

Step 2

Install the core packages for support for the NodeMCU board.

The package is called esp8266. If you install through the arduino IDE boards manager, you will see this name.

Use the path to the .cli-config.yml after --config-file, for example, if it's in the current directory (.) itself, run this:

arduino-cli core install esp8266:esp8266 --config-file ./.cli-config.yml

Now if you check the output of arduino-cli board listall. You will find a NodeMCU 1.0 board.

Extra Step:

In case you are using the Blynk library, use this to install that library:

arduino-cli lib install Blynk

Then, to compile your sketch/code, run:

Assuming the code is in nodemcu/nodemcu.ino

arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 nodemcu

Then upload to the board:

Replace /dev/ttyUSB0 with the port given in the output of arduino-cli board list in Step 0.

arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2 nodemcu

It should output something like:

esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 4c:75:25:37:40:e5
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 289216 bytes to 210989...
Wrote 289216 bytes (210989 compressed) at 0x00000000 in 18.6 seconds (effective 124.3 kbit/s)...
Hash of data verified.

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

Possible Errors

These are the possible errors you may face, following the above steps:

  1. Error during build: Platform 'esp8266:esp8266' not found: platform not installed

This simply means the core for the board has not been installed, see above steps for this, or ask in comments below.

  1. Invalid argument passed: Found 0 platform for reference "esp8266:esp8266"

It may happen after arduino-cli core install esp8266:esp8266. It is because arduino-cli doesn't have this board package in it's index. For this to work you have to provide the URL to a 3rd party index file, using --additional-urls or with config file .cli-config (recommended) as stated above

  1. fatal error: BlynkSimpleEsp8266.h: No such file or directory

This means you have used the BlynkSimpleEsp8266.h header in your code, which comes from the Blynk library. Follow the extra step to fix this.

@plainlystated
Copy link

Thanks for this -- and for dropping a link on the older doc as well. Very helpful!

@flyingyizi
Copy link

flyingyizi commented Mar 25, 2024

in step 1, execute arduino-cli config add board_manager.additional_urls http://arduino.esp8266.com/stable/package_esp8266com_index.json command maybe more easy.

like below shows :

$ arduino-cli config add board_manager.additional_urls http://arduino.esp8266.com/stable/package_esp8266com_index.json
$ arduino-cli core search esp8266
ID              Version Name
esp8266:esp8266 3.1.2   esp8266
$ arduino-cli core install esp8266:esp8266

$ arduino-cli board listall |findstr esp8266
4D Systems gen4 IoD Range        esp8266:esp8266:gen4iod
Adafruit Feather HUZZAH ESP8266  esp8266:esp8266:huzzah
Amperka WiFi Slot                esp8266:esp8266:wifi_slot
Arduino                          esp8266:esp8266:arduino-esp8266
DOIT ESP-Mx DevKit (ESP8285)     esp8266:esp8266:espmxdevkit
Digistump Oak                    esp8266:esp8266:oak
ESPDuino (ESP-13 Module)         esp8266:esp8266:espduino
ESPectro Core                    esp8266:esp8266:espectro
ESPino (ESP-12 Module)           esp8266:esp8266:espino
ESPresso Lite 1.0                esp8266:esp8266:espresso_lite_v1
ESPresso Lite 2.0                esp8266:esp8266:espresso_lite_v2
Generic ESP8266 Module           esp8266:esp8266:generic
Generic ESP8285 Module           esp8266:esp8266:esp8285
ITEAD Sonoff                     esp8266:esp8266:sonoff
Invent One                       esp8266:esp8266:inventone
LOLIN(WEMOS) D1 ESP-WROOM-02     esp8266:esp8266:d1_wroom_02
LOLIN(WEMOS) D1 R2 & mini        esp8266:esp8266:d1_mini
LOLIN(WEMOS) D1 mini (clone)     esp8266:esp8266:d1_mini_clone
LOLIN(WEMOS) D1 mini Lite        esp8266:esp8266:d1_mini_lite
LOLIN(WEMOS) D1 mini Pro         esp8266:esp8266:d1_mini_pro
LOLIN(WeMos) D1 R1               esp8266:esp8266:d1
Lifely Agrumino Lemon v4         esp8266:esp8266:agruminolemon
NodeMCU 0.9 (ESP-12 Module)      esp8266:esp8266:nodemcu
NodeMCU 1.0 (ESP-12E Module)     esp8266:esp8266:nodemcuv2
Olimex MOD-WIFI-ESP8266(-DEV)    esp8266:esp8266:modwifi
Phoenix 1.0                      esp8266:esp8266:phoenix_v1
Phoenix 2.0                      esp8266:esp8266:phoenix_v2
Schirmilabs Eduino WiFi          esp8266:esp8266:eduinowifi
Seeed Wio Link                   esp8266:esp8266:wiolink
SparkFun Blynk Board             esp8266:esp8266:blynk
SparkFun ESP8266 Thing           esp8266:esp8266:thing
SparkFun ESP8266 Thing Dev       esp8266:esp8266:thingdev
SweetPea ESP-210                 esp8266:esp8266:esp210
ThaiEasyElec's ESPino            esp8266:esp8266:espinotee
WiFi Kit 8                       esp8266:esp8266:wifi_kit_8
WiFiduino                        esp8266:esp8266:wifiduino
WifInfo                          esp8266:esp8266:wifinfo
XinaBox CW01                     esp8266:esp8266:cw01

@playbahn
Copy link

Thanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment