Tags:
tag this topic
create new tag
view all tags
---+ A Custom !MicroPython binary ---++ Introduction We have already seen how to create a custom !MicroPython binary when we integrated all the modules needed for the WEB server. In case of the camera driver things are even a bit more tricky. The driver integrated into esp-idf is written in C and we must get access to its functions through !MicroPython. We therefore need a !MicroPython to C interface. A simple example on how to do this, can be found [[https://docs.micropython.org/en/latest/develop/cmodules.html][this chapter ]]of the !MicroPython manual. ---++ Creating a new _port_ in !MicroPython In addition to the diver itself we must enable the external psram needed to store the rather big image data. You can see how this is done by looking at the esp32 port of !MicroPython. In the _boards_ sub-directory you will find folders for different board configurations: * GENERIC * GENERIC_D2WD * GENERIC_SDRAM this is the one we are interested in * TINYPICO In order not to mess up the original code I created a new port called esp32-cam by copying all files from ports/esp32 to ports/esp32-cam. In the boards folder I created the folder ESP32_CAMERA with the files * mpconfigboard.h with the following contents: <literal>#define MICROPY_HW_BOARD_NAME "ESP32 module"<br />#define MICROPY_HW_MCU_NAME "ESP32"<br />#define MODULE_EXAMPLE_ENABLED (1)<br />#define MODULE_ESP32_CAMERA_ENABLED (1) </literal> * and mpconfigboard.mk <literal>SDKCONFIG += boards/sdkconfig.base<br />SDKCONFIG += boards/sdkconfig.spiram<br />SDKCONFIG += boards/sdkconfig.camera </literal> boards/sdconfig.camera contains the definitions needed for compilation of the camera driver: <literal># ESP32-CAMERA<br />CONFIG_CAMERA_SUPPORT=y<br />CONFIG_OV2640_SUPPORT=y<br />#CONFIG_OV7725_SUPPORT=y </literal> Finally we must modify the port's Makefile to include compilation of the camera driver. I have attached the modified Makefile to this page: %ATTACHURL%/Makefile First we have to specify the additional include files needed:<br /><br /> <literal>ifeq ($(CONFIG_CAMERA_SUPPORT),y)<br />INC_ESPCOMP += -I$(ESPCOMP)/esp32-camera/driver/include<br />INC_ESPCOMP += -I$(ESPCOMP)/esp32-camera/driver/private_include<br />INC_ESPCOMP += -I$(ESPCOMP)/esp32-camera/conversions/include<br />INC_ESPCOMP += -I$(ESPCOMP)/esp32-camera/conversions/private_include<br />INC_ESPCOMP += -I$(ESPCOMP)/esp32-camera/sensors/private_include<br />endif</literal> Then we must add the additional C sources to be compiled:<br /><br /> <literal>ifeq ($(CONFIG_CAMERA_SUPPORT),y)<br />ESPIDF_CAMERA_O = $(patsubst %.c,%.o,\<br /> $(wildcard $(ESPCOMP)/esp32-camera/driver/*.c) \<br /> $(wildcard $(ESPCOMP)/esp32-camera/conversions/*.c) \<br /> $(wildcard $(ESPCOMP)/esp32-camera/sensors/*.c) \<br /> )<br />endif</literal> and finally we add the camera object files created this way.<br /><br /> <literal>ifeq ($(CONFIG_CAMERA_SUPPORT),y)<br />$(eval $(call gen_espidf_lib_rule,esp32_camera,$(ESPIDF_CAMERA_O)))<br />endif </literal> The camera driver is not a standard component in esp-idf and must be added there. Go to the component directory of your esp32 development environment esp-idf and clone the driver into this place. You will find it on https://github.com/espressif/esp32-camera/tree/master/driver ---++ The !MicroPython C module for the camera driver I based my !MicroPython C module on work done by shariltumin: [[https://github.com/shariltumin/esp32-cam-micropython]] but I had to extend it quite a bit to be able to access the other control parameters the driver offers and to be able to read back the setting. The extended C-module and Makefile are attached here: %ATTACHURL%/modcamera.c %ATTACHURL%/micropython.mk These files are stored in the folder user_modules/esp32_camera at the same level in the files system as the !MicroPython sources. To compile the custom version of !MicroPython you have to give the following commands, which I saved in a shell script: #!/bin/sh<br /># build Micropython with the integrated esp32-camera driver<br />#<br />make BOARD=ESP32_CAMERA ESPIDF=/opt/ucc/afnog/afnog-2020/esp32-cam/esp-idf-micropython clean<br />make BOARD=ESP32_CAMERA ESPIDF=/opt/ucc/afnog/afnog-2020/esp32-cam/esp-idf-micropython USER_C_MODULES=../../../user_modules<br /><br /> ESPIDF= ... specifies where to find the esp-idf and the camera driver. -- %USERSIG{UliRaich - 2020-01-25}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
EXT
Makefile
r1
manage
37.7 K
2020-03-05 - 09:12
UliRaich
mk
micropython.mk
r1
manage
0.6 K
2020-03-05 - 09:38
UliRaich
c
modcamera.c
r1
manage
27.0 K
2020-03-05 - 09:38
UliRaich
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2020-03-05
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
AFNOG Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback