memory saving serial data transmission

Hi everyone! I have an ADC that send sensors data to Arduino (let say that those data are rapresented as int from 2500 to 5000). I need to send these data to a Raspberry trough bluetooth serial connection.

Data sent from the Arduino have this layout;

data1,data2,data3,…data7
data1,data2,data3,…data7

for example

2536,4263,4235,4898,2636,4632,3223
3464,3524,4542,3645,3456,3454,4599

right now I’m using this way to transmit data:

  for (int i = 0; i<7; i++) {
      

      bt.print(val_average[i], DEC); // il valore
      if (i<6){
       
      
        bt.print(",");
        }
  }
  bt.println();
 

  delay(100);

from the Raspberry side I’m using

line=serial.readline()
file.write(line)

It works, but if I get it right, every digit sent in this way is rapresented as a char, so 8 bit.
2536 → 48=32 bit
so each line is 32
7+ 6*8 byte (commas) + EOL char

How can I reduce the amount of byte used?
I was thinking, since the layout is allways the same, to get rid of the commas and send 2byte for each sensor value and then translate everything from raspberry side.

for example
sensoreValue= 3467 → 110110001011 -->00001101 and 10001011
so that

//arduno side
Serial.print(3467); //old one

//should became something like

Serial.write(0b00001101);
Serial.write(0b10001011);

I don’t know if it is possible or if there is something already implemented. Please, give me your advice.

thanks for your time, hope to hear you soon,

Dario

How can I reduce the amount of byte used?

On the sending end? Or on the receiving end?

Changing ro sending binary data will reduce the number of bytes sent, but will not save any significant amount of memory, since each int is converted to a string on the fly. In addition, it is MUCH harder to keep binary data in sync. Remember that serial data is NOT guaranteed to be sent and received.

PaulS:
On the sending end? Or on the receiving end?

I'd like to reduce the size of the data sent from the arduino.

but it isnt possible to send just one ASCII from Arduino so for example, if i want to send 250 I just send ' ú ' that corrispond to 11111010 that is 250? The problem here is that not all the 8 bit combinations have an ASCII match. Am I wrong?

Any idea is welcome.

Have a look at this Python Binary Data demo.

You have not said WHY you want to reduce the amount of data that is transmitted. If time is the problem have you tried a higher baud rate. An Arduino should work fine at 500,000 baud or 1,000,000 baud.

It is very much easier to debug a program that sends human readable data.

...R

The problem here is that not all the 8 bit combinations have an ASCII match. Am I wrong?

No, and yes. There is not, for instance, an ASCII character that corresponds to 219, for instance. But, so what?

uint8_t needToSendThis = 219;
Serial.write(needToSendThis);

will send the VALUE 219, even though it does not have a printable character equivalent.

Having said that, if you need to send 4 values, 219, 129, 43, and 17, and one of them gets lost, what are you going to do about it? How will you know? The next set of values might be 220, 100, 150, and 127. In the stream 219, 129, 17, 220, 100, 150, 127, ..., How are you going to notice that the value for the 3rd variable got lost?