Pages: [1]   Go Down
Author Topic: Communication between Multiple Arduino's through Soft-serial library  (Read 766 times)
0 Members and 1 Guest are viewing this topic.
pakistan
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
i used soft-serial library to communicate multiple Arduino but the problem i am facing is that the data corrupts after some intervals as show in the below image, could any one please tell me how to solve this issue? thanks

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 553
Posts: 46286
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
as show in the below image
What image? I don't see any image.

I don't see any code, either.
Logged

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

oh sorry i think the image link was corrupted,
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 16
Posts: 907
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're using transparent mode to send the data, this can happen.  The packet can get split into two and you get a mess.  If you switch to api mode, use the XBee library and be sure to check the checksum on the packet.  This kind of thing most often happens when you have the baudrate set high and are really putting the data into the XBee rapidly.  It also happens when you have a number of XBees and there isn't enough guard time for the devices to sync up properly.

The latest XBee library supports software serial quite nicely and can help you with this kind of thing.  Hunt around though and make sure you have the latest library.
Logged

Trying to keep my house under control http://www.desert-home.com/

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

thanks for reply, the first thing i clear to you that i am not using xbee , i communicate it through wire medium, secandly can you please tell me how to switch to API mode?

below is the code for the master i am using 
Code:
#include <SoftwareSerial.h>

SoftwareSerial serialSlave1(3, 2);

int indexSlave1=0;         
byte valSlave1[17];

void setup() 
{
  Serial.begin(115200);
  serialSlave1.begin(28800);
}
 
    float qSalve1[4],
 
    byte * f_1Slave1 = (byte *) &qSalve1[0];
    byte * f_2Slave1 = (byte *) &qSalve1[1];
    byte * f_3Slave1 = (byte *) &qSalve1[2];
    byte * f_4Slave1 = (byte *) &qSalve1[3];
   
void loop()
{
  while(1<serialSlave1.available())
    {
       byte ch = serialSlave1.read();
       valSlave1[indexSlave1]=ch;
       indexSlave1++;
     if(ch=='\n'){ indexSlave1 = 0;} 
    }

       for(int fs=0;fs<4;fs++) f_1Slave1[fs]= valSlave1[fs];
       for(int fs=0;fs<4;fs++) f_2Slave1[fs]= valSlave1[fs+4];
       for(int fs=0;fs<4;fs++) f_3Slave1[fs]= valSlave1[fs+8];
       for(int fs=0;fs<4;fs++) f_4Slave1[fs]= valSlave1[fs+12];
       
        Serial.print(qSalve1[0],4);
        Serial.print(",");
        Serial.print(qSalve1[1],4);
        Serial.print(",");
        Serial.print(qSalve1[2],4);
        Serial.print(",");
        Serial.print(qSalve1[3],4);
        delay(15);
       
}
Logged

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

thanks for reply, the first thing i clear to you that i am not using xbee , i communicate it through wire medium, secandly can you please tell me how to switch to API mode?

below is the code for the master i am using 
Code:
#include <SoftwareSerial.h>

SoftwareSerial serialSlave1(3, 2);

int indexSlave1=0;         
byte valSlave1[17];

void setup() 
{
  Serial.begin(115200);
  serialSlave1.begin(28800);
}
 
    float qSalve1[4],
 
    byte * f_1Slave1 = (byte *) &qSalve1[0];
    byte * f_2Slave1 = (byte *) &qSalve1[1];
    byte * f_3Slave1 = (byte *) &qSalve1[2];
    byte * f_4Slave1 = (byte *) &qSalve1[3];
   
void loop()
{
  while(1<serialSlave1.available())
    {
       byte ch = serialSlave1.read();
       valSlave1[indexSlave1]=ch;
       indexSlave1++;
     if(ch=='\n'){ indexSlave1 = 0;} 
    }

       for(int fs=0;fs<4;fs++) f_1Slave1[fs]= valSlave1[fs];
       for(int fs=0;fs<4;fs++) f_2Slave1[fs]= valSlave1[fs+4];
       for(int fs=0;fs<4;fs++) f_3Slave1[fs]= valSlave1[fs+8];
       for(int fs=0;fs<4;fs++) f_4Slave1[fs]= valSlave1[fs+12];
       
        Serial.print(qSalve1[0],4);
        Serial.print(",");
        Serial.print(qSalve1[1],4);
        Serial.print(",");
        Serial.print(qSalve1[2],4);
        Serial.print(",");
        Serial.print(qSalve1[3],4);
        delay(15);
       
}
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 16
Posts: 907
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, somehow I got the idea you were using an XBee.  To address the problem you're seeing, why are you initializing like this:

byte * f_1Slave1 = (byte *) &qSalve1[0];
Logged

Trying to keep my house under control http://www.desert-home.com/

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

this is just because i use byte by byte value of a float variable, the slave send float value byte by byte and the master receive it in the same way. i think this may not be an issue, i some how reach to this problem that is it may be due to the interrupt call by any library either in slave or in master which is not good for Soft-serial communication.but did not know how to solve it smiley-sad
« Last Edit: December 19, 2012, 02:42:33 pm by sajidzaman » Logged

Pages: [1]   Go Up
Jump to: