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.

@playbahn
Copy link

Thanks man!

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