From 0b9d18b0a412ace3dc3bd5462e249cdab173dfd3 Mon Sep 17 00:00:00 2001 From: Christopher Nadler <147471517+cnadler86@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:46:13 +0200 Subject: [PATCH 1/7] modcamera.h aktualisieren Default ov5640 only for esp32s3 --- src/modcamera.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modcamera.h b/src/modcamera.h index d16ef25..07b9890 100644 --- a/src/modcamera.h +++ b/src/modcamera.h @@ -86,7 +86,7 @@ defined(MICROPY_CAMERA_PIN_PCLK) && defined(MICROPY_CAMERA_PIN_VSYNC) && defined #define CONFIG_OV2640_SUPPORT 1 #endif -#ifndef CONFIG_OV5640_SUPPORT +#if !defined(CONFIG_OV5640_SUPPORT) && defined(CONFIG_IDF_TARGET_ESP32S3) #define CONFIG_OV5640_SUPPORT 1 #endif From 7de532a84545853a528f49b786645604f4f2396d Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Tue, 8 Oct 2024 09:44:06 +0200 Subject: [PATCH 2/7] clean test --- tests/esp32_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/esp32_test.py b/tests/esp32_test.py index dfa2169..16b65c6 100644 --- a/tests/esp32_test.py +++ b/tests/esp32_test.py @@ -1,5 +1,4 @@ from camera import Camera, FrameSize, PixelFormat -import uinspect as inspect def test_property_get_frame_size(): camera = Camera() From 8ecf844396f79e36f3d2a2ddbc5917af302cbcb7 Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Tue, 8 Oct 2024 08:08:14 +0000 Subject: [PATCH 3/7] Improved readme --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5dc8e8e..a996e83 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Camera API for micropython + [![ESP32 Port](https://github.com/cnadler86/micropython-camera-API/actions/workflows/ESP32.yml/badge.svg)](https://github.com/cnadler86/micropython-camera-API/actions/workflows/ESP32.yml) This project aims to support cameras in different ports in micropython, starting with the ESP32-Port and omnivision (OV2640 & OV5640) cameras. The project implements a general API for cameras in micropython (such as circuitpython have done). @@ -6,9 +7,11 @@ At the moment, this is a micropython user module, but it might get in the microp The API is stable, but it might change without previous anounce. ## Precomiled FW (the easy way) + If you are not familiar with building a custom firmware, you can go to the [releases](https://github.com/cnadler86/micropython-camera-API/releases) page and download one of the generic FWs that suits your board. ## Using the API + ```python from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling @@ -47,23 +50,29 @@ If you want more insides in the methods and what they actually do, you can find Notice that for the methods in here you need to prefix a get/set, depending that you want to do. ## Build your custom FW + ### Setup build environment (the DIY way) + To build the project, follow the following instructions: + - [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.3/esp32/get-started/index.html): I used version 5.2.2, but it might work with other versions (see notes). - Clone the micropython repo and this repo in a folder, e.g. "MyESPCam". I used the actual micropython master branch (between v1.23 and before 1.24). - You will have to add the ESP32-Camera driver (I used v2.0.12). To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main_esp32s3/idf_component.yml): -``` + +```yml espressif/esp32-camera: git: https://github.com/espressif/esp32-camera ``` -You can also clone the https://github.com/espressif/esp32-camera repository inside the esp-idf/components folder instead of altering the idf_component.yml file. + +You can also clone the repository inside the esp-idf/components folder instead of altering the idf_component.yml file. ### Add camera configurations to your board (Optional, but recomended) + To make things easier, add the following lines to your board config-file "mpconfigboard.h" with the respective pins and camera parameters. Otherwise you will need to pass all parameters during construction. Don't forget the empty line at the buttom. Example for xiao sense: -``` +```c #define MICROPY_CAMERA_PIN_D0 (15) #define MICROPY_CAMERA_PIN_D1 (17) #define MICROPY_CAMERA_PIN_D2 (18) @@ -88,17 +97,20 @@ Example for xiao sense: ``` ### Build the API + To build the project, you could do it the following way: ```bash -$ . /esp-idf/export.sh +. /esp-idf/export.sh $ cd MyESPCam/micropython/ports/esp32 $ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= clean $ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= submodules $ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= all ``` + if you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html). ## Notes + - The OV5640 pinout is compatible with boards designed for the OV2640 but the voltage supply is too high for the internal 1.5V regulator, so the camera overheats unless a heat sink is applied. For recording purposes the OV5640 should only be used with an ESP32S3 board. Frame sizes above FHD framesize should only be used for still images due to memory limitations. -- If your target board is a ESP32, I recomend using IDF >= 5.2, since older versions may lead to IRAM overflow during build. Alternatively you can modify your sdkconfig-file (see [issue #1](https://github.com/cnadler86/micropython-camera-API/issues/1)). \ No newline at end of file +- If your target board is a ESP32, I recomend using IDF >= 5.2, since older versions may lead to IRAM overflow during build. Alternatively you can modify your sdkconfig-file (see [issue #1](https://github.com/cnadler86/micropython-camera-API/issues/1)). From ae74b576bbf458ee9c400e6d32742c65d20b536e Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Tue, 8 Oct 2024 08:09:48 +0000 Subject: [PATCH 4/7] udate readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a996e83..3448545 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,10 @@ To build the project, you could do it the following way: ```bash . /esp-idf/export.sh -$ cd MyESPCam/micropython/ports/esp32 -$ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= clean -$ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= submodules -$ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= all +cd MyESPCam/micropython/ports/esp32 +make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= clean +make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= submodules +make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= all ``` if you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html). From 6e24c660bed765cd60f19a19f5bb89f2c6e17691 Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Wed, 9 Oct 2024 07:46:27 +0000 Subject: [PATCH 5/7] Update Readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3448545..46a8af1 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ camera.set_quality(10) You can get and set sensor properties by the respective methods (e.g. camera.get_brightness() or camera.set_vflip(True). See autocompletitions in Thonny in order to see the list of methods. If you want more insides in the methods and what they actually do, you can find a very good documentation [here](https://docs.circuitpython.org/en/latest/shared-bindings/espcamera/index.html). -Notice that for the methods in here you need to prefix a get/set, depending that you want to do. +Notice that for the methods in here you need to prefix a get/set, depending on what you want to do. ## Build your custom FW @@ -55,7 +55,7 @@ Notice that for the methods in here you need to prefix a get/set, depending that To build the project, follow the following instructions: -- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.3/esp32/get-started/index.html): I used version 5.2.2, but it might work with other versions (see notes). +- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.3/esp32/get-started/index.html): I used version 5.2.3, but it might work with other versions (see notes). - Clone the micropython repo and this repo in a folder, e.g. "MyESPCam". I used the actual micropython master branch (between v1.23 and before 1.24). - You will have to add the ESP32-Camera driver (I used v2.0.12). To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main_esp32s3/idf_component.yml): @@ -64,13 +64,13 @@ To build the project, follow the following instructions: git: https://github.com/espressif/esp32-camera ``` -You can also clone the repository inside the esp-idf/components folder instead of altering the idf_component.yml file. +Alternatively, you can clone the repository inside the esp-idf/components folder instead of altering the idf_component.yml file. -### Add camera configurations to your board (Optional, but recomended) +### Add camera configurations to your board (Optional, but recommended) -To make things easier, add the following lines to your board config-file "mpconfigboard.h" with the respective pins and camera parameters. Otherwise you will need to pass all parameters during construction. -Don't forget the empty line at the buttom. -Example for xiao sense: +To make things easier, add the following lines to your board config-file "mpconfigboard.h" with the respective pins and camera parameters. Otherwise, you will need to pass all parameters during construction. +Don't forget the empty line at the bottom. +Example for Xiao sense: ```c #define MICROPY_CAMERA_PIN_D0 (15) @@ -108,9 +108,9 @@ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOA make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD= all ``` -if you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html). +If you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html). ## Notes - The OV5640 pinout is compatible with boards designed for the OV2640 but the voltage supply is too high for the internal 1.5V regulator, so the camera overheats unless a heat sink is applied. For recording purposes the OV5640 should only be used with an ESP32S3 board. Frame sizes above FHD framesize should only be used for still images due to memory limitations. -- If your target board is a ESP32, I recomend using IDF >= 5.2, since older versions may lead to IRAM overflow during build. Alternatively you can modify your sdkconfig-file (see [issue #1](https://github.com/cnadler86/micropython-camera-API/issues/1)). +- If your target board is a ESP32, I recommend using IDF >= 5.2, since older versions may lead to IRAM overflow during build. Alternatively you can modify your sdkconfig-file (see [issue #1](https://github.com/cnadler86/micropython-camera-API/issues/1)). From c403821c7d2f94dce8e8e3d3edfeb0bc58cdfd23 Mon Sep 17 00:00:00 2001 From: Christopher Nadler <147471517+cnadler86@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:13:50 +0200 Subject: [PATCH 6/7] README.md aktualisieren --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46a8af1..9c817e2 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,13 @@ make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOA ``` If you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html). - ## Notes - The OV5640 pinout is compatible with boards designed for the OV2640 but the voltage supply is too high for the internal 1.5V regulator, so the camera overheats unless a heat sink is applied. For recording purposes the OV5640 should only be used with an ESP32S3 board. Frame sizes above FHD framesize should only be used for still images due to memory limitations. - If your target board is a ESP32, I recommend using IDF >= 5.2, since older versions may lead to IRAM overflow during build. Alternatively you can modify your sdkconfig-file (see [issue #1](https://github.com/cnadler86/micropython-camera-API/issues/1)). + +## Plans for the future +- [ ] imolrment structure in repo to include other boards like xiao sense +- [ ] harmonize properties to standard ones at API level, e.g. jpeg quality to the range 100=very good, 1/0= very bad +- [ ] edge case: enable usage of pins such as i2c for other applications +- [ ] provide examples in binary image with lfs-merge \ No newline at end of file From 11894baff9075f4dfabd976802378f82c58cec57 Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Thu, 10 Oct 2024 05:04:53 +0200 Subject: [PATCH 7/7] Improved readme. --- README.md | 13 +++++++------ src/modcamera.c | 8 ++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c817e2..acb2778 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ If you are not familiar with building a custom firmware, you can go to the [rele from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling # Camera construction and initialization +# These pins are just examples and if you use them just like that will get a watchdog error. Adapt them to your board! camera = Camera( data_pins=[1,2,3,4,5,6,7,8], vsync_pin=9, @@ -87,12 +88,12 @@ Example for Xiao sense: #define MICROPY_CAMERA_PIN_XCLK (10) #define MICROPY_CAMERA_PIN_PWDN (-1) #define MICROPY_CAMERA_PIN_RESET (-1) -#define MICROPY_CAMERA_PIN_SIOD (40) -#define MICROPY_CAMERA_PIN_SIOC (39) -#define MICROPY_CAMERA_XCLK_FREQ (20000000) -#define MICROPY_CAMERA_FB_COUNT (2) -#define MICROPY_CAMERA_JPEG_QUALITY (10) -#define MICROPY_CAMERA_GRAB_MODE (1) +#define MICROPY_CAMERA_PIN_SIOD (40) // SDA +#define MICROPY_CAMERA_PIN_SIOC (39) // SCL +#define MICROPY_CAMERA_XCLK_FREQ (20000000) // Frequencies are normally either 10 MHz or 20 MHz +#define MICROPY_CAMERA_FB_COUNT (2) // Usually the value is between 1 (slow) and 2 (fast, but more load on CPU) +#define MICROPY_CAMERA_JPEG_QUALITY (10) // Quality of JPEG output. 0-63 lower means higher quality. Definition will change in the future +#define MICROPY_CAMERA_GRAB_MODE (1) // 0=WHEN_EMPTY (might have old data, but less resources), 1=LATEST (best, but more resources) ``` diff --git a/src/modcamera.c b/src/modcamera.c index e7741a8..bd9f731 100644 --- a/src/modcamera.c +++ b/src/modcamera.c @@ -290,6 +290,14 @@ const mp_rom_map_elem_t mp_camera_hal_gainceiling_table[] = { { MP_ROM_QSTR(MP_QSTR_128X), MP_ROM_INT(GAINCEILING_128X) }, }; +// Supporting functions +static int map(int value, int fromLow, int fromHigh, int toLow, int toHigh) { + if (fromHigh == fromLow) { + mp_raise_ValueError(MP_ERROR_TEXT("fromLow und fromHigh shall not be equal")); + } + return (int)((int32_t)(value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow); +} + //TODO: Makros with convertion function, since the API will use standarized values. // Helper functions to get and set camera and sensor information #define SENSOR_STATUS_GETSET_IN_RANGE(type, name, status_field_name, setter_function_name, min_val, max_val) \