Tag Archives: wifi

ESP32 – IDF Sdk with Eclipse

After configuring the IDF development environment in the previous article

ESP32 – IDF Sdk

let’s see now how to use Eclipse as IDE for code development. Instructions are available at the link

Eclipse Setup

Download the  C/C++ Eclipse  for Linux

Eclipse Download

Unpack the file and move it to /opt/

Run ecplise

Set the workspace for eclipse

eclipse-workspaceOnce the IDE is open, select File -> Import -> C / C ++ – -> Existing Code as Makefile Project

eclipse-importPress Next; on the next screen select the folder containing the Makefile of a sample project in the “Existing Code Location” field and choose CrossGcc as “Toolchain for indexer settings” as shown below

eclipse-import2Once the project is loaded, using the mouse right button on the project name, select the properties option

eclipse-project-propertiesUnder C / C ++ Build -> Envinronment add the variable

eclipse-batchAdd the IDF_PATH variable pointing to the downloaded IDF SDK in the same section

eclipse-idf-pathEdit the PATH variable and add the path to the bin folder of the cross compiler /home/sviluppo/Esp32/espressif/esp/xtensa-esp32-elf/bin

eclipse-pathAccess “C / C ++ General” -> “Preprocessor Include Paths”; choose the Providers tab and click on “CDT Cross GCC Built-in Compiler Settings”

eclipse-cross-cdtReplace $ {COMMAND}

eclipse-cross-cdt1with xtensa-esp32-elf-gcc

eclipse-cross-cdt2Choose now, always in the providers section,  “CDT GCC Build Output Parser”

eclipse-cross-cdt3and insert at the beginning of the “Compiler command pattern” xtensa-esp32-elf-

eclipse-cross-cdt4Save the configurations.

The project settings should always be made by make menuconfig in the unix shell. Access the shell and set the LED to be switched on/off  the value 2 as GPIO; this is because in our case the card is a doit whose design is illustrated in this document


Access to Example configuration

blink-configurationand set the gpio value to 2

blink-gpioSave the configuration. Go back to Eclipse and proceed with cleaning with

eclipse-clean-blinkand subsequent compilation with Project -> Build

eclipse-build-blinkTo run firmware flash from eclipse;, select the project and with the right button choose Build Targets -> Create …

eclipse-create-targetEnter flash as value in the target name field, leaving everything else as default

eclipse-create-target-flashAt this point we proceed to upload the image by double-clicking on the new flash item within the project targets

eclipse-run-flashThe settings to run the flash must be set with make menuconfig, as seen in the previous article

 

ESP32 – IDF Sdk

This article describes how to set the Espressif development environment for the ESP32.

From the link to the resources for the soc

https://www.espressif.com/en/products/hardware/esp32/resources

we access the guide for compiling the firmware on the Windows, OSX and Linux platforms

http://esp-idf.readthedocs.io/en/latest/get-started/index.html

In this article we use Linux Debian 9 as operating system, configured as described previously  here

MicroPython – Python ib embedded devices

We  use the IDF github. On Debian 9, with the user used to connect to the system, we create  the Esp32 folder under the user’s Home and  the espressif folder inside it

Install the prerequisites

Download the cross compiler

Create the esp folder and unpack the toolchain

Add the bin folder of the cross compiler to the PATH

Add the user used for the operations to the dialout group

Clone the IDF repository from  $HOME/Esp32/espressif

Add the IDF_PATH environment variable

Create the project folder under $HOME/Esp32/espressif and copy an example from di IDF examples

Run the configuration

Access Serial flasher config -> and set the connection parameters; in our case we leave the default

idf-serial_flasher-engSave the configuration and build the firmware

To upload the firmware on the device run

To upload only the application run

while to build only the application run

To run the program monitor run

hello_world-engHere are the other examples available with sdk

https://github.com/espressif/esp-idf/tree/f586f5e/examples

The following link contains the references of the IDF API

http://esp-idf.readthedocs.io/en/latest/api-reference/index.html

You can also generate documentation from the github source. Go into  ~/Esp32/espressif/esp-idf/docs/en

Install the prerequisites

Generate documentantion in html format

make-html-eng

The documentation is available under  _build / html.

In the next article we will configure Eclipse as IDE  to build our applications

ESP32 -IDF Sdk with Eclipse

 

ESP32 – Nodemcu firmware compiling

After  the compilation of the MicroPython firmware for ESP32

ESP32 – MicroPython compiling for ESP32

this article shows how to generate the Nodemcu firmware for the ESP32 MCU.

The firmware is not yet complete as the one existing for ESP8266.

The instructions can be found on the github at the link

https://github.com/nodemcu/nodemcu-firmware/tree/dev-esp32

The compilation documentation is available at the link

https://nodemcu.readthedocs.io/en/dev-esp32/en/build/

The operating system used is Debian 9 previously encountered for the esptool and Adafruit-ampy utilities

MicroPython – Python on embedded devices

Log on  with the operating system user on Debian 9, sviluppo in our case; under the home folder  create the Esp32 folder and inside this folder the  nodemcu  folder

Clone the repository

To update the cloned repository follow the description on the compilation link, i.e.

Go into  nodemcu-firmware-esp32 folder and run

nodemcu-settingsEnable the bluetooth  in Component config–>Bluetooth

nodemcu-bluetoothEnable various modules in Component config–>Nodemcu modules

nodemcu-modulesIn the flash settings we set the default values for our ESP32,  Serial flasher config->

nodemcu-flashSave the configuration and exit. To build the firmware run

At the end of the compilation the command to upload the firmware  is shown; the same operation is executed  by simply running

For informations about the partitions of the various ESP32 versions, refer to the documentation

http://api-guides/partition-tables.html

In the next article we’ll  show how to make an application using the Espressif SDK

ESP32 – IDF Sdk

ESP32 – MicroPython compiling for ESP32

We begin now a series of articles about the Espressif ESP32 MCU

ESP32 Wifi-Bluetooth Module

After having analyzed in the previous articles  MicroPython  for ESP8266, in this we start to treat MicroPython on ESP32.

The following shows how to generate the MicroPython image from the source code for the ESP32 board.

The operating system is Debian 9, previously encountered for the esptool and Adafruit-ampy utilities

MicroPython – Python on embedded devices

Log on  with the operating system user on Debian 9, sviluppo in our case; under the home folder  create the Micropython folder and inside this folder the  esp32 folder

The MicroPython source code is available at the following link

Github Micropython

Instructions to build the firmware for the ESP32 are available at the link

MicroPython esp32

Clone the repository

Go into  micropython/ports/esp32 folder

Run

The command releases the git hash for the supported espidf

At the time of our compilation the result is as follows

Go into  /home/sviluppo/Micropython/esp32 folder and clone ESPIDF

Checkout with the hash obtained above

Run

We follow the instructions at the link

Cross compiler

to install the cross compiler; install the prerequisites for building

Download the cross compiler

Create the  esp folder under /home/sviluppo/Micropython/esp32

Unpack the cross compiler in esp

Add the binary folder of the cross compiler to the PATH envinronment variable

Go into the following folder

and create the makefile file with the following code inside

Go into the micropython folder available in /home/sviluppo/Micropython/esp32

Run

to add external dependencies.

Next step is the MicroPython cross compiler build

Finally we can build the ESP32  firmware with the following commands

The firmware is generated under ports/esp32/build with the name firmware.bin.

Proceed to load the firmware with the commands

In our case, the firmware upload was successful with the command

It is also possible to load the firmware.bin image with the commands

where  /dev/ttyXXX is replaced with the actual serial port to which we connect the ESP32 board.

In the next article we’ll compile the nodemcu firmware for ESP32

ESP32 – Nodemcu firmware compiling

MicroPython – MicroPython compiling for ESP8266 with additional modules

After the firmware build of the MicroPython firmware for esp8266 in the previous article

MicroPython – MicroPython compiling for ESP8266

we now show how build a module inside the firmware; this option optimizes the module execution and minimizes the size of the same on the device; the module is frozen into the firmware.

With the firmware compiled with the defaults, the following modules are available, listed in the REPL console with the command

standardmodulesNow let’s try to compile the firmware with the mqtt modules already inside. For this purpose, the module sources are copied to the umqtt folder under modules

umqttfolderWe proceed to recompile the firmware. From micropython/ports/esp8266 we run the following commands

We can see from the compilation log, that these modules are placed in the frozen state

frozenmodulesAfter uploading this firmware we obtain the following list of modules inside the firmware

firmwarewithmodulesIt is also possible to create the firmware with the modules not compiled and optimized, by copying the sources in the scripts folder under esp8266; in the specific case the sources must be placed as shown below

The modules are always visible in the firmware, but not optimized, so if you need some module it is convenient to copy it on the device during the coding  and in the last phase of the project compile the firmware with the frozen modules.

 

 

MicroPython – MicroPython compiling for ESP8266

After using in some examples the MicroPython firmware on the ESP8266 board

MicroPython – Nodes examples with DHT11, Relay and MQTT

this article shows how to generate the MicroPython firmware for the ESP8266 board.

The operating system used for this task is Debian 9, already encountered when we analyzed  the esptool utility

MicroPython – Python on embedded devices

Log on  with the operating system user on Debian 9, sviluppo in our case; under the home folder  create the Micropython folder and inside this folder the  esp8266 folder

The MicroPython source code is available at the following link

Github Micropython

Instructions to build the firmware for the ESP8266 are available at the link

MicroPython esp8266

Clone the repository

Download the cross compiler, as described here

Cross compiler

As indicated in the link above, download the source of the cross compiler always from the folder esp8266

Install the prerequisites for building

Proceed to the build of the cross compiler with the following commands

At the end of the build add the binary folder of the cross compiler to the PATH envinronment variable

Go into the micropython folder available under ~/Micropython/esp8266

Run

to add external dependencies.

Next step is the MicroPython cross compiler build

Finally we can build the ESP8266 firmware with the following commands

The firmware is generated under ports/esp8266/build folder with the name firmware_combined.bin.

Proceed to load the firmware with the command

where  /dev/ttyXXX is repalced with the actual serial port to which we connect the ESP8266 board.

In our case, the firmware upload was successful with the command

It is also possible to load the firmware_combined.bin image with the command

In the next article we’ll  analyze how to build the MicroPython firmware adding into the image additional MicroPython modules

MicroPython – MicroPython compiling for ESP8266 with additional modules

ESP32 Wifi-Bluetooth Module

In this article we describe briefly the ESP32  chip from Espressif

ESP32

This lower power SOC  contains a 32 bit MCU  with bluetooth and wifi modules. At the Espressif web site we can find the detailed informations about the ESP32

ESP32 Resources

The device datasheet is available in the following pdf document

ESP32 Datasheet

The ESP32 modules are available individually or in a development kits; the last system simplifies its usage as the development kit contains all the hardware to use rapidly the soc device; we are already ready to load the firmware and use the device.

On internet various web sites describe home automation or iot projects using this soc.

A reference site for the ESP32  is

esp32

At above link we can find the various development platforms utilized  for the ESP32. The most relevant  are

  • Arduino Ide

ESP32 Arduino

  • ESP-IDF

ESP32 IDF

  • Micropython

MicroPython

  • PlatformIO

PlatformIO

  • Firmware Lua

LuaNode

Lua-RTOS-ESP32

Nodemcu Development

We can buy the ESP32 modules/dev kits from various internet online websites, for example ebay

ESP32 on ebay

Different ESP32  modules are available from different vendors

Espressif esp-wroom-32

AI-Thinker esp32s

At the link

http://esp32.net/

different hardware configurations available are listed.

As development kits we report

AI-Thinker NodeMCU-32S

DoIT ESP32 Dev Kit

There are development kits based on esp32 that also integrate a LORA wireless  module internally

Lora

We report for example the following

Heltec Wifi LoRa 32

TTGO LoRa32

In the next articles we’ll describe how to build firmwares and use the ESP32 MCU.

Nodemcu Enduser_setup module lua sample(part2)

After the firmware build and its upload to the nodemcu dev kit, we connected a switch to pin D5, as shown in the previous article

Nodemcu Enduser_setup module lua sample(part1)

We finally can upload some sample code in which we use the enduser_setup module

Open ESPlorer and load the following sample code

  • webserver.lua

  • riasserawifi.lua

  • init.lua

 It is possible to download the above samples at the following link

 Sample code

Here is the documentation about the enduser_setup module

enduser_setup module documentation

The example consists of three files:

  1. init.lua:  It is executed at the startup of the esp8266.
  2. riazzerawifi.lua: It starts the portal to connect and save the configuration to your Access Point.
  3. webserver.lua:  It starts the webserver sample on the nodemcu.

As you can see from the code in init.lua, when the pin D5 is in the state HIGH, we start the portal using enduser_setup module. In the case in which the pin D5 is in the state LOW the  esp8266 acquires the IP from an Access Point defined previously after which the test webserver starts.

To save the access point confguration to which we want to connect we place the switch in order to have the HIGH input on pin D5 and reboot the card.

From a PC we can observe the presence of another access point, defined in the file riazzerawifi.lua

composed by Mynode string + ChipID module

nodemcu portal wifiWe can connect to this access point and  via browser we  access to the portal at the ip address 192.168.4.1

Login portal wifi nodemcuSelect or enter the SSID of an access point providing the correct   password. After the connection reposition the switch to have  the LOW state  for pin D5 and reboot the nodemcu dev kit.

Now the system will automatically connect to the SSID defined previously and starts the example of the web server.

Please refer to the Lua documentation nodemcu for further study and usable modules

LUA Nodemcu Documentation

Nodemcu Enduser_setup module lua sample(part1)

In the previous article we showed a sample LUA code for ESP8266

Lua sample code for esp8266

Let us now see an example in which we’ll use the enduser_setup Lua module.

As a first step we compile the nodemcu firmware by including the enduser_setup module. We have to apply the same steps discussed in the build process article

Nodemcu firmware build

editing the app/include/user_modules.h file and uncommenting the line

After the building and firmware upload to the device, we use a switch connected to nodemcu dev kit as shown in the picture

reset access point nodemcu

The pin D5 can be connected to a low or high input voltage. Based on the input voltage we can change the behavior of the system.

Note: The Pin D5 in this specific example has been used as Input Pin; in the case of use as Output Pin, you must insert a resistor to limit the output current, as specified in the link

GPIO Pin Allocations

In the next article we’lll upload a LUA sample code with enduser_setup module enabled and we’ll utilize it to manage the wifi connections

Nodemcu Enduser_setup module lua sample(part2)

Lua sample code for esp8266

As mentioned in the previous article

how to upload nodemcu firmware with esptool

we are now ready to upload some example code on ESP8266 system.

We follow the LUA Nodemcu documentation

Nodemcu LUA Documentation

and upload a simple http server on the system.

Using ESPlorer  we  upload the following code, a modified version of the code available on the github. Modify the fields “SSID” and “password” with the the values of your Wi-fi Router.

webserver pin

Save the file as ipstatico.lua. With ESPlorer upload the file to nodemcu devkit with “Save to ESP” button .
Create a second file named init.lua

Save this file on the device.

Reboot the device with the reset command on ESPlorer tool and from the ESPlorer  command bar execute

ESPlorerThis command  provides us the ip acquired by the device. We are able now to access with a browser to the assigned ip address, discovered above, and interact with a small interface that allows us to activate or not the PIN1 output

webserverlua

With this method, however, we need to know the Access Point to which you must connect. To overcome this limitation, we can use the enduser_sertup module

Enduser_setup module

With this module we start the ESP8266 device as an access point with a portal on which we can enter the credentials of the access point which we  want to connect.

In the next article we’ll build the nodemcu firmware by adding the  enduser setup module, not available in the standard firmware, and we will do the same example using this  module

Enduser_setup module sample