Writing in to array

Hi gays…

needed your help in very simple problem

how to declarer and write in to a BYTE array???


here says that function: Serial.readBytes(buffer, length)

buffer: the buffer to store the bytes in (char or byte)

So char is works but byte aren’t

but I need exactly a byte not the char… Char give me garbidge…

What Im trying to do is reading the answer (series of bytes) from device…

char Str2[6]; works but getting garbidge
byte Str2[6]; – IDE won’t comply…

I don’t get why

this the code

char Str2[6];
byte ReqSld[] = {0x00, 0x04, 0x00, 0x04};

 for (int i=0;i<6;i++) Str2[i]=0;  

         mySerial.write(ReqSld, sizeof(ReqSld));
         mySerial.readBytes(Str2,6);          // (buff, size)
         int i;
         for(i=0; i<6; i=i+1)
            Serial.write(Str2[i]);        // it is write and also reads same way byte by byte
//          R=mySerial.read();
//          Serial.println(R);

Common guys??? nobody have any solution to this?

b= byte (Str2[0]);

I found this... works but needs to put in the String some how


I don't understand what you are trying to do with the device's reply. It's a sequence of bytes, but you want to store them in a string? Why?

And your code is really ugly, learn indenting, especially if you want people to review it...

But most importantly, it's really bad practice to just wait a certain time to then read a certain amount of data without even knowing if it arrived :P. See this example for a better way to do it.

I don't get why

this the code

Because you didn't post a complete compilable program, neither do I.

There is no need to use readBytes()
See the Arduino code in this demo