Serial communication lot of variables

Hi,

I need to send more than 75 variables from an arduino-like (Spark Core) to an arduino and build an array with the data that have been received. I have try a simple serial.write and serial.read but over 10 variable it crash.

Thanks

Where’s your code?

Sounds like you did something wrong.

The code on the arduino-like is a simple Serial.write. I have confirmed that this is working by doing this on the arduino:

 if(ser.available()){
   Serial.println(ser.read());
}

The code on the arduino is:

#include <SoftwareSerial.h>
SoftwareSerial ser(2,3);
int var[10];
void setup() {
  Serial.begin(9600);
  Serial.println("SERIAL: BEGIN");
  
  ser.begin(9600);
}
void loop() {
       if(ser.available() >10 ){
for(int i=0; i < 9; i++)  {
var[i] = ser.read();
Serial.println(var[i]);
}

}}

Serial.read() returns a character (8-bit value), NOT an int. So, you’re reading half an int into var[0], the other half into var[1], etc. You need to read() two bytes, and assemble them back into an int. One way to do that is:

var[i] = ser.read() << 8;
var[i] |= ser.read() & 0xff;

This is assuming the MSB is sent first. I’m not sure if that is correct in this case, but a couple of print statements will tell you for sure.

Regards,
Ray L.

AND Serial.println will be sending a newline character after each of those.

The examples in serial input basics should meet your requirement

...R

Thanks guys ! I'm going to try that and come back if I have other issues.