Skip to main content
2 of 2
added 1000 characters in body
Majenko
  • 105.9k
  • 5
  • 82
  • 139

The simple answer is: don't.

At the moment you are trying to assign integers to chars, and that just won't fit. It's like a round peg in a square hole. Or more like trying to force a bowling pin through a hose pipe. It just isn't going to fit.

So you either need to "print" the values into your final string (say with sprintf()) or just don't build up a string at all and print the values directly. And while you're at it, use some loops to make your code simpler:

for (int i = 0; i < 14; i++) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
}

for (int i = 23; i > 13; i--) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
}

Serial.print(Temp_read);
Serial.print(",");
Serial.print(HV_Read);
Serial.print(",");
Serial.print(SPD);
Serial.print(",");
Serial.println(DISCONNECTOR);

If you really need to create a string the easiest way is probably with sprintf (or snprintf to prevent buffer overflows):

char sendBuffer[200]; // Enough room for 28 integers of 1-5 characters, plus commas.

snprintf(sendBuffer, 200, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
    Mod_current[0], Mod_current[1], Mod_current[2], Mod_current[3],
    Mod_current[4], Mod_current[5], Mod_current[6], Mod_current[7],
    Mod_current[8], Mod_current[9], Mod_current[10], Mod_current[11],
    Mod_current[12], Mod_current[13], Mod_current[14], Mod_current[23],
    Mod_current[22], Mod_current[21], Mod_current[20], Mod_current[19],
    Mod_current[18], Mod_current[17], Mod_current[16], Mod_current[15],
    Mod_current[14], Temp_read, HV_Read, SPD, DISCONNECTOR);

int len = strlen(sendBuffer);
Serial.println(sendBuffer);
Serial.print(len);
Serial.println(" bytes");

(note: I think I got the right number of parameters there)

Majenko
  • 105.9k
  • 5
  • 82
  • 139