Tag Archives: espressif

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

MicroPython – MicroPython program structure

After reviewing various development tools for MicroPython in previous articles

MicroPython – Development tools Ampy – Eric

MicroPython IDE uPyCraft

in this article we briefly describe the main features of MicroPython. In particular, we examine the documentation relating to the ESP8266, but the concepts can also be extended to the other boards.

The documentation on the ESP8266 soc and MicroPython  is available at the link

ESP8266 MicroPython Documentation

At the link we can find all the informations necessary to implement the code on the card and the features of MicroPython as well as the differences compared to Python.

Here are the main points for coding in MicroPython:

  • MicroPython has a REPL (Read Evaluate Print Loop) console through the serial port to which the device is connected on which we can give the various MicroPython commands interactively.
  • The REPL console can also be accessed via connection to the IP address of the device by enabling the WEBREPL (Web Browser Interactive prompt) console

WebREPL Documentation

importing the webrepl package, enabling it and starting it at each device restart. To access the configured device, we can use the link

WEBREPL Access

or locally cloning it  from github

  • At the start of the device the system runs boot.py and after main.py.
  • The MicroPython libraries are available on the github at the link

MicroPython libraries

  • Additional packages

The additional modules can be downloaded from the link of the libraries presented above or downloaded with the upip utility (Package Manager) from the REPL console if available in the Python Package Index (PyPI) repository

PYPI

as described below

upip

Below is a simple example that connects to the router and allows us to access the MicroPython console with the browser and WEBREPL.

  • boot.py code

At the first access it is required to enable webrepl to be executed in the REPL console with the command

we can activate the service and the access password.

The procedure generates the webrepl_cfg.py file on the device.

After setting up and restarting, we access the web console by opening the locally cloned webrepl.html file with a browser

WebreplPressing connect and after entering the password ,set in the initial setup, we access the console

WebreplConnectedNow we install from the WEBREPL console, for example, the stat module using upip

To paste commands  execute Ctrl+A e Ctrl+V

WebreplupipIn this case the package was taken from the PYPI repository, unpacked and installed on the device.

We have noticed that some modules, although available on the repository, give an error during installation with upip; these modules are installed directly without using the upip utility,but by downloading the library from the site listed above and transferring the code to the device.

Here is the link of the code shown above

Webreplsample

Another option available is to build  the firmware with the required modules.

In the next article we will examine examples similar to what was done with LUA on ESP8266 in previous articles

MicroPython – Nodes examples with DHT11, Relay and MQTT

 

 

 

Micropython – Development tools Ampy – Eric

After the  uPyCraft  intallation in the previous article

MicroPython – IDE MicroPython uPyCraft

let’s now look at other tools available for the development in MicroPython for various platforms.

This article shows the operations to be performed on Windows and Linux.

First Python package to install is Ampy (Adafruit MicroPython Tool)

ampy

The tool is available in the python repositories, so it can be installed using the  pip tool.

In Windos run in a dos command prompt

Similarly in Linux run in a shell

The available commands are listed running

ampyAmpy allows the transfer, creation, viewing, and execution of files on the device.

As for the IDE you can install Eric, generic Python IDE

Eric

Eric does not allow communication from the IDE with the device as seen with uPyCraft; this task is delegated to Ampy. For the installation proceed as follows:

  • For Linux Debian 9 just run

The tool is available among the development tools; at the first execution it requires default settings

ericSettingsWe define the workspace location

ericWorkspaceand we have the access to the IDE

eric

  • For Windows download the zip

Eric

Unzip the zip into a folder from which we run it; install the prerequisites

Perform the eric installation at this point by double clicking on install.py

ericInstallWindowsThe program checks the prerequisites and completes the installation

ericWindowsProcedure

Clicking twice on eric6.py or running eric6 from a dos command prompt we run the program in the same way as seen for Linux Debian

ericWindows

In the next article we will briefly examine how a MicroPython program is structured

MicroPython – MicroPython program structure

 

Micropython – MicroPython IDE uPyCraft

After installing the firmware on the Nodemcu esp8266 DevKit board

MicroPython Firmware

let us now examine a development tool can be suitable for the development of Python code.

A tool that allows both to write code and upload it to the device is uPyCraft

uPyCraft

The tool currently works for Windows and from version 0.30 is also available for Linux; the source code is available at the link

uPyCraft Source

Here are the steps for Windows and Linux.

  • Windows

Once downloaded the package we must  run it as an administrator; the installation of the Monaco font is required

monaco-font

After the font installation,  we have the access to the IDE

upycraft-v0-29We set the Location in Tools->Preferences->Language Location

upycraftlocation

and the serial port paramenters in Tools->Preferences->Serial

upycraftserialsettingsWe plug the device into an USB port and set the serial port on uPyCraft

upycraftserialWe choose the device type; in this case it is ESP8266

upycraftdeviceBy clicking on the connection icon we access to the device and view the files on it

upycraftconnectionThe firmware installation expands on the device only the Python file boot.py

upycraftfilesystemThe tool allows to download examples of MicroPython code for the board, blink.py for example

examplesClicking the “Download and Run” button we load the code onto the device and run it

blinkIn this example the led of the Nodemcu DevKit blinks.

  • Linux

The tool is similar in the Linux version; once downloaded the package to which we have to assign  the execution right we run it. We must assign to the user the access to the serial port with the command, already seen above

In our case, on Debian 9, we have the following screens similar to what we saw on Windows.

In the uPyCraft IDE

upycraft-v0-30linuxWe set the Location in Tools->Preferences->Language Location

upycraftlocationlinux

and the serial port paramenters in Tools->Preferences->Serial

upycraftserialsettingslinuxWe plug the device into an USB port and set the serial port on uPyCraft

upycraftseriallinuxWe choose the device type; in this case it is ESP8266

upycraftdevicelinuxBy clicking on the connection icon we access to the device and view the files on it

upycraftconnectionlinuxThe firmware installation expands on the device only the Python file boot.py

upycraftfilesystemlinuxThe tool allows to download examples of MicroPython code for the board, blink.py for example

exampleslinuxClicking the “Download and Run” button we load the code onto the device and run it

blinklinuxAs in Windows the led of the Nodemcu DevKit blinks..

In version 0.30 for Windows we noticed some bugs, so for this operating system we continue to use the uPyCraft  version 0.29.

Further informations about uPyCraft can be found at the following site

uPyCraft Documentation

In the next article we will discuss another Python development tool

MicroPython – Development tools Ampy – Eric

MicroPython – Python on embedded devices

In this article we begin to treat MicroPython

MicroPython

an implementation of Python3

Python

for embedded devices.

Various images are available on the MicroPython website for different devices, including the modules esp8266 and esp32

MicroPython Dowloads

We start our tests with a Nodemcu esp8266 DevKit

Nodemcu Devkit

We proceed to load the firmware  on this card.

The Micropython site also refers how to load the firmware on the cards; these informations are available at the link

MicroPython Tutorial for esp8266

To load the firmware we always use the tool esptool, also available on the Python repository.

To be able to use it, we need to install Python3 on our development platform. Here are the steps to follow for Windows and Linux.

  • Windows

For windows we must first install the Python3 environment, available at the following link

Python for Windows

In our case, we downloaded the  version 3.6.4 for 64-bit systems. We installed the package  with administrative rights

setuppythonAfter proceeding to add Python in the Path we click “Install Now”

pythonsetupendAfter the installation, we open a dos command propmt and check the installed Python version

pythonversionAlways from the dos command prompt we proceed to the installation of esptool with the command

esptoolinstallationAt this point we can proceed to the MicroPython firmware upload on the Nodemcu esp8266 DevKit. Of course, it is necessary to have the serial-ttl drivers installed for your DevKit model on Windows. Now go into  the folder where the firmware has been downloaded  and run the following  commands from the dos command prompt

erase_flashProceed to load the firmware

firmware_flashOnce the firmware is installed  we log on the Python console using, in our case with the nodemcu card DevKit, the same port already used to load the firmware.

On Windows we can use Putty

Putty

and set the serial connection to 115200 baud rates

repl_putty

  • Linux

For Linux we use the Debian 9 distribution, but the procedure can be extended to other distributions. After installing Debian 9 , similar to version 8

Debian 8

we proceed to the installation of Python3 and esptool from a Linux shell

Add the user used on Debian to the dialout group

In our case, using  sviluppo as a user, the command is as follows

Let’s move on to install the Python esptool package

We can then proceed with the installation of the firmware in the same way as done on Windows.

We check on which serial port the card is available (ttyUSBX)

ttylinuxWe perform a flash erase and firmware upload

To log on the DevKit we use screen

Here is the manual of the tool

Screen Manual

To detach from screen press

instead to resume run

To quit screen

Once connected you get the same result as Windows

screenIn the next article we will begin to see which IDEs can be used to create and load our Python code

MicroPython IDE uPyCraft