add new values to array

As you can’t transmit “an array” and with serial only bytes, there is NO difference for the receiving end between

byte arrA[] = {0x01, 0x02, 0x03};
byte arrB[] = {0x04, 0x05, 0x06};
for(byte i = 0; i < 3; i++){
  Serial.write(arrA[i]);
}
for(byte i = 0; i < 3; i++){
  Serial.write(arrB[i]);
}

//or
byte arrC[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
for(byte i = 0; i < 6; i++){
  Serial.write(arrC[i]);
}

That’s why I say, there is rarely a use for it :wink:

As a bonus for writing in the middle of the array:

byte myArray[10];
//write at the start
myArray[0] = 42;
//write in the middle
myArray[5] = 100;
//or
//myArray[sizeof(myArray) / 2] = 100;

Under what conditions do you need to change characters in the data stream? Is it based on

Character count?
Value of past characters?
Value of future characters?

The last one is non-causal and is the only case where you'd need to store characters in an array in order to change some in the middle. If not do it "on the fly". Worst case, use a circular buffer as a FIFO with independent "write" and "read" pointers.

Koren12345:
byte array

So it is not saved as HEX at all, but as bytes

As I think has been mentioned previously in this thread HEX is only a way of representing the data to make it easier for humans to read, so when you do

byte array1[3] = {0x00 , 0x01 , 0x02};
byte array2[3] = {0x0A , 0x0B , 0x0C};

what is actually stored are the values 0, 1, 2, 10, 11 and 12 or if you want it in binary 00000000, 00000001, 00000010, 00001010, 00001011 and 00001100

septillion:
As you can’t transmit “an array” and with serial only bytes, there is NO difference for the receiving end between

byte arrA[] = {0x01, 0x02, 0x03};

byte arrB = {0x04, 0x05, 0x06};
for(byte i = 0; i < 3; i++){
  Serial.write(arrA[i]);
}
for(byte i = 0; i < 3; i++){
  Serial.write(arrB[i]);
}

//or
byte arrC = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
for(byte i = 0; i < 6; i++){
  Serial.write(arrC[i]);
}




That's why I say, there is rarely a use for it ;)

As a bonus for writing in the middle of the array:


byte myArray[10];
//write at the start
myArray[0] = 42;
//write in the middle
myArray[5] = 100;
//or
//myArray[sizeof(myArray) / 2] = 100;

… what he said :wink:

OK ,
I will try to answer all the questions: :slight_smile:

  1. @gfvalvo
    I need to enter some chars in the original message , because the device I'm sending to him - work wih another protocol
    so if I need to add chars before\in the middle\end of the message
    before and in the end it's not a problem
    in the middle - I'm doing it by searching for "0xA" - this is like comma in the old protocol and need to be replace with "\s; "

2.@septillion
I know how to enter data into specific place , but how do I add another array to old one ?
this is what I want to get
array3 = array 1 , array 2

Then DON’T start with two arrays in the first place! Memory IS limited

Instead of writing to a second array, just start writing that data to the place you want it to end up. You can even fake there are two arrays for functions that take an array as parameter. But as always, be careful not to write out of bound.

void writeToArray(byte a[]){
  for(byte i = 0; i < 3; i++){
    a[i] = i + 1;
  }
}

byte largeArray[10];

void loop(){
  writeToArray(largeArray);
  writeToArray(*largeArray[5]);
  //largeArray now is {1, 2, 3, 0, 0, 1, 2, 3, 0, 0}
}

A concrete example of an incoming message and the required outgoing message would be helpful.

It was undoubtedly convenient to use array manipulation in C#, but likely not necessary. I suspect that you can get by with some header arrays, separator arrays and trailing data arrays and choose what is appropriate to the protocol you're using.

Which is a long winded way of repeating gfvalvo's request for examples.

You could look up "linked lists".
But your spec for your data handling is so poor no one can really tell what you are doing or why you're doing it.