Skip to main content
Tweeted twitter.com/StackArduino/status/1421485804640247814
Fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31
[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}
[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}
byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));
byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));
fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17) 
     % communication established
end
fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17) 
     % communication established
end
[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}
byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));
fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17) 
     % communication established
end
[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}
byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));
fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17) 
     % communication established
end
edited body
Source Link
UserK
  • 559
  • 1
  • 11
  • 24

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}

In the third attempt I tried sending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

reads binary data from the device connected to the serial port object, obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 1117) 
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}

In the third attempt I tried sending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

reads binary data from the device connected to the serial port object, obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 11) 
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}

In the third attempt I tried sending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

reads binary data from the device connected to the serial port object, obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17) 
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

added 459 characters in body
Source Link
UserK
  • 559
  • 1
  • 11
  • 24

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10'));.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s); First -> Fail
      // Second attempt
      //xbee.write(s0x11);  -> Fail
      // doesn'tThird work,attempt
 Matlab receives number like: 32 orbyte 117,112message[] = {0x11,116 0x11};
      xbee.write(0x11message, sizeof(message)); 
    } 
  }
}

ThenIn the third attempt I tried to sendsending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

I am using inThe Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

reads binary data from the device connected to the serial port object, obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 11) 
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10'));.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read();  
    if(getData == 16)
    {    
      uint8_t s = 17; 
      // First attempt
      //xbee.write(s); // doesn't work, Matlab receives number like: 32 or 117,112,116
      xbee.write(0x11);
    } 
  }
}

Then I tried to send an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

I am using in Matlab the fread function which:

reads binary data from the device connected to the serial port object, obj, and returns the data

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software. Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx); 
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read(); 
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println(); 
    if(getData == 16)
    {           
      // First attempt   
      //uint8_t s = 17; 
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message)); 
    } 
  }
}

In the third attempt I tried sending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

reads binary data from the device connected to the serial port object, obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10')); 
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 11) 
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

enter image description here

deleted 39 characters in body
Source Link
UserK
  • 559
  • 1
  • 11
  • 24
Loading
Source Link
UserK
  • 559
  • 1
  • 11
  • 24
Loading