Page 1 of 3

ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 12:53 pm
by mnfisher
I've posted a couple of examples of using espressif sample code with the esp32. With the release of v10 I thought I'd try and find a 'neater' way of doing this. I've posted here as I think the code should be applicable to v9 as well...

A work in progress.. And not a project for the faint of heart....

So - with a esp32cam board (optimism is a dangerous thing) I wanted to get the camera working from within FC...
First job is to get the camera component compiling from within Flowcode.

So - first get the the esp32 camera source... (this is at https://github.com/espressif/esp32-camera)

Then copy the esp32-camera directory to a new location.

Now create a new FC project and save it to this 'esp32-camera' directory - and call it examples.fcfx Note that FC10 seems to do things 'slightly' differently - and I haven't experimented with renaming the examples folder - however I don't want FC to create the main folder and sdkconfig.

In the examples folder edit CMakelists.txt and change project to esp-project (last lines should read:
project(esp-project)
In the examples\main directory edit CMakelists.txt and change the first line to
set(COMPONENT_SRCS "take_picture.c" "esp-project.c")
Edit take_picture.c and change the first line of init_camera to
int init_camera()
and change app_main() to
void snap()
{
camera_fb_t *pic = esp_camera_fb_get();

// use pic->buf to access the image
esp_camera_fb_return(pic);
}
Add
#include "take_picture.h" to the start of the file...


Note that we will need to get rid of the esp_camera_fb_return line (and call this after dealing with the photo - however the first task is to get this to compile...

Create a new file take_picture.h
#ifndef take_picture
#define take_picture 1

int init_camera();

void snap();

#endif
Continued in next post...

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 12:57 pm
by mnfisher
As an aside: To make esp32 programming a nicer place: edit C:\ProgramData\MatrixTSL\FlowcodeV10\FCD\ESP\Batch\esp32_prog.bat and change 115200 to 921600 - this programs the esp32 at 8x speed (FC ignores the setting in menuconfig)

If this speed doesn't work reliably for you try multiples of 115200 (2x, 4x)

Martin

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 1:20 pm
by mnfisher
In examples.fcfx in the supplementary code:
#include "take_picture.h"
To use our 'current code' - we can add FCL_ERR = init_camera(); or snap(); in C blocks - and this is what I did (note that snap currently just discards the photo..

I 'flashed' the LED on A4 - to show 'life' - and all seems well....

However - we can't yet compile from FC... To do this - first open a command prompt and
cd esp32-camera/examples
esp-idf\export
idf.py fullclean

idf.py menuconfig - in the component config there should be a camera configuration 'tab' at the bottom - untick all except the camera you have attached (I have ov2640)

You should now be able to compile using either idf.py build or from within FC :-)
examples.fcfx
(8.16 KiB) Downloaded 56 times
This is a simple test (takes a 'photo' (which is discarded) and flashes the onboard LED - the UART doesn't seem to work with esp32cam boards (and opening a com port 'stops' program execution - so no debug messages for us)

Next job - save the picture to SD :-) First - lunch!

Martin

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 5:15 pm
by BenR
Hi Martin,

Ooh I've got a bunch if these camera boards so very interested to how you get on with this one. Maybe together we can somehow wrangle this into a component.

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 5:55 pm
by mnfisher
Hi Ben,

Just got my first JPEG saved :-) After a lot of fiddling.

Hit upon the snag of the SD card not being supported (?) on the camera board - so had to pull in some more espressif code...

Still - got there - next try upping res to UXGA
MYPHOTO.JPG
MYPHOTO.JPG (8.84 KiB) Viewed 1740 times
The names Bailey, David Bailey???

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 5:59 pm
by chipfryer27
Bailey? I'll drink to that....

Great work and thanks for sharing.

Regards

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 6:23 pm
by mnfisher
And it works at UXGA as well...

Strangely, I think my first bit of code on the old v7 forum was for a JPEG camera on Arduino - which I used to make some timelapse 'movies' - this should be much better (640 x 480 on Arduino) - and I now have it churning out PICn.jpg at a few secs intervals - pity it's dark outside!

Not sure how it's easiest to share the code - I also added the sd_card_example from the espressif examples with a couple of small functions to open/close/write files etc...

Biggest stumbling block was a #define BOARD_WROVER_KIT 1 in the camera example - I think it was there before and I didn't add it myself... However this meant the 'pins' were incorrect....

Anyone (Ben) have any of the other camera units available??

Martin

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 9:02 pm
by BenR
These are the ones I have.
https://www.aliexpress.com/item/1005001642663021.html

I've confirmed they work but wasn't able to include all the various libraries into Flowcode compiler. I must admit I didn't get to spend very long on it.

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 9:15 pm
by mnfisher
Yes - same one, though I think I paid a bit more :( 72p each including the 'extension' board!

Martin

Re: ESP32 - Reusing example source - Esp32-Camera

Posted: Sun Jan 29, 2023 9:21 pm
by chipfryer27
72p for a camera board..... They saw you coming :) :) :)

Beggars belief it can be sold at a profit at that price.......