Filling an array using a for loop and sending it through Bluetooth.

Hello, I raised the issue in my previous topic(LINK), but decided to give it a separate one since the main problem of that topic was already solved for me. The problem is, that I need to gather the information from the HC-SR04 proximity sensor and store it in an array along with the corresponding angle of the servo, that the sensor is placed on. Once the entire sweep of the servo is done, I want to send the data through HC-05 to my mobile app. Sending data with each every iteration causes a lot of disruption in the communication. The thing I managed to achieve is to get the data that is incomplete and presented as ASCII code. Below I will post the part of the code that I’m currently using.

  if(skan == true) { // po wywołaniu skanowania z poziomu aplikacji
  degree = 40;

    for (int p = 0; p <= 100; p++){ 
      obracanie.write(degree+p); // komenda pozwalająca na bezpośrednie zadanie kąta dla serwa
      distance = calculateDistance();// wywołuje funkcję odpowiedzialną za zmierzenie odległości z czujnika ultradźwiękowego
      dane[2*p] = distance;
      dane[2*p+1] = ",";
      dane[200+2*p] = degree+p;
      dane[200+2*p+1] = ",";
      Serial.println(dane[p]);
      Serial.println(dane[degree+p]);
      //int dane_int = atoi(dane);
      if(p == 100){
        skan=false; // po osiągnięciu zadanego końcowego kąta obrotu wyjdź z funkcji skanowania
        dane[201] = "|";
        BTserial.print(dane);//tu komenda do wysłania przez bt
        Serial.println(dane);
        //Serial.println(dane_int);
        //Serial.println(dane[2]);
     }
    }
  }

“dane” is declared as char dane[401] right now.
Thank you so much in advance for every response!

Edit: corrected from “dane[401” to “dane[401]”.

If I understand correctly dane is an array with 40 elements then you do this
    dane[200 + 2 * p + 1] = ",";so the array index will always be greater than 200. How is that supposed to work ?

The size of an array is 401, I missed the "]" in my previous post and it might look like it was [40]

it might look like it was [40]

It did
What is the data type of the array ?

By the way, I do not appreciate you changing your original post without noting that you had edited it which makes now my comment look silly

Sorry, didn't intend to do that!
As of now, data type of array is char. I need to send an array that looks something like this: [35, 35, 36, ...80|40, 41, 42 ... 140,]. I need both the separators so the mobile app can recognize the distance or degree sections and divide each iteration to process it into a graphic simulation of the area in front of the sensor.

I need to send an array that looks something like this: [35, 35, 36, ...80|40, 41, 42 ... 140,]

I am willing to bet that it looks nothing like that if it is ASCII, leaving aside the square brackets that you have misused.

You say

I need to gather the information from the HC-SR04 proximity sensor and store it in an array along with the corresponding angle of the servo,

If the servo is moving in regular steps you do not need to save the angle, only the distance reading for each step. Nor do you need to save data separators in the array as you can add them when you send the data

Answering the second part of your post, I agree with you, in the meantime I modified it a bit so I don't need to send angle readings.

As for the first part, on the serial port monitor I can see a bunch of :clubs:○◘Hf5u etc, end weirdly it does translate to 3-digit numbers that actually make sense when compared to the info I want to send. So sadly you would lose the bet :smiley: From what I managed to learn until now, it is not really possible to send 100 numbers at once using serial.print. The error I get during compilation says "call of overloaded 'println(int [200])' is ambiguous". I'm gonna try and send every single distance info after the for loop is done and gather it somehow in the mobile app.

So sadly you would lose the bet

Are you seriously telling me that your array looks like this

 [35, 35, 36, ...80|40, 41, 42 ... 140,]

You possibly mean it looks like this

 {35, 35, 36, ...80|40, 41, 42 ... 140,}

which is not the same thing at all

Earlier in the thread you said

I managed to achieve is to get the data that is incomplete and presented as ASCII code.

and that the array was declared as an array of chars. Are you still working with an array of chars and if so how do you get more than one character, such as 36, into a char ?

Maybe we're talking about slightly different things. What I mean is, for example if I get ":clubs:" in serial monitor, I can translate it to 226 153 163 in ASCII numbers. With the proper combination of symbols, spaces etc I was able to get numbers like 041 042 043 044 up to 127 after conversion, which corresponded to the angles I was sending.