Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing 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![]() https://micropython-usermod.readthedocs.io/en/latest/usermods_01.html ![]() |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing 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![]() 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: |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing 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 MicroPythonWhen 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:![]()
![]() | |||||||
-- ![]() | ||||||||
Line: 62 to 84 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing the correct module versions | ||||||||
Line: 34 to 37 | ||||||||
![]() | ||||||||
Deleted: | ||||||||
< < | Making upysh commands availableIn 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.![]() | |||||||
Including user C modulesSometimes 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: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing the correct module versions | ||||||||
Line: 34 to 34 | ||||||||
![]() | ||||||||
Added: | ||||||||
> > | Making upysh commands availableIn 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.![]() | |||||||
Including user C modulesSometimes 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 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing the correct module versions | ||||||||
Line: 7 to 7 | ||||||||
![]() | ||||||||
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_envOnce the environment is created you can activate it: | ||||||||
Line: 16 to 15 | ||||||||
python3 -m venv mp_envOnce 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: | |||||||
![]() | ||||||||
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 | |||||||
-- ![]() | ||||||||
Line: 54 to 57 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Compiling MicropythonForcing the correct module versions | ||||||||
Line: 34 to 37 | ||||||||
![]() | ||||||||
Added: | ||||||||
> > | Including user C modulesSometimes 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 | |||||||
-- ![]() Comments |
Line: 1 to 1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
Added: | |||||||||
> > |
Compiling MicropythonForcing the correct module versionsWhen trying to compile the ESP32 port of MicroPython on an Ubuntu-20.04 system I see the following error:![]() Then I create a virtual environment mp_env for MicroPython compilation: python3 -m venv mp_envOnce the environment is created you can activate it: source mp_env/bin/activateOnce 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 pyserialOnce this is accomplished compilation of MicroPython works as expected: ![]() Freezing modules into the MicroPython binaryWe 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:![]() ![]() Comments
|