Passing CircularBuffer in function

Hello,

I use the library : CircularBuffer.h
but i can’t use Circular object in my function

#include <CircularBuffer.h>

CircularBuffer<float, 1500> Tableau;

void My_function ( CircularBuffer *f_Tableau, int Size_FIFO){
for (unsigned int i = 0; i < Size_FIFO; i++) {
Serial.println (Pile_FIFO (i)) —> Here the problem
}
}

loop {
My_function (&Tableau, 2500);

}

Use code tags, not quote tags.

Post a complete program with setup and loop.

Show the full error message, preferably in code tags.

1500 floats is bigger than the entire memory on some Arduinos. Which Arduino are you using?

I’m using Arduino DUE

here the code

#include <CircularBuffer.h>

CircularBuffer<float, 5> Tableau;

void My_function (CircularBuffer<float, 5> *f_Tableau, int Size_FIFO){
   for (unsigned int i = 0; i < Size_FIFO; i++) {
     Serial.println (f_Tableau [i]);// ---> Here the problem
   }
}

void setup() {
  Serial.begin(9600);

}

void loop() {
  Tableau.push(0.1);
  Tableau.push(0.5);
  
  My_function (&Tableau, 5);
}

And the error :

Desktop\sketch_jul13a\sketch_jul13a2\sketch_jul13a2.ino: In function ‘void My_function(CircularBuffer<float, 5u>*, int)’:

sketch_jul13a2:7: error: no matching function for call to ‘UARTClass::println(CircularBuffer<float, 5u>&)’

Serial.println (f_Tableau );// —> Here the problem

  • ^*
    Desktop\sketch_jul13a\sketch_jul13a2\sketch_jul13a2.ino:7:35: note: candidates are:
    In file included from AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Stream.h:26:0,
  • from AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/HardwareSerial.h:24,*
  • from AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:195,*
  • from sketch\sketch_jul13a2.ino.cpp:1:*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:70:12: note: size_t Print::println(const __FlashStringHelper*)
    size_t println(const __FlashStringHelper *);
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:70:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘const __FlashStringHelper*’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:71:12: note: size_t Print::println(const String&)
  • size_t println(const String &s);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:71:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘const String&’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:72:12: note: size_t Print::println(const char*)
  • size_t println(const char);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:72:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘const char*’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:73:12: note: size_t Print::println(char)
  • size_t println(char);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:73:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘char’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:74:12: note: size_t Print::println(unsigned char, int)
  • size_t println(unsigned char, int = DEC);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:74:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘unsigned char’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:75:12: note: size_t Print::println(int, int)
  • size_t println(int, int = DEC);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:75:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘int’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:76:12: note: size_t Print::println(unsigned int, int)
  • size_t println(unsigned int, int = DEC);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:76:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘unsigned int’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:77:12: note: size_t Print::println(long int, int)
  • size_t println(long, int = DEC);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:77:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘long int’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:78:12: note: size_t Print::println(long unsigned int, int)
  • size_t println(unsigned long, int = DEC);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:78:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘long unsigned int’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:79:12: note: size_t Print::println(double, int)
  • size_t println(double, int = 2);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:79:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘double’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:80:12: note: size_t Print::println(const Printable&)
  • size_t println(const Printable&);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:80:12: note: no known conversion for argument 1 from ‘CircularBuffer<float, 5u>’ to ‘const Printable&’
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:81:12: note: size_t Print::println()
  • size_t println(void);*
  • ^*
    AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Print.h:81:12: note: candidate expects 0 arguments, 1 provided
    exit status 1
    no matching function for call to ‘UARTClass::println(CircularBuffer<float, 5u>&)’
    [/quote]

What methods does CircularBuffer provide for getting data out of the buffer? The square-brackets operator is obviously not one of them.

The library named "CircularBuffer"

Try:

Serial.println (f_Tableau->pop());

pop() is to remove an element from the end of the buffer

but i want one element of my FIFO ?

For example

#include <CircularBuffer.h>

CircularBuffer<float, 5> Tableau;

void My_function (CircularBuffer<float, 5> *f_Tableau){
     Serial.println (f_Tableau [2]);
}

void setup() {
  Serial.begin(9600);

}

void loop() {
  Tableau.push(0.1);
  Tableau.push(0.2);
  Tableau.push(0.3);
  Tableau.push(0.4);
  Tableau.push(0.5);
  
  My_function (&Tableau);
}

This website will help: www.xyproblem.info

Try:

Serial.println ((*f_Tableau)[i]);

shaotzi:
The library named "CircularBuffer"

GitHub - rlogiacco/CircularBuffer: Arduino circular buffer library

That library does define the operator.

Try removing the space between f-tableau and [

It works if you pass a reference.

#include <CircularBuffer.h>

CircularBuffer<float, 5> Tableau;

void My_function(CircularBuffer<float, 5> &f_Tableau) {

 Serial.println(f_Tableau[2]);
}

void setup() {
 Serial.begin(115200);
 delay(1000);

 Tableau.push(0.1);
 Tableau.push(0.2);
 Tableau.push(0.3);
 Tableau.push(0.4);
 Tableau.push(0.5);
 My_function(Tableau);
}

void loop() {
}

Thanks a lot for your help!

The arduino_new solution is what I'm looking but the solution from gfvalvo is better.

It also works with a pointer:

#include <CircularBuffer.h>

CircularBuffer<float, 5> Tableau;

void My_function(CircularBuffer<float, 5> *f_Tableau) {

 Serial.println(f_Tableau->operator[](2));
}

void setup() {
 Serial.begin(115200);
 delay(1000);

 Tableau.push(0.1);
 Tableau.push(0.2);
 Tableau.push(0.3);
 Tableau.push(0.4);
 Tableau.push(0.5);
 My_function(&Tableau);
}

void loop() {
}

EDIT:
Just re-read solution from @arduino_new. Realized mine is the same, but his/hers looks nicer.