I want to send a simple data from Matlab to one Arduino connected with PC and then that arduino will send the received data to another arduino via xbee. To think it simply suppose I want to send '5' to Arduino 1. After receiving the '5', Arduino 1 will send that '5' to Arduino 2 via xbee connected with both the arduinos. I am not getting any data in the last Arduino. And while using by Matlab, serial monitor is locked; so I can't understand whether even Arduino 1 is getting the data from Matlab or not.
I checked the previous queries but didn't find anything suitable.
Matlab is running in my PC, I connected Arduino-1+Xbee with my PC; And then powered another Arduino-2+Xbee by battery. So, did you mean sending Matlab command to connected Xbee+arduino is technically not possible? Will SoftwareSerial work?
Could you please let me know whether is it possible to use Matlab with Arduino+Xbee? Or I have to go for something else (rather than Matlab) to accomplish this?
MatLab sent you data. Why do you need to send that data back to MatLab?
I want to send one data [suppose like '1234'] to one arduino. Arduino will process the data and send it to other arduino via xbee. Matlab is not sending to two arduino+xbee.
For what? To talk to the XBee? That depends on how the XBee is connected to the Arduino.
I mentioned SoftwareSerial incase the arduino can't read command/data from Matlab while connected with Xbee. As you said it is possible; I think I should discard this idea. And for just the query my Series 1 Xbee is connected with Arduino UNO R3 via https://solarbotics.com/product/51835/.
I tried this simple blinking experiment; which works when only arduino is there but if I connect xbee, it is not working.
For Arduino:
int ledPin=13;
int matlabData;
void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available()>0) // if there is data to read
{
matlabData=Serial.read(); // read data
if(matlabData==1)
digitalWrite(ledPin,HIGH); // turn light on
else if(matlabData==2)
digitalWrite(ledPin,LOW); // turn light off
}
}
For Matlab:
clear all
clc
answer=1; % this is where we'll store the user's answer
arduino=serial('COM4','BaudRate',9600); % create serial communication object on port COM4
fopen(arduino); % initiate arduino communication
while answer
fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); % ask user to enter value for variable answer
end
fclose(arduino); % end communication with arduino
How can I make the arduino to receive the blinking command even when it is connected with Xbee?