tsaarni / esp32-micropython-webcam

ESP32-CAM webcam with MicroPython
Apache License 2.0
148 stars 33 forks source link

TTGO-Camera-Plus camera.init() fails #7

Closed johncblacker closed 4 years ago

johncblacker commented 4 years ago

I'm trying to get a TTGO camera board to work with your distro and although I've gone in and updated the modcamera.c with my updated pin configuration for the camera, but I'm still getting the message that the init fails. I get Camera probe failed with error 0x103 and I can't find what the error is. I would guess I still have some kind of configuration issue but don't know what it is...do you have any clues?

tsaarni commented 4 years ago

@johncblacker No sorry, I don't really know anything about the driver.

johncblacker commented 4 years ago

OK, so let's try this. There is the camera.c, etc. within the esp-idf/components/esp32-camera directory and then there's the modcamera.c module. What is the modcamera module's purpose? Is it not the "driver" which you say you know nothing about?

tsaarni commented 4 years ago

modcamera.c is the python module that makes it possible to call the camera driver from Python code. I implemented only this part.

On the other hand, camera.c is the actual driver that talks with the camera chip using I2C, using the processor pin configuration that you defined. This driver is implemented by Espressif, not me. That is the reason why I can't help with the driver failure. If you check the parent directory of that file, you find there is few more files in the driver. The version I used is old, you can find the latest version from here https://github.com/espressif/esp32-camera/tree/master/driver.

The board that I worked with had OV2640 camera sensor and it seems your board has the same. If you have not found help for the problem just by googling, i suppose the approach I would take, would be to get hands dirty: download the datasheet for the camera chip (probably this one) and try to read the driver code along with the datasheet and understand where it goes wrong.

johncblacker commented 4 years ago

Yes, I guess that’s where I’m headed.

Sent from my iPad

On Jun 17, 2020, at 3:01 PM, Tero Saarni notifications@github.com wrote:

 modcamera.c is the python module that makes it possible to call the camera driver from Python code. I implemented only this part.

On the other hand, camera.c is the actual driver that talks with the camera chip using I2C, using the processor pin configuration that you defined. This driver is implemented by Espressif, not me. That is the reason why I can't help with the driver failure. If you check the parent directory of that file, you find there is few more files in the driver. The version I used is old, you can find the latest version from here https://github.com/espressif/esp32-camera/tree/master/driver.

The board that I worked with had OV2640 camera sensor and it seems your board has the same. If you have not found help for the problem just by googling, i suppose the approach I would take, would be to get hands dirty: download the datasheet for the camera chip (probably this one) and try to read the driver code along with the datasheet and understand where it goes wrong.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

johncblacker commented 4 years ago

OK, I understand the environment and where your modcamera.c fits in. Am I correct that I can create a camera_config file which contains the pin configuration

of my camera (TTGO-Camera-Plus) and pass the address of that config_camera to the camera.init? Something like: camera.init(&myconfig), will that work?

I believe that the esp-idf camera.c and your modcamera.c both use the pin configuration for the esp32-cam board, is that right? My board: TTGO-Camera-Plus

uses a different pin configuration and therefore the plain camera.init() function fails. I’m now getting a -x103 error from camera.init(), before I was getting

0x20003. So, I’m making progress – I think. I’m still finding that the SCCB functions are failing, so I have to look into that also. I get:

SCCB_Write [ff] = 80

SCCB_Write [12]=01

So, I still have more work to do to figure that out, maybe have to look at the SCCB_Write section of the OV2640 datasheet.

Thanks for your help…I think I can get this to work! It’s not rocket science!

jb

From: Tero Saarni notifications@github.com Sent: Wednesday, June 17, 2020 3:02 PM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

modcamera.c https://github.com/tsaarni/micropython-with-esp32-cam/blob/esp32-camera-for-micropython/ports/esp32/modcamera.c is the python module that makes it possible to call the camera driver from Python code. I implemented only this part.

On the other hand, camera.c https://github.com/tsaarni/esp32-camera-for-micropython/blob/esp32-camera-for-micropython/driver/camera.c is the actual driver that talks with the camera chip using I2C, using the processor pin configuration that you defined. This driver is implemented by Espressif, not me. That is the reason why I can't help with the driver failure. If you check the parent directory of that file, you find there is few more files in the driver. The version I used is old, you can find the latest version from here https://github.com/espressif/esp32-camera/tree/master/driver.

The board that I worked with had OV2640 camera sensor and it seems your board has the same. If you have not found help for the problem just by googling, i suppose the approach I would take, would be to get hands dirty: download the datasheet for the camera chip (probably this one https://www.uctronics.com/download/cam_module/OV2640DS.pdf ) and try to read the driver code along with the datasheet and understand where it goes wrong.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-645563036 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAAW3QPG6ID53DTERLITRXEHJNANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAAQBEF5TX6Q3VAADGUTRXEHJNA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEZ5IFHA.gif

tsaarni commented 4 years ago

OK, I understand the environment and where your modcamera.c fits in. Am I correct that I can create a camera_config file which contains the pin configuration of my camera (TTGO-Camera-Plus) and pass the address of that config_camera to the camera.init? Something like: camera.init(&myconfig), will that work?

Do you mean passing the camera configuration from the Python script side to the C code? Yeah, I think that would be very good improvement.

Reading a configuration file with the data structure as a buffer is one option, though crafting that file according to the C struct camera_config_t (defined by the driver) could be bit tricky for the users. I guess user would probably end up writing C code then anyway to create that file? Another option could be to create a Python object and passing that to modcamera.c which could parse it to camera_config_t. That would be like a new Python specific API that users can more conveniently customize for their boards.

If you are interested in this, Micropython docs give information how to write modules in C, including how to do Python object parsing inside the C module. Any contributions here would be very welcome :) Or you can of course just fork your own version.

I still have my camera board lying around somewhere, but I have not worked with this project for quite a while. I have not uplifted any micropython changes, or ESP camera driver changes after creating this project. Sorry for this! There just seems to be too much interesting stuff to do to justify coming back to improve your "old" projects...

I believe that the esp-idf camera.c and your modcamera.c both use the pin configuration for the esp32-cam board, is that right?

It has been a while but if I recall correctly, I closely followed the example Espressif gives in their README.md but did some minor changes in the config. In my wiki I wrote "The ESP32-CAM module in the picture is available from various places, see here for one reseller. I believe these are based on this discontinued product". That second link had schemas and and also link to this example repo from AI-Thinker employee, with even more information on the pins in the README.md and sdkconfig. So, I think I collected the information for my config from AI-Thinker example and docs, and I did not need to get familiar with the driver, or even too deeply familiar with my own board since I found all needed information in this example.

But as you say, it is not rocket science! Even in extreme case I think finding out the config is very much doable without any information from board supplier just by following the traces with a multimeter. I wish you best luck with this, and a least in my case these kind of hobby projects are so good for learning how stuff actually works, that usually I can almost justify the time I put into projects like this :)

johncblacker commented 4 years ago

Thanks for the reply…for expediency, I just modified the pin configuration inside MODCAMERA.C and built my firmware. I do notice that sometimes the camera.init() works

and other times it seems to throw a 0x103 error…don’t know why. But, even when the camera.init() works, I then try a camera.capture() and that doesn’t seem to work.

So, I don’t know what’s going on. When I say camera.init() works, I can see buffers being allocated by the camera. Here’s some output from REPL:

import camera

camera.init()

[0;31mE (6106490) camera: Camera probe failed with error 0x103[0m

[0;31mE (6106490) camera: Camera Init Failed[0m

False

camera.init()

[0;32mI (6112940) gpio: GPIO[36]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112940) gpio: GPIO[37]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112950) gpio: GPIO[38]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112960) gpio: GPIO[39]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112970) gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112980) gpio: GPIO[26]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6112990) gpio: GPIO[13]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6113000) gpio: GPIO[34]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6113010) gpio: GPIO[5]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6113020) gpio: GPIO[27]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6113020) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m

[0;32mI (6113030) camera: Allocating 1 frame buffers (234 KB total)[0m

[0;32mI (6113070) camera: Allocating 234 KB frame buffer in OnBoard RAM[0m

[0;31mE (6113110) gpio: gpio_install_isr_service(394): GPIO isr service already installed[0m

True

First init fails, second works!

I tried “buf = camera.capture()” and it doesn’t seem to ever complete…of course, I don’t know what I’m doing!

From: Tero Saarni notifications@github.com Sent: Saturday, June 20, 2020 4:15 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

OK, I understand the environment and where your modcamera.c fits in. Am I correct that I can create a camera_config file which contains the pin configuration of my camera (TTGO-Camera-Plus) and pass the address of that config_camera to the camera.init? Something like: camera.init(&myconfig), will that work?

Do you mean passing the camera configuration from the Python script side to the C code? Yeah, I think that would be very good improvement.

Reading a configuration file with the data structure as a buffer is one option, though crafting that file according to the C struct camera_config_t (defined by the driver) could be bit tricky for the users. I guess user would probably end up writing C code then anyway to create that file? Another option could be to create a Python object and passing that to modcamera.c which could parse it to camera_config_t. That would be like a new Python specific API that users can more conveniently customize for their boards.

If you are interested in this, Micropython docs give information how to write modules in C, including how to do Python object parsing inside the C module. Any contributions here would be very welcome :) Or you can of course just fork your own version.

I still have my camera board lying around somewhere, but I have not worked with this project for quite a while. I have not uplifted any micropython changes, or ESP camera driver changes after creating this project. Sorry for this! There just seems to be too much interesting stuff to do to justify coming back to improve your "old" projects...

I believe that the esp-idf camera.c and your modcamera.c both use the pin configuration for the esp32-cam board, is that right?

It has been a while but if I recall correctly, I closely followed the example Espressif gives in their README.md https://github.com/espressif/esp32-camera/blob/master/README.md but did some minor changes in the config. In my wiki https://github.com/tsaarni/micropython-with-esp32-cam/wiki I wrote "The ESP32-CAM module in the picture is available from various places, see here https://www.banggood.com/Geekcreit-ESP32-CAM-WiFi-+-Bluetooth-Camera-Module-Development-Board-ESP32-With-Camera-Module-OV2640--p-1394679.html for one reseller. I believe these are based on this https://www.seeedstudio.com/ESP32-CAM-Development-Board-with-camer-p-3153.html discontinued product". That second link https://www.seeedstudio.com/ESP32-CAM-Development-Board-with-camer-p-3153.html had schemas and and also link to this example https://github.com/donny681/ESP32_CAMERA_QR repo from AI-Thinker employee, with even more information on the pins in the README.md https://github.com/donny681/ESP32_CAMERA_QR/blob/master/README.md and sdkconfig https://github.com/donny681/ESP32_CAMERA_QR/blob/0d87564e6858ca529eb217bce518355dcf705ea8/sdkconfig#L127 . So, I think I collected the information for my config from AI-Thinker example and docs, and I did not need to get familiar with the driver, or even too deeply familiar with my own board since I found all needed information in this example.

But as you say, it is not rocket science! Even in extreme case I think finding out the config is very much doable without any information from board supplier just by following the traces with a multimeter. I wish you best luck with this, and a least in my case these kind of hobby projects are so good for learning how stuff actually works, that usually I can almost justify the time I put into projects like this :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-646961723 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAARTHIES72H24ZID2PDRXRVZLANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAAUQSVQF4RNWMG6JWKDRXRVZLA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE2H5UOY.gif

tsaarni commented 4 years ago

I'm sure you know this already but just to make sure: are you aware of this project https://github.com/Xinyuan-LilyGO/esp32-camera-screen/ and is this your board?

There's familiar setup code here with the camera_config_t and the pin definitions are here.

Do these match with what you use?

johncblacker commented 4 years ago

I am aware of that but it doesn’t use micropython. I was able to get my camera board working via Arduino, but that’s not what I want!

Looks like https://github.com/lemariva/micropython-camera-driver is my best bet right now as it’s a micropython implementation and

I did get it to work with my esp32-cam. Having a program issue with his code using my camera definitions. His code allows the pin

definitions to be specified at runtime! EXACTLY WHAT I WANT…

Thank you.

From: Tero Saarni notifications@github.com Sent: Saturday, June 20, 2020 1:07 PM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

I'm sure you know this already but just to make sure: are you aware of this project https://github.com/Xinyuan-LilyGO/esp32-camera-screen/ and it this your board?

There's familiar setup code here https://github.com/Xinyuan-LilyGO/esp32-camera-screen/blob/66c7f1141e5429130f4ad21cf5f2ac6a41711aa4/main/app_camera.c#L42 with the camera_config_t and the pin definitions are here https://github.com/Xinyuan-LilyGO/esp32-camera-screen/blob/66c7f1141e5429130f4ad21cf5f2ac6a41711aa4/main/include/board_def.h#L31 .

Do these match with what you use?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-647021618 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAARHW4DOPDLJUQWAEYTRXTUDTANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAAU6FO7WOBCROFKL26DRXTUDTA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE2IMIMQ.gif

tsaarni commented 4 years ago

Yes I was thinking just using the pin definitions from the LilyGO project for modcamera.c but glad that you found the project that already has the option to provide pins from python at run time. That is much better option, like we discussed earlier. Good luck with your project(s)!

johncblacker commented 4 years ago

Yes, this is the ideal implementation, but right now there’s a problem with the camera.init( …… arguments here ……) call. I sent email to author.

I’ll let you know when fixed.

From: Tero Saarni notifications@github.com Sent: Sunday, June 21, 2020 11:58 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

Yes I was thinking just using the pin definitions from the LilyGO project for modcamera.c but glad that you found the project that already has the option to provide pins from python at run time. That is much better option, like we discussed earlier. Good luck with your project(s)!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-647146247 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAAWXW7CRZLLEZPF5CYLRXYUXPANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAASUTYE2FUMFNZTSJJTRXYUXPA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE2JKWBY.gif

johncblacker commented 4 years ago

Thank you. I have been working with the lemariva distro and have only been able to get it to work with the ESP32-CAM,

despite all the testing I’ve done with both the TTGO-CAMERA-PLUS and the M5CAM from M5STACK. I find that the micropython

part of the lemariva distro seems to work OK, but his accompanying documentation and python usage scripts leave a lot to

be desired and I’ve reverted to using your boot/main/webcam python scripts along with his distro. Apparently, he’s grown

tired of my bringing up issues to him and sent me a rather “sarcastic” email telling me if I find a problem, fork the repos and

fix the problem! Not what I expected, but so be it! He’s been trying to put a lot of new stuff (like MQTT and time-lapse) into

his “package” but in the process has left some of his repositories in a mess. Fortunately, I built my own repo of micropython

from his code and am being extra careful when it comes to using his python “camera” usage scripts.

Hope you have better luck than I.

John Blacker

From: Tero Saarni notifications@github.com Sent: Sunday, June 21, 2020 11:58 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

Yes I was thinking just using the pin definitions from the LilyGO project for modcamera.c but glad that you found the project that already has the option to provide pins from python at run time. That is much better option, like we discussed earlier. Good luck with your project(s)!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-647146247 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAAWXW7CRZLLEZPF5CYLRXYUXPANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAASUTYE2FUMFNZTSJJTRXYUXPA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE2JKWBY.gif

johncblacker commented 4 years ago

So, I have an M5STACK ESP32 CAMERA module and am trying to get the lemariva code (or even yours) but I run into a memory problem.

board has 4MB of flash, but after putting MP on and then the picoweb and micropython.ulogging support apps on there, the camera init

fails because it doesn’t have enough memory left and I get heap corruption errors in the camera.init() function. So I’m wondering how

to take advantage of the 4MB of PSRAM that’s on the ESP32 boards, or in some cases, like my TTGO-CAMERA-PLUS, it has 8MB of PSRAM.

But I don’t know how and where in the build to control the size of PSRAM. I looked at a github repo called the loboris distro and he has a

BUILD.sh script in which you specify this information but he doesn’t have the ESP32 cam stuff in there. I keep reading about using the ESP-IDF

menuconfig to control the SDKCONFIG file, but how do you do that under, say “windows subsystem for linux” on windows 10 (or perhaps,

just under windows 10 itself). Do I have to get into learning the whole ESP-IDF development process in order to get an SDKCONFIG file that

I can then use during the build process under micropython/ports/esp32? I apologize if this sounds a like I’m rambling, but I really don’t know

which direction to turn to be able to make micropython firmware that will take advantage of the PSRAM (whatever the size) of the ESP32 board

I’m using.

Thank you for any help you can provide.

John Blacker

tsaarni commented 4 years ago

I might have a hunch what confuses you with the firmware build, or at least this was something I figured out to be bit confusing myself: When I was playing with MicroPython, maybe 1.5 years ago or so, there was two different approaches to build MicroPython for ESP32:

  1. MicroPython's own build system, which has ports concept to target different microcontrollers
  2. ESP-IDF build system, where the idea is to compile MicroPython as an "ESP-IDF component"

In the first option the way to build is defined by MicroPython using Makefiles of one of the ports, for example esp32. To further customize the build for different boards, one directs the Makefile to use one of the board specific configurations under boards, see for example GENERIC_SPIRAM. I think menuconfig is not used by MicroPython build system at all.

For the second option, one uses the ESP-IDF build process. It is the same approach as one would normally use for C based projects on ESP architecture. The build is highly customisable with menuconfig and it exposes a lot of ESP32 specific options that are (or at least were) not exposed under MicroPython ESP32 port. One of the core concepts in ESP-IDF build is the "component" system - people can create external components that will be build under ESP-IDF build system. One could call these modules or plugins that can be chosen with menuconfig. Example of a component is the camera component in https://github.com/espressif/esp32-camera. If you check the README, it instructs to clone the repository under IDF components directory and then run menuconfig to enable it in the build. The repository contains Kconfig and component.mk files that make it a part of IDF component system.

Now, someone actually took MicroPython repository and modified that into ESP-IDF component https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo in order to utilize IDF build and all the options HW options it exposes, instead of relying on MicroPython ports system. However, to me it looks like this second build method has not been updated anymore for the latest MicroPython versions for quite some time.

On the other hand, the MicroPython ports seem to have support for accessing SPI RAM when appropriate boards definition is used in the build.

As an example, if you check how @lemariva made his build here in his blog, he uses the MicroPython build system (1st option) and defines BOARD to point out either GENERIC or GENERIC_SPIRAM. Similar instructions are here in MicroPython's ESP32 port README.

If checking https://github.com/m5stack/M5Stack_MicroPython, it is based on the ESP-IDF component build system. I think the ESP-IDF and menuconfig surely would be usable under WSL, but since it looks like the MicroPython versions extracted as IDF components seem old, I would myself go with the MicroPython ports/boards build approach and try to enable SPIRAM board config (if you did not do it already).

johncblacker commented 4 years ago

Thank you for your reply.

I am using the micropython build approach using the Makefile in mp/ports/esp32. I got an email from Mauro Riva and

he mentions changing the value in the main.c program, but I’m not sure which direction to go to solve my “heap” issues.

I did email him for further guidance. Maybe I’ll just change it, build and see what happens! I am using the board definition

GENERIC_ESP32CAM which includes config for SPIRAM.

From: Tero Saarni notifications@github.com Sent: Friday, July 3, 2020 12:39 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

I might have a hunch what confuses you with the firmware build, or at least this was something I figured out to be bit confusing myself: When I was playing with MicroPython, maybe 1.5 years ago or so, there was two different approaches to build MicroPython for ESP32:

  1. MicroPython's own build system, which has ports concept to target different microcontrollers
  2. ESP-IDF build system, where the idea is to compile MicroPython as an "ESP-IDF component"

In the first option the way to build is defined by MicroPython using Makefiles of one of the ports, for example esp32 https://github.com/micropython/micropython/tree/master/ports/esp32 . To further customize the build for different boards, one directs the Makefile to use one of the board specific configurations under boards, see for example GENERIC_SPIRAM https://github.com/micropython/micropython/tree/master/ports/esp32/boards/GENERIC_SPIRAM . I doubt menuconfig is used by MicroPython build system at all.

For the second option, one uses the ESP-IDF build process. It is the same approach as one would normally use for C based projects on ESP architecture. The build is highly customisable with menuconfig and it exposes a lot of ESP32 specific options that are (or at least were) not exposed under MicroPython ESP32 port. One of the core concepts in ESP-IDF build is the "component" system - people can create external components that will be build under ESP-IDF build system. One could call these modules or plugins that can be chosen with menuconfig. Example of a component is the camera component in https://github.com/espressif/esp32-camera. If you check the README, it instructs to clone the repository under IDF components directory and then run menuconfig to enable it in the build. The repository contains Kconfig and component.mk files that make it a part of IDF component system.

Now, someone actually took MicroPython repository and modified that into ESP-IDF component https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo in order to utilize IDF build and all the options, instead of relying on MicroPython ports system. However, to me it looks like this second build method has not been updated anymore for the latest MicroPython versions for quite some time.

On the other hand, the MicroPython ports seem to have support for accessing SPI RAM when appropriate boards definition is used in the build.

As and example, if you check how @lemariva https://github.com/lemariva made his build [here in his blog](https://lemariva.com/blog/2020/03/tutorial-getting-started-micropython-v20, he uses the MicroPython build system (1st option) and defines BOARD to point out either GENERIC or GENERIC_SPIRAM. Similar instructed are listed in MicroPython's ESP32 port README https://github.com/micropython/micropython/tree/master/ports/esp32 .

If checking https://github.com/m5stack/M5Stack_MicroPython, it is based on the ESP-IDF component build system. I think the ESP-IDF and menuconfig surely would be usable under WSL, but since it looks like the MicroPython versions extracted as IDF components seem old, I would myself go with the MicroPython ports/boards build approach and try to enable SPIRAM board config (if you did not do it already).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-653341511 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAASDIX3FFCT6GRVG2XDRZVOGDANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAARD7BQSGCB5OD7GK33RZVOGDA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE3YTGRY.gif

johncblacker commented 4 years ago

I’m going to run this by you in the hope that you have knowledge of writing mp modules, which I don’t have.

So, here’s what I’d like to do, but though I thought it a simple fix, it doesn’t compile.

The lemariva repository contains a module called modcamera.c with an accompanying modcamera.h which acts

as a front-end to the esp-camera module that provides the camera driver functionality. Currently his front to the

camera.init() function provides the capability to specify the pin definitions at run-time which is great. The

issue I have with it is that it always returns with a python value of “none” (mp_const_none). So what I’d

like is for it to return “true” if the init works or “false” if the init doesn’t work. I tried modifying the

return portion of his camera_init_helper() function (which calls the esp camera.init() and I changed the

function “signature” to return a mp_obj_t just like what is done in the camera.deinit() and camera.capture() functions,

but it doesn’t compile. So, I guess I’m missing something else that needs to change (beside my knowledge 😊) and I’m

hoping you might have the answer. Here’s what I get from the build:

CC modcamera.c

In file included from modcamera.c:6:0:

modcamera.c: In function 'camera_init_helper':

../../py/obj.h:102:39: error: 'return' with a value, in function returning void [-Werror]

define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 6))

                                   ^

../../py/obj.h:673:24: note: in expansion of macro 'MP_OBJ_NEW_IMMEDIATE_OBJ'

define mp_const_false MP_OBJ_NEW_IMMEDIATE_OBJ(1)

                    ^

modcamera.c:120:9: note: in expansion of macro 'mp_const_false'

return mp_const_false; // jblacker added and commented next instr

     ^

../../py/obj.h:102:39: error: 'return' with a value, in function returning void [-Werror]

define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 6))

                                   ^

../../py/obj.h:674:23: note: in expansion of macro 'MP_OBJ_NEW_IMMEDIATE_OBJ'

define mp_const_true MP_OBJ_NEW_IMMEDIATE_OBJ(3)

                   ^

modcamera.c:123:12: note: in expansion of macro 'mp_const_true'

 return mp_const_true;

        ^

cc1: all warnings being treated as errors

../../py/mkrules.mk:63: recipe for target 'build-GENERIC_ESP32CAM/modc

It seems to be indicating that it believes that the function should not return a value, but I did change the

function signature…like I said, maybe missing a change elsewhere; but where? I’d run this by Mauro Riva, but

he’s not been too responsive lately.

Thanks for your help.

John Blacker

From: Tero Saarni notifications@github.com Sent: Friday, July 3, 2020 12:39 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

I might have a hunch what confuses you with the firmware build, or at least this was something I figured out to be bit confusing myself: When I was playing with MicroPython, maybe 1.5 years ago or so, there was two different approaches to build MicroPython for ESP32:

  1. MicroPython's own build system, which has ports concept to target different microcontrollers
  2. ESP-IDF build system, where the idea is to compile MicroPython as an "ESP-IDF component"

In the first option the way to build is defined by MicroPython using Makefiles of one of the ports, for example esp32 https://github.com/micropython/micropython/tree/master/ports/esp32 . To further customize the build for different boards, one directs the Makefile to use one of the board specific configurations under boards, see for example GENERIC_SPIRAM https://github.com/micropython/micropython/tree/master/ports/esp32/boards/GENERIC_SPIRAM . I doubt menuconfig is used by MicroPython build system at all.

For the second option, one uses the ESP-IDF build process. It is the same approach as one would normally use for C based projects on ESP architecture. The build is highly customisable with menuconfig and it exposes a lot of ESP32 specific options that are (or at least were) not exposed under MicroPython ESP32 port. One of the core concepts in ESP-IDF build is the "component" system - people can create external components that will be build under ESP-IDF build system. One could call these modules or plugins that can be chosen with menuconfig. Example of a component is the camera component in https://github.com/espressif/esp32-camera. If you check the README, it instructs to clone the repository under IDF components directory and then run menuconfig to enable it in the build. The repository contains Kconfig and component.mk files that make it a part of IDF component system.

Now, someone actually took MicroPython repository and modified that into ESP-IDF component https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo in order to utilize IDF build and all the options, instead of relying on MicroPython ports system. However, to me it looks like this second build method has not been updated anymore for the latest MicroPython versions for quite some time.

On the other hand, the MicroPython ports seem to have support for accessing SPI RAM when appropriate boards definition is used in the build.

As and example, if you check how @lemariva https://github.com/lemariva made his build [here in his blog](https://lemariva.com/blog/2020/03/tutorial-getting-started-micropython-v20, he uses the MicroPython build system (1st option) and defines BOARD to point out either GENERIC or GENERIC_SPIRAM. Similar instructed are listed in MicroPython's ESP32 port README https://github.com/micropython/micropython/tree/master/ports/esp32 .

If checking https://github.com/m5stack/M5Stack_MicroPython, it is based on the ESP-IDF component build system. I think the ESP-IDF and menuconfig surely would be usable under WSL, but since it looks like the MicroPython versions extracted as IDF components seem old, I would myself go with the MicroPython ports/boards build approach and try to enable SPIRAM board config (if you did not do it already).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-653341511 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAASDIX3FFCT6GRVG2XDRZVOGDANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAARD7BQSGCB5OD7GK33RZVOGDA5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE3YTGRY.gif

lemariva commented 4 years ago

value of “none” (mp_const_none)

You don't check the repositories, before writing. The issue was solved 12 days ago.

../../py/obj.h:102:39: error: 'return' with a value, in function returning void [-Werror]

It is not a MicroPython problem, it is a C problem. You are trying to return a bool and the function camera_init_helper is a void function. That is very easy to see. You need to change that. But, check the repo file, it is already done and the firmware was also updated.

(sorry @tsaarni, the issue is closed and I'm messing up with it)

johncblacker commented 4 years ago

I’m sorry. You are correct; I didn’t check the repositories to see if any issues were posted

and changes made. I apologize for the inconvenience. I will refresh my esp32-camera-driver repository

before I do any more testing.

John Blacker

From: Mauro Riva notifications@github.com Sent: Thursday, July 9, 2020 11:03 AM To: tsaarni/esp32-micropython-webcam esp32-micropython-webcam@noreply.github.com Cc: John Blacker joblacker@cfl.rr.com; Mention mention@noreply.github.com Subject: Re: [tsaarni/esp32-micropython-webcam] TTGO-Camera-Plus camera.init() fails (#7)

value of “none” (mp_const_none)

You don't check the repositories, before writing. The issue was solved 12 days ago. https://github.com/lemariva/micropython-camera-driver/commit/ba3e6c7d54354b34eeb10b31d9b6ac25d0b9646a

../../py/obj.h:102:39: error: 'return' with a value, in function returning void [-Werror]

It is not a MicroPython problem, it is a C problem. You are trying to return a bool and the function camera_init_helper is a void function. That is very easy to see. You need to change that. But, check the repo file, it is already done and the firmware was also updated.

(sorry @tsaarni https://github.com/tsaarni , the issue is closed and I'm messing up with it)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tsaarni/esp32-micropython-webcam/issues/7#issuecomment-656181115 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAARVQOKBEXZALIEE4EDR2XLY7ANCNFSM4N75DTCQ . https://github.com/notifications/beacon/AB6WAAVNO5HNJ7SHBE3XB43R2XLY7A5CNFSM4N75DTC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE4OIO6Y.gif