Code Monkey home page Code Monkey logo

create-esp32-app's Introduction

ESP32 Starter template

A Simple ESP32 Starter template generator

from your command line run

npx create-esp32-app

create-esp-32.PNG

You can watch the video by clicking the image link below

Quick overview

This template can be used as is but, its intended as a quick start for the students learning the ESP32-IDF through my course https://learnesp32.com

if you want a simple vanilla flavoured template to copy and paste see esp32-starter

prerequisites

  1. You will need to have node installed.

  2. The esp-idf must be installed. you can follow the instructions in my course (free of charge) with the "Setting up Your Environment" module or follow the official documentation. The installation will create 2 folders. the esp-idf and the tools folder (usually called .espresif). pay attention to where these folders are as you will need to know there locations

  3. this template is for vscode which will need to be installed

  4. In VSCODE add the c++ extension

  5. ensure tour ESP32 is plugged in and that a COM PORT is established (You may need a driver for your ESP32 dev board)

Run command

  1. in any directory run
npx create-esp32-app
  1. you will be prompted for the name of your project.
  2. you will be prompted for the IDF path (esp-idf folder). select or navigate to the location of the IDF path. If you have an environment variable called IDF_PATH the path will default to the environment variable.
  3. you will be prompted for the IDF-TOOLS path (.espressif folder). select or navigate to the location of the IDF-TOOLS path. If you have an environment variable called IDF_TOOLS_PATH the path will default to the environment variable.
  4. You will be asked if you want to create a c or c++ project
  5. You will be asked if you like to include additional sample code or other items. Leave blank if you would like a bare-bones project
  6. navigate to the directory of the project name you created
cd <project name>
  1. open the project in vscode code .

vs code intellisense

intellisense should just work so long as you have set up the paths correctly. If you have trouble double check your idf and tools paths and correct them in the /.vscode/c_cpp_properties.json file

flashing the esp32

  1. In vs code, open a new terminal by pressing ctrl + ` (or pressing F1 and typing open new terminal)

  2. The first time you open the terminal. Vscode will ask you to allow permission to run a script. The script in question is the esp-idf import script which imports all the esp-idf environment variables into the shell. click allow and close the shell by pressing the trash can (not the x) then reopen the terminal again.

  3. Type the following command

idf.py -p [your com port] flash monitor

Additional code samples

  • blinky [example: blink led]
  • c++ [example: c++ starter]
  • debug [debug cfg files]
  • example connect [example: connect to internet]
  • menuconfig [example: config menu with idf.py menuconfig]

log a request if you would like something else added

Troubleshooting

Integrated terminal does not work in vs-code after version 1.15.1

As of vs-code v1.56.1 the terminal does not run the needed scripts to import the IDF environment see this issue

You will need to add "terminal.integrated.allowWorkspaceConfiguration":true to your user settings for the terminal to work.

To get to your user settings, see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations for windows users its usually located at C:\Users<you user name>\AppData\Roaming\Code\User\settings.json then add the following entry

"terminal.integrated.allowWorkspaceConfiguration":true

space in user profiles

you receive an error when running npx-create-esp32-app that looks like

  • Error: EPERM: operation not permitted, mkdir
  • TypeError: cannot read property '' of undefined

This can happen on windows if there is a space in your username which means you will have a space in your home directory. You can see your home directory on windows by typing

echo %USERPROFILE%

if you do have a space

  1. create a directory to store your npm (node package manager) cache
  2. set the new directory for node cache
mkdir c:\node_cache
npm config set cache C:\node_cache --global

then try npx create-esp32 again

As of vs-code v1.56.1 the terminal does not run the needed scripts to import the IDF environment see this issue

You will need to "terminal.integrated.allowWorkspaceConfiguration":true to your user settings for the terminal to work.

To get to your user settings, see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations for windows users its usually located at C:\Users<you user name>\AppData\Roaming\Code\User\settings.json then add the following entry

"terminal.integrated.allowWorkspaceConfiguration":true

python issues

  1. if you use the installed idf console and there is no issues however in the idf terminal you get a python issue, it is recommended that you download and install python from https://www.python.org/downloads/

when going through the wizard pay attention to the options and under advanced option ensure you check the

Add Python to environment variables

option

python variables are unsatisfied

have a look at the .vscode/settings.json

check or add that you have the following entries. The one for your OS is the important one

  "terminal.integrated.env.windows": {
    "IDF_PYTHON_ENV_PATH" : "<IDF_TOOLS_PATH>/.espressif/tools/idf-python/3.8.7/Scripts"
  },
  "terminal.integrated.env.osx": {
    "IDF_PYTHON_ENV_PATH" : "<IDF_TOOLS_PATH>/.espressif/tools/idf-python/3.8.7/Scripts"
  },
  "terminal.integrated.env.linux": {
    "IDF_PYTHON_ENV_PATH" : "<IDF_TOOLS_PATH>/.espressif/tools/idf-python/3.8.7/Scripts"
  },

ensure the path for your OS is correct

Sometimes on initial configuration or if you are switching IDF version you get an error in the console telling you to run install.bat. If you see this simple run it. c:\esp\esp-idf\install.bat this usually sorts out most other python issues. You normally would only need to run this once

Create-esp32-app not updating to the new version

the current version of the project can be established by looking at the package.json under the version property. When you run create-esp32-app the first line should print out the version number

Welcome to CREATE-ESP32-APP v0.7.2 ๐ŸŽ‰

If you don't see the version number or it's old, you may have a stale version in cache. To remedy this

  1. ensure its not globaly deployed
npm uninstall -g create-esp32-app
  1. find the location of your npx cache
 npm config get cache
  1. this will print out the cache directory. navigate to that directory
cd <cache dir>
  1. you should see a _npx dir in there
cd _npx
  1. delete the content
#for linux or mac
rm -rf *
#for windows
del *

Contribution

Pull requests are both welcome and encouraged ๐Ÿ˜ƒ

create-esp32-app's People

Contributors

mair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-esp32-app's Issues

Espressif Visual Studio Plugin

Thanks for your tutorial.

I followed your instruction and after pressing CMD+~ I get the following result:

[Running] cd "~/dev/iot/esp/projects/hello_world_native/main/" && gcc main.c -o main && "~/dev/iot/esp/projects/hello_world_native/main/"main
main.c:3:10: fatal error: 'driver/gpio.h' file not found
#include "driver/gpio.h"
         ^~~~~~~~~~~~~~~
1 error generated.

It looks like he is not picking up the cmd described in settings.conf. I have added

"terminal.integrated.allowWorkspaceConfiguration": true,

to the user setting, but that doesn't seem to help.

And I am asking myself, is there a reason that you are not using the official espressif visual studio plugin?

macOS has moved to zsh

In esp-idf-template/.vscode/settings.json bash is used to configure settings, however Catalina has moved to zsh and so when setting the shell to zsh the error no such option init-file appears:

"terminal.integrated.shell.osx": "/bin/zsh",
  "terminal.integrated.shellArgs.osx": ["--init-file", "/Vol...],

How does one fix this for zsh?

Update:

I ended up commenting out the above lines and adding the following to my .zshrc file:

esp() {
    conda activate esp32
    . /Volumes/Atom/esp32/esp-idf/export.sh
}

As I use conda to control my python environments, this solution works well.

Errors with Node.JS. Unable to create the esp32 projects (both Win / Ubuntu)

I need some help. I have a problem using your Node JS app today (both Window 10 and Ubuntu 20.04 LTS). It cannot create the project. In the project folder, there is no file. I did not have any issue last Friday on Window 10. Thank you for any help or comment you can provide.

Best regards,
Michael

Windows 10

C:\Users\mikel\Documents\esp_idf\esp32\idf420_examples\peripherals>npx create-esp32-app
npx: installed 424 in 19.384s
IDF_PATH env var set! using C:\esp\esp-idf
IDF_TOOLS_PATH env var set! using C:\esp\tools.espressif
? Project Name ledc_vsc
? Select directory to ESP-IDF C:\esp\esp-idf
? Select directory to espressif Tools (Xtensa tools[.espressif] directory]) C:\esp\tools.espressif
? Use C++ (default is c [press Enter]) No
? Select additional sample code blinky [example: blink led], debug [debug cfg files], menuconfig [example: config menu
with idf.py menuconfig]
answers {
projectName: 'ledc_vsc',
iDFPath: 'C:\esp\esp-idf',
toolsPath: 'C:\esp\tools\.espressif',
isCpp: false,
pythonDir: null,
Additions: [ 'blinky', 'Debug', 'menuconfig' ]
}
Generating Template with name"ledc_vsc"
(node:3968) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of null
at generateTemplateModel (C:\Users\mikel\AppData\Roaming\npm-cache_npx\3968\node_modules\create-esp32-app\index.js:204:41)
at generate (C:\Users\mikel\AppData\Roaming\npm-cache_npx\3968\node_modules\create-esp32-app\index.js:150:23)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:3968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Ubuntu 20.04 LTS

michael@michael-SVE141190X:~/esp/esp_idf_v420_projects/examples/peripherals$ npx create-esp32-app
npx: installed 424 in 14.789s
IDF_PATH env var not set
IDF_TOOLS_PATH env var not set
? Project Name gio_vsc
? Select directory to ESP-IDF /home/michael/esp/esp-idf
? Select directory to espressif Tools (Xtensa tools[.espressif] directory]) /home/michael/.espressif
? Use C++ (default is c [press Enter]) No
(node:15405) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, scandir '/home/michael/.npm/_npx/15405/lib/node_modules/create-esp32-app/additions'
at Object.readdirSync (fs.js:790:3)
at getAdditions (/home/michael/.npm/_npx/15405/lib/node_modules/create-esp32-app/index.js:85:27)
at generate (/home/michael/.npm/_npx/15405/lib/node_modules/create-esp32-app/index.js:113:29)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:15405) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:15405) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Warning!: Python directory in tools was not discovered

Ubuntu 20.04
Espressif sdk: 4.2

Problem: python interpreter not found.

This directory exists: ~/esp/esp-idf/tools
But it has no .espressif subdirectory.
ie: ~/esp/esp-idf/tools/.espressif does not exist.

This directory exists: ~/.espressif/tools, however if selected as the toolsPath, the python dir is not found.

Warning!: Python directory in tools was not discovered
answers {
  projectName: 'blinky',
  iDFPath: '/home/davem/esp/esp-idf',
  toolsPath: '/home/davem/.espressif/tools',
  isCpp: false,
  pythonDir: null,
  Additions: []
}
Generating Template with name"mair1"
Success

There is a python directory here though: /.espressif/python_env/idf4.2_py3.8_env, but I don't see how to set that separately from the tools directory.

Note: even though the python interpreter isn't found, the project still compiles and flashes just fine!

And opening a terminal in VSCode (ctl-shift-`) does find a python interpreter:

Detecting the Python interpreter
Checking "python" ...
Python 3.8.5
"python" has been detected
Adding ESP-IDF tools to PATH...
Not using an unsupported version of tool cmake found in PATH: 3.16.3.
Using Python interpreter in /home/davem/.espressif/python_env/idf4.2_py3.8_env/bin/python
Checking if Python packages are up to date...
Python requirements from /home/davem/esp/esp-idf/requirements.txt are satisfied.
Added the following directories to PATH:
  /home/davem/esp/esp-idf/components/esptool_py/esptool
  /home/davem/esp/esp-idf/components/espcoredump
  /home/davem/esp/esp-idf/components/partition_table
  /home/davem/esp/esp-idf/components/app_update
  /home/davem/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin
  /home/davem/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin
  /home/davem/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin
  /home/davem/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin
  /home/davem/.espressif/tools/cmake/3.16.4/bin
  /home/davem/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709/openocd-esp32/bin
  /home/davem/.espressif/python_env/idf4.2_py3.8_env/bin
  /home/davem/esp/esp-idf/tools
Done! You can now compile ESP-IDF projects.

c_cpp_properties.json (non Issue)

This is not a issue, but you can shrink your c_cpp_properties.json file down by using
"${IDF_PATH}/components/**"

instead of listing all the components folders line by line.

I.E...

{
    "env": {
        "MESSAGE":" MAC AND LINUX USERS!!!- change path from c:/... to ~/esp/... or as approirate for your enviroment",
        "IDF_TOOLS": "<%= IDF_TOOLS_PATH %>/tools",
        "IDF_PATH": "<%= IDF_PATH %>"
    },
    "configurations": [
        {
            "name": "esp32",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${IDF_PATH}",
                    "${IDF_TOOLS}"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "${workspaceFolder}",
                "${workspaceFolder}/build/config",
                "${workspaceFolder}/build/bootloader/config",

                "${IDF_TOOLS}/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/8.2.0/include",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.2.0",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.2.0/xtensa-esp32-elf",

                "${IDF_TOOLS}/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/8.2.0/include",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.2.0",
                "${IDF_TOOLS}/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.2.0/xtensa-esp32-elf",
                
                "${IDF_PATH}/components/**"
            ],
            "defines": [],
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

OTA: Failed to update firmware

I am having a trouble working with OTA_using_google_drive. When I try to upgrade I get the following error message from the terminal:

I (200024) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (200994) esp_netif_handlers: example_connect: sta ip: 192.168.1.9, mask: 255.255.255.0, gw: 192.168.1.1
I (200994) example_connect: Got IPv4 event: Interface "example_connect: sta" address: 192.168.1.9
I (201584) example_connect: Got IPv6 event: Interface "example_connect: sta" address: fe80:0000:0000:0000:3694:54ff:fe25:a510, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (201584) example_connect: Connected to example_connect: sta
I (201594) example_connect: - IPv4 address: 192.168.1.9
I (201594) example_connect: - IPv6 address: fe80:0000:0000:0000:3694:54ff:fe25:a510, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (201714) wifi:idx:1 (ifx:0, 84:06:fa:d9:28:a0), tid:4, ssn:0, winSize:64
E (205984) HTTP_HEADER: Buffer length is small to fit all the headers
I (206144) esp_https_ota: Starting OTA...
I (206144) esp_https_ota: Writing to partition subtype 16 at offset 0x110000
E (206154) esp_https_ota: Mismatch chip id, expected 0, found 27757
OTA Failed to update firmware

E (206154) OTA: Failed to update firmware

c_cpp_properties.json file ${IDF_PATH} fails to resolve.

Given a library include statement with 'squiggly' lines.
When the lightbulb icon is selected and the absolute path is included in c_cpp_properties.json file, the squiggly lines disappear.

However, if the path is substituted, then the squiggly lines return.

ie: this works: "/home/davem/esp/esp-idf/components/soc/soc/include"
but this fails: "${IDF_PATH}/components/soc/soc/include"

curiously, the environment variable is correct:

echo ${IDF_PATH}
/home/davem/esp/esp-idf

ESp32 S2

Hi

Is there any args for ESP32S2 boards

Example - Multi Core / Multi Threading on Dual Core ESP32

Hi Mair,

This is a feature request towards "Learning ESP32" course.
Multi Core / Multi Threading on Dual Core ESP32
Please add an example of creating two or more different threads running on Two separate cores of ESP32 - 'D' series dual core chips. Also how to exchange information between separate thread process running on different cores will highly appreciated. This will also add an advance and must desired/learn topic to the course.

Best Regards,
Vinay

new version of vs code breaks terminal

As of vs-code v1.56.1 the terminal does not run the needed scripts to import the IDF environment
see this issue

You will need to add "terminal.integrated.allowWorkspaceConfiguration":true to your user settings for the terminal to work.

To get to your user settings, see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations
for windows users its usually located at C:\Users\<you user name>\AppData\Roaming\Code\User\settings.json
then add the following entry

"terminal.integrated.allowWorkspaceConfiguration":true
for further troubleshooting see the troubleshooting section in the readme file https://github.com/Mair/create-esp32-app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.