Difference: CompilingNopMicroPython (1 vs. 9)

Revision 92020-10-12 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Changed:
<
<
When trying to compile the ESP32 port of MicroPython on an Ubuntu-20.04 system I see the following error:
>
>
When trying to compile the ESP32 port of MicroPython on an Ubuntu-20.04 system, I see the following error:
  compileError.png
Changed:
<
<
As the message states we are running a version of pyparsing which is too recent for the ESP_IDF development environment and we must create a virtual environment for Python3 with an older version the pyparsing.
>
>
As the message states, we are running a version of pyparsing which is too recent for the ESP_IDF development environment and we must create a virtual environment for Python3 with an older version of pyparsing.
  This is how I did it:
Line: 12 to 12
 This is how I did it:

First I created a directory ~/pythonEnvironments in my home directory.
Then I created a virtual environment mp_env for MicroPython compilation:

Added:
>
>
 
python3 -m venv mp_env
Changed:
<
<
Once the environment is created you can activate it:
>
>
Once the environment is created, I can activate it:
 
source mp_env/bin/activate
Changed:
<
<
In your new environment you can use pip to load the modules you need with the correct version numbers:
>
>
In my new environment I can use pip to load the modules I need with the correct version numbers:
 
pip3 install pyparsing==2.3.1
pip3 install pyserial
Line: 25 to 28
  virtualEnv.png
Changed:
<
<
As soon as you are done you can deactivate the environment and return to the standard Python environment with the deactivate command.
>
>
As soon as I am done I can deactivate the environment and return to the standard Python environment with the deactivate command.
 

Freezing modules into the MicroPython binary

Changed:
<
<
We want to give students easy access to drivers for the sensors we use during the course. If we compile and freeze these modules into the MicroPython binary, then these module are available for import without the necessity to upload them to the ESP32 before use. in addition this method frees valuable RAM space, a resource that is very scarce on the machine.
>
>
We want to give students easy access to drivers for the sensors that we use during the course. If we compile and freeze these modules into the MicroPython binary, then these modules are available for import without the necessity to upload them to the ESP32 before use. in addition, this method frees valuable RAM space, a resource that is very scarce on the machine.
  Freezing of MicroPython modules into the binary is pretty easy: We must simply copy the Python code into the ports/esp32/modules directory of the MicroPython source before compilation. Here is the list of additional modules that are currently included:
Line: 38 to 41
  Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data sent through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.
Changed:
<
<
In order to make the user module known and enabled by MicroPython we must compile the interpreter with the following command (valid for the dht11Raw module):
>
>
In order to make the user module known and enabled by MicroPython, we must compile the interpreter with the following command (valid for the dht11Raw module):
  make USER_C_MODULES=../../../user_modules CFLAGS_EXTRA=-DMODULE_DHT11RAW_ENABLED=1

Revision 82020-06-29 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 43 to 40
  In order to make the user module known and enabled by MicroPython we must compile the interpreter with the following command (valid for the dht11Raw module):
Changed:
<
<
make USER_C_MODULES=../../../user_modules -CFLAGS_EXTRA=-DMODULE_DHT11RAW_ENABLED=1
>
>
make USER_C_MODULES=../../../user_modules CFLAGS_EXTRA=-DMODULE_DHT11RAW_ENABLED=1
  For more details about C user modules in MicroPython see https://docs.micropython.org/en/latest/develop/cmodules.html and
https://micropython-usermod.readthedocs.io/en/latest/usermods_01.html

Revision 72020-06-29 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 42 to 45
  make USER_C_MODULES=../../../user_modules -CFLAGS_EXTRA=-DMODULE_DHT11RAW_ENABLED=1
Changed:
<
<
For more details about C user modules in MicroPython see https://docs.micropython.org/en/latest/develop/cmodules.html
>
>
For more details about C user modules in MicroPython see https://docs.micropython.org/en/latest/develop/cmodules.html and
https://micropython-usermod.readthedocs.io/en/latest/usermods_01.html
  The source code for the example module described in the docs and the dht11Raw module can be found in this gzipped tar archive:

Revision 62020-05-13 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 50 to 47
 The source code for the example module described in the docs and the dht11Raw module can be found in this gzipped tar archive:

https://iotworkshop.africa/pub/IoT_Course_English/CompilingNopMicroPython/user_modules.tar.gz

Added:
>
>

Debugging MicroPython

When using the ESP32 port of MicroPython you can use the logging facilities provided by ESP-IDF. Typically you define a DEBUG_printf function of this type:

debugPrintf.png

The ESP-IDF logging facility knows 5 levels of error logging:

  • ESP_LOGE: for errors
  • ESP_LOGW: for warnings
  • ESP_LOGI: for information messages (this level has been chosen in our example above)
  • ESP_LOGD: for debugging
  • ESP_LOGV: for verbose
You can set the logging level up to which you want to see the messages with

esp.osdebug(0,esp.LOG_INFO)

setting the level to "information". In this case LOGE, LOGW and LOGI messages will be shown but not LOGD and LOGV messages. If you set

esp.osdebug(None)

no messages will be shown.

The screen dump below shows the output of help(esp) with all the methods and constants defined in this module.

espModule.png

  -- Uli Raich - 2020-04-29
Line: 62 to 84
 
META FILEATTACHMENT attachment="modules.png" attr="" comment="" date="1588186737" name="modules.png" path="modules.png" size="35152" user="UliRaich" version="1"
META FILEATTACHMENT attachment="user_modules.tar.gz" attr="" comment="" date="1588408264" name="user_modules.tar.gz" path="user_modules.tar.gz" size="2205" user="UliRaich" version="1"
META FILEATTACHMENT attachment="upysh.png" attr="" comment="" date="1588841730" name="upysh.png" path="upysh.png" size="16059" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="debugPrintf.png" attr="" comment="" date="1589383416" name="debugPrintf.png" path="debugPrintf.png" size="20200" user="UliRaich" version="1"
META FILEATTACHMENT attachment="espModule.png" attr="" comment="" date="1589383922" name="espModule.png" path="espModule.png" size="50479" user="UliRaich" version="1"

Revision 52020-05-07 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 34 to 37
  modules.png
Deleted:
<
<

Making upysh commands available

In boot.py you find the commands executed when booting up MicroPython. This file is created in ../ports/esp32/modules/inisetup.py. I added the command:

from upysh import *

which gives you access to all upysh commands. Type man to see the commands available.

upysh.png

 

Including user C modules

Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data sent through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.

Revision 42020-05-07 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 34 to 34
  modules.png
Added:
>
>

Making upysh commands available

In boot.py you find the commands executed when booting up MicroPython. This file is created in ../ports/esp32/modules/inisetup.py. I added the command:

from upysh import *

which gives you access to all upysh commands. Type man to see the commands available.

upysh.png

 

Including user C modules

Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data sent through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.

Line: 58 to 67
 
META FILEATTACHMENT attachment="virtualEnv.png" attr="" comment="" date="1588184280" name="virtualEnv.png" path="virtualEnv.png" size="165214" user="UliRaich" version="1"
META FILEATTACHMENT attachment="modules.png" attr="" comment="" date="1588186737" name="modules.png" path="modules.png" size="35152" user="UliRaich" version="1"
META FILEATTACHMENT attachment="user_modules.tar.gz" attr="" comment="" date="1588408264" name="user_modules.tar.gz" path="user_modules.tar.gz" size="2205" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="upysh.png" attr="" comment="" date="1588841730" name="upysh.png" path="upysh.png" size="16059" user="UliRaich" version="1"

Revision 32020-05-02 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 7 to 7
  compileError.png
Changed:
<
<
As the message states we are running a version of pyparsing which is too recent for the ESP_IDF development environment and we must create a virtual environment for Python3 with the correct version the this module.
>
>
As the message states we are running a version of pyparsing which is too recent for the ESP_IDF development environment and we must create a virtual environment for Python3 with an older version the pyparsing.
  This is how I did it:
Changed:
<
<
First I created a directory ~/pythonEnvironments in my home directory.
Then I create a virtual environment mp_env for MicroPython compilation:
>
>
First I created a directory ~/pythonEnvironments in my home directory.
Then I created a virtual environment mp_env for MicroPython compilation:
 
python3 -m venv mp_env

Once the environment is created you can activate it:

Line: 16 to 15
 
python3 -m venv mp_env

Once the environment is created you can activate it:

Deleted:
<
<
 
source mp_env/bin/activate
Changed:
<
<
Once you are in your new environment you can use pip to load the modules you need with the correct version numbers:

pip3 install pyparsing=2.3.1
>
>
In your new environment you can use pip to load the modules you need with the correct version numbers:
pip3 install pyparsing==2.3.1
 pip3 install pyserial
Changed:
<
<
Once this is accomplished compilation of MicroPython works as expected:
>
>
When this is accomplished compilation of MicroPython works as expected:
  virtualEnv.png
Line: 39 to 36
 

Including user C modules

Changed:
<
<
Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data send through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.
>
>
Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data sent through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.

In order to make the user module known and enabled by MicroPython we must compile the interpreter with the following command (valid for the dht11Raw module):

make USER_C_MODULES=../../../user_modules -CFLAGS_EXTRA=-DMODULE_DHT11RAW_ENABLED=1

For more details about C user modules in MicroPython see https://docs.micropython.org/en/latest/develop/cmodules.html

 
Changed:
<
<
MicroPython in the compiled with the command:
>
>
The source code for the example module described in the docs and the dht11Raw module can be found in this gzipped tar archive:
 
Changed:
<
<
make USER_C_MODULES=../../../user_modules
>
>
https://iotworkshop.africa/pub/IoT_Course_English/CompilingNopMicroPython/user_modules.tar.gz
  -- Uli Raich - 2020-04-29
Line: 54 to 57
 
META FILEATTACHMENT attachment="compileError.png" attr="" comment="" date="1588183347" name="compileError.png" path="compileError.png" size="61143" user="UliRaich" version="1"
META FILEATTACHMENT attachment="virtualEnv.png" attr="" comment="" date="1588184280" name="virtualEnv.png" path="virtualEnv.png" size="165214" user="UliRaich" version="1"
META FILEATTACHMENT attachment="modules.png" attr="" comment="" date="1588186737" name="modules.png" path="modules.png" size="35152" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="user_modules.tar.gz" attr="" comment="" date="1588408264" name="user_modules.tar.gz" path="user_modules.tar.gz" size="2205" user="UliRaich" version="1"

Revision 22020-05-01 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

Line: 34 to 37
  modules.png
Added:
>
>

Including user C modules

Sometimes it may be needed to write modules in C, which can be called by MicroPython. A typical example is the readout of the DHT11 when we want to get access to the raw data send through the DHT11 proprietary protocol. The serial data bits come in too fast to be treated by Python code. To include such a module we add a user_module (could be any name) directory in which we create the module directory (dht11Raw in case of the DHT11). Into this directory we put the C code and a micropython.mk file.

MicroPython in the compiled with the command:

make USER_C_MODULES=../../../user_modules

 -- Uli Raich - 2020-04-29

Comments

Revision 12020-04-29 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WebHome"

Compiling Micropython

Forcing the correct module versions

When trying to compile the ESP32 port of MicroPython on an Ubuntu-20.04 system I see the following error:

compileError.png

As the message states we are running a version of pyparsing which is too recent for the ESP_IDF development environment and we must create a virtual environment for Python3 with the correct version the this module.

This is how I did it:

First I created a directory ~/pythonEnvironments in my home directory.
Then I create a virtual environment mp_env for MicroPython compilation:

python3 -m venv mp_env

Once the environment is created you can activate it:

source mp_env/bin/activate

Once you are in your new environment you can use pip to load the modules you need with the correct version numbers:

pip3 install pyparsing=2.3.1
pip3 install pyserial

Once this is accomplished compilation of MicroPython works as expected:

virtualEnv.png

As soon as you are done you can deactivate the environment and return to the standard Python environment with the deactivate command.

Freezing modules into the MicroPython binary

We want to give students easy access to drivers for the sensors we use during the course. If we compile and freeze these modules into the MicroPython binary, then these module are available for import without the necessity to upload them to the ESP32 before use. in addition this method frees valuable RAM space, a resource that is very scarce on the machine.

Freezing of MicroPython modules into the binary is pretty easy: We must simply copy the Python code into the ports/esp32/modules directory of the MicroPython source before compilation. Here is the list of additional modules that are currently included:

modules.png

-- Uli Raich - 2020-04-29

Comments

<--/commentPlugin-->

META FILEATTACHMENT attachment="compileError.png" attr="" comment="" date="1588183347" name="compileError.png" path="compileError.png" size="61143" user="UliRaich" version="1"
META FILEATTACHMENT attachment="virtualEnv.png" attr="" comment="" date="1588184280" name="virtualEnv.png" path="virtualEnv.png" size="165214" user="UliRaich" version="1"
META FILEATTACHMENT attachment="modules.png" attr="" comment="" date="1588186737" name="modules.png" path="modules.png" size="35152" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback