How to use C++ code in Arduino ide

Just pass the whole struct as reference

sorry, you just call the function, how can I write "buf[i]" in this " read.txt"

How can I do?

Are you going to explain why you want to do this ?

I'm just need to now how can I deal with this problem" how can send "buf[i]" to the function to be written in the file "read.txt"
For four days I have been searching for a solution to this problem with no avail :frowning:

Actually as fb is a pointer, just pass the pointer

void someFunction(camera_fb_t * theFrameBufferPointer) {
  for (int i = 0; i < theFrameBufferPointer->len; i++){
    Serial.print(theFrameBufferPointer->buf[i]);
    Serial.print(",");
  }
}

thanks for reply, can I use this in .cpp file and then write "buf[i]" in the txt file ?
and how can call like this in .ino file ?

yes, similar to what @johnwasser was suggesting with extern etc...

the .cpp would of course then need to know about the camera_fb_t type, so will need to include the relevant header (likely esp_camera.h) and then you have access to the full structure

typedef struct {
    uint8_t * buf;              /*!< Pointer to the pixel data */
    size_t len;                 /*!< Length of the buffer in bytes */
    size_t width;               /*!< Width of the buffer in pixels */
    size_t height;              /*!< Height of the buffer in pixels */
    pixformat_t format;         /*!< Format of the pixel data */
    struct timeval timestamp;   /*!< Timestamp since boot of the first DMA buffer of the frame */
} camera_fb_t;

test.ino

#include <esp_camera.h>
#include "sideModule.h"

void setup() {
  Serial.begin(115200); Serial.println();
  someFunction(esp_camera_fb_get());
}

void loop() {}

sideModule.h

#include <esp_camera.h>
void someFunction(camera_fb_t * theFrameBufferPointer);

sideModule.cpp

#include <Arduino.h>
#include "sideModule.h"

void someFunction(camera_fb_t * theFrameBufferPointer) {
  for (int i = 0; i < theFrameBufferPointer->len; i++){
    Serial.print(theFrameBufferPointer->buf[i]);
    Serial.print(",");
  }
}

I'm trying with this file but I couldn't create a file after calling the function

void someFunction(camera_fb_t * theFrameBufferPointer) {
ofstream myfile ("C://Users//pc//Desktop//epp.txt");
for (int i = 0; i < theFrameBufferPointer->len; i++){
myfile << theFrameBufferPointer->buf[i] << "," ;
}
}

use code tags please. You've been here long enough to do the right thing now.

ESP32-CAM Take Photo and Save to MicroSD Card

ESP32-CAM Take Photo and Save to MicroSD Card | Random Nerd Tutorials

An internet search may have been quicker then waiting for someone...?

@Idahowalker
was already mentioned in #3. Apparently of no interest... but who knows what OP is up to...

I'm getting tired.

I agree #3 solves the issue. I was thinking that perhaps, a revisit or reminder would move things along.

another issue:: I'm trying to insert the data of fp->buf[i] in arr[i] , I need arr[i] be as float .
what is the correct way to do that ?

float *arr=(float*)malloc( fb->len*sizeof(float));
Serial.print(fb->height); Serial.write(',');  
Serial.print(fb->width); Serial.write(',');  
for (int i = 0; i < fb->len; i++){            
  Serial.print(fb->buf[i]);
    arr[i] = float(fb->buf[i]); 
  if (i != fb->len -1) Serial.write(',');
  else Serial.println();
}
for (int i = 0; i < fb->len; i++){    

  Serial.print(arr[i]);
}

Why would you duplicate the memory? Why does it need to be float?

You might want to start paying attention to remaining RAM, might want to adjust your partition table.

Actually, I'm working with a function that needs an array as a float, and I need to insert the frame data into a float arr[i]

If you are going to move the frame buffer to another array, why not make the 2nd array the same element size as the framebuffer?

float *arr=(float*)malloc( fb->len*sizeof(float));
arr[i] = float(fp->buf[i]); `

It is true what you said, I am paying attention to this thing, but my problem is how to use such this arr[i] = fp->buf[i]