0

I've tried to read everything including this post: 2D-array as argument to function

I'm getting error: "cannot convert 'float' to 'float ()[8]' for argument '1' to 'float pzemGetter(float ()[8], PZEM004Tv30, byte)'"

Anyway, I couldn't make this code to work with arduino mega and pzem-004t v3 module... I'm just interested to get it in such way only to get a flexible code when using loops and things like that

`#include <PZEM004Tv30.h>`
`byte disabled = 150;`
`byte enabled = 180;`
`byte busyIndex = 0; //To ensure arduino mega is not busy before sending float array from PZEM`
`#define FLOATS_SENT 8`
`//============Arrays definition to be reported to raspberry through serial connection`
`float pzemGroup[8][8];  //A testing way to group pzem modules into array of arrays`
`byte statusArray[32];`


`PZEM004Tv30 pzemFrameGroup[] = {PZEM004Tv30(&Serial3, 0x42), PZEM004Tv30(&Serial3, 0x43),`
`                                PZEM004Tv30(&Serial3, 0x44), PZEM004Tv30(&Serial3, 0x45),`
`                                PZEM004Tv30(&Serial3, 0x46), PZEM004Tv30(&Serial3, 0x47),`
`                            PZEM004Tv30(&Serial3, 0x48), PZEM004Tv30(&Serial3, 0x49)`
                           };

`void setup() {`
`Serial.begin(115200); //This is the speed for serial monitoring`
`Serial2.begin(9600);  //Speed for serial comm with raspberry pi through USB Serial FTDI adapter`
`delay(200);`
`}`

`void loop() {`

`pzemGetter(pzemGroup[3][], pzemFrameGroup[0], busyIndex = 8);`
`float testValue1 = pzemGroup[3][0];`
`float testValue2 = pzemGroup[3][1];`
`float testValue3 = pzemGroup[3][2];`
`}//End loop function`

`//Function definition to get data from energy modules pzem004t installed in the same bus`
`float pzemGetter (float (*frmEnergy)[8], PZEM004Tv30 pzemModule, byte busyFlagLocator) {`
`statusArray[busyFlagLocator] = enabled;`
`frmEnergy[0][0] = 26.10; //I added this one as a personal initial element verification in raspberry`
`frmEnergy[0][1] = pzemModule.voltage();`
`frmEnergy[0][2] = pzemModule.power();`
`frmEnergy[0][3] = pzemModule.current();`
`frmEnergy[0][4] = pzemModule.energy();`
`frmEnergy[0][5] = pzemModule.frequency();`
`frmEnergy[0][6] = pzemModule.pf();`
`frmEnergy[0][7] = 26.10; //I added this one as a personal final element verification in raspberry`
`statusArray[busyFlagLocator] = disabled;`
`}`
ElectroMESH
  • 1
  • 1
  • 6
  • `pzemGetter(pzemGroup[3][], pzemFrameGroup[0], busyIndex = 8);` Change the first argument to `pzemGroup[3]`, i.e., remove the `[]`. You just "indexed" too much, and got a single float, instead of the address of 8 floats. That's what error message was saying. – aMike Mar 05 '21 at 14:18
  • Hi! I'm still getting the same error in Arduino IDE: cannot convert 'float*' to 'float**' for argument '1' to 'float pzemGetter(float**, PZEM004Tv30, byte)' – ElectroMESH Mar 06 '21 at 15:33
  • Try this when you call pzemGetter: `pzemGetter(&pzemGroup[3], ...)` Your pzemGetter wants to see a pointer to an array of 8 floats, and that's what this gives it. – aMike Mar 29 '21 at 04:51
  • I also did as you recommend, but the same problem. Finally I read somewhere that arduino does not deal with 2D array directly, so I created one temporary 1D array and then used a for loop to transfer its content to the specific 2D array (I mean, to the specific row for each one of its columns) – ElectroMESH Apr 02 '21 at 18:37
  • Anyway I feel sad because the system doesn't allow me to to post my own answer with enough details to this question. I already SOLVED it and I wanted to share what I did and how I did, but I'm banned ;-( – ElectroMESH Apr 02 '21 at 19:07
  • I'm sorry we couldn't get a good answer to your question. I took your code, stripped out the Arduino stuff, and compiled it on my laptop - that's where my answers came from - it compiled w/o errors or warnings. I don't know why some site said that the Arduino cannot handle 2D arrays. It uses C (ok, really C++), and C has had multiple dimension arrays for over 40 years! (yikes! :-) Hang in there... ask a few more questions, answer a few questions and you'll collect enough points - THEN you can answer your own question! :-) I'm glad you got it working! – aMike Apr 06 '21 at 00:52
  • Thanks a lot aMike. I'm sorry because in this case it's not possible for me to share details about what I did to solve this and trace what's wrong with me. Anyway my project and certain coding stuffs related to this point keeps track in GitHub with my username as "evdclick". PD: It's difficult to ask questions where most of them are duplicates, and well as you can see I can't even actually answer my own solved question. It's a really weird thing from stackoverflow :) just because I have 14points and 5downVotes. What else do they expect from a newbie? :-D – ElectroMESH Apr 07 '21 at 04:58
  • and yes aMike .... I gave another try to the solution you recommended and this time I got it! :) Thank you so much! – ElectroMESH Apr 07 '21 at 05:02
  • I looked at your github page - Wow! That's a great project! As for newbies... I was there not that long ago... wasn't able to comment, but could answer questions. I thought that was backwards... no suggestions allowed until you got enough points? Weird. OK, I'll leave you alone now! Take care! – aMike Apr 08 '21 at 14:57

0 Answers0