Unknown Error: New to Arduino and C, Diving into the Deep End....

Hi!

I am working on an IMU (inertial measurement unit) project that uses an accelerometer and gyroscope. I'm fairly early in the project and would simply like to read data from the accelerometer. In the datasheet, it recommended reading all data registers at once to avoid data changes between readings. Anyway, I am writing my own "readFrom" function to do this, but I get an error that says the following: (error: invalid conversion from 'byte*' to 'byte'). This occurs on the last line (54) where I try to return the "data" variable. (Code is attached to this post.)

Apparently it has something to do with pointers, but I don't know anything about them, or what they have to do with my code. I am following a more complex code to create my own, but I feel as if everything I've done is pretty straightforward.

Any help would be really appreciated. I've spent a lot of time just trying to get a valid output, and this seems to be the last hurdle.

Thank you very much!

code.ino (1.44 KB)

Thanks for the knowledge bomb! I got it working using the "usual practice." I had no idea you couldn't return an array...

Now I can finally start working on the rest of it!

Another, arguably more "c++ correct", way to do it, is to pass a reference to the array, rather than a pointer. Note nothing changes by the argument list for myFunction. This has the advantage that the compiler will not allow you to pass an array of the wrong length to the function, which can save you from some hard to find bugs:

void myFunction(char (&aCharArray)[6] ){

     char arrayInFunction[6] = {'1','2','3','4','5','6'};


     for(int i = 0; i < 6; i++){
          aCharArray[i] = arrayInFunction[i];
     }

}

void theCallingFunction(){

     char arrayInCaller[6];

     myFunction(arrayInCaller);

     for(int i = 0; i<6; i++){
          Serial.print(arrayInCaller[i]);
     }
}

Regards,
Ray L.