Pages: [1]   Go Down
Author Topic: Sending String over serial with two arduinos  (Read 601 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I hope im in good section smiley,
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:
#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:

#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 smiley



« Last Edit: March 01, 2013, 09:52:10 am by svermigo » Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9586
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad ..

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


gives me  - error: invalid array assignment


so I tried
Code:
struct SEND_DATA_STRUCTURE{
  char data[9];
};
...
 char temp[] = "file.txt";
 mydata.data = temp;

same error - error: invalid array assignment

I also tried

Code:
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 smiley-sad .. can you try to give me one working example please ? smiley-sad
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: