Go Down

Topic: Sending String over serial with two arduinos (Read 632 times) previous topic - next topic

svermigo

Mar 01, 2013, 03:45 pm Last Edit: Mar 01, 2013, 03:52 pm by svermigo Reason: 1
Hello, I hope im in good section :),
I have some troubles to get working serial communication between two arduinos. I found really nice library, where you can create a struct, it will be serialized and sent over serial. It should be deserialized and give you good results. But it doesnt work for me. When I use just integers in struct, works everything fine, but when I change to String, it doesnt work anymore. I think the problem will be probably in size of whole struct, but im not sure, im quite new in arduino.
Can anyone help me how to get around it and send strings between these two arduinos?


transmitter:


Code: [Select]
#include <EasyTransfer.h>
EasyTransfer ET;
struct SEND_DATA_STRUCTURE{
 String data;
 String filename;
};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

#include <Wire.h>  

void setup(){
 Serial1.begin(9600);
 ET.begin(details(mydata), &Serial1);
}

void loop() {
 mydata.data = "text dataaaa :-)";
 char temp[] = "file.txt";
 mydata.filename = temp;
 ET.sendData();
 delay(5000);  
}




receiver:

Code: [Select]


#include <EasyTransfer.h>
struct RECEIVE_DATA_STRUCTURE{
 String data;
 String filename;
};

RECEIVE_DATA_STRUCTURE mydata;
EasyTransfer ET;

void setup()
{
 Serial1.begin(9600);
 Serial.begin(9600);
 ET.begin(details(mydata), &Serial1);
}

void loop()
{

 if(ET.receiveData()){
   Serial.println(mydata.data);
   Serial.println(mydata.filename);
 }
}




EDITED:   I dont need to use this library, if there is another solution :)




zoomkat

Quote
Can anyone help me how to get around it and send strings between these two arduinos?


Not sure what the struct thing is, but sending strings should be fairly easy. Have you tested sending strings using the serial monitor?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

PaulS

Quote
Can anyone help me how to get around it and send strings between these two arduinos?

Your struct does not contain two strings. It contains two Strings. Strings are far different beasts from strings. Until 1.0.4 is released, they are to be avoided.

Replace the Strings with strings, and the transfer will work.

svermigo


Quote
Can anyone help me how to get around it and send strings between these two arduinos?

Your struct does not contain two strings. It contains two Strings. Strings are far different beasts from strings. Until 1.0.4 is released, they are to be avoided.

Replace the Strings with strings, and the transfer will work.


when I replace it, I got this error .. error: 'string' does not name a type
Do I need import any library?

Thanks

PaulS

Quote
error: 'string' does not name a type

Of course not. The term string is a shorter way of saying "NULL terminated array of chars".

Quote
Do I need import any library?

No. You simply need to use a char array.

svermigo


Quote
Do I need import any library?

No. You simply need to use a char array.


I have tried that allready, but I didnt find out, how to do it :( ..

Code: [Select]

struct SEND_DATA_STRUCTURE{
  char data[9];
};
...
mydata.data = "file.txt";


gives me  - error: invalid array assignment


so I tried
Code: [Select]

struct SEND_DATA_STRUCTURE{
  char data[9];
};
...
char temp[] = "file.txt";
mydata.data = temp;

same error - error: invalid array assignment

I also tried

Code: [Select]

struct SEND_DATA_STRUCTURE{
  char data[9];
};
...
char temp[] = "file.txt";
mydata.data = &temp[0];


error: incompatible types in assignment of 'char*' to 'char [9]'


Every time, Im getting error on the last row ..
I have found about 100 ways how it doesnt work :( .. can you try to give me one working example please ? :(

PaulS

Maybe you need to get a book on C, and learn HOW to work with strings. The strcat() and strcpy() functions do what you have tried every which way but correctly to do.

svermigo


Maybe you need to get a book on C, and learn HOW to work with strings. The strcat() and strcpy() functions do what you have tried every which way but correctly to do.


Thanks

Go Up