Arduino,Xbee,Matlab project
3 次查看(过去 30 天)
显示 更早的评论
Hi Folks, I am trying to plot the real time graph of all the axes of the accelerometer wirelessly by XBee through MATLAB. I have achieved the following till now : On the transmitter side, I have an Arduino connected with an Xbee shield. I am using a Series 2 Xbees for this purpose. I have an ADXL335 breakout board accelerometer hooked in to the analog pins Arduino+Shield combo and also the XBee ( Co-Ordinator API) on the shield . On the receiver side, I have an XBee (Router AT) connected to a computer which will record the output and plot it on MATLAB. I also wanna mention that I am using the Arduino library for MATLAB for the Arduino code. Now when i wire up the Arduino ( i.e i dont use the Xbee) then i get a perfect output of all the axis of the accelerometer. but when i hook in the Xbee and try to communicate with the arduino i get nothing. For eg. when use the Xbee the command to plot the graph is: a = arduino(COM X) ; where X is the COM port where the Arduino is connected. Now what changes should do in the command when i connect my Xbee? Recalling again that my Arduino and accelerometer are not connected to the computer but my receiver side Xbee is.
Here is my MATLAB code:
a.pinMode(15,'input'); a.pinMode(16,'input'); a.pinMode(17,'input'); a.pinMode(18,'output'); a.pinMode(19,'output'); a.digitalWrite(18,0); a.digitalWrite(19,1); xval = zeros(); yval = zeros(); zval = zeros();
xval(1) = a.analogRead(3); yval(1) = a.analogRead(2); zval(1) = a.analogRead(2);
pause(.001);
for i = 2:1000
xval(i) = a.analogRead(3);
yval(i) = a.analogRead(2);
zval(i) = a.analogRead(2);
xmod = (xval-496)/300;
ymod = (yval-511)/300;
zmod = (zval-508)/300;
subplot( 3,1,1)
plot(xmod, 'r');
axis([1 1000 -0.5 0.5]);
title( 'x' );
subplot( 3,1,2)
plot(ymod, 'r');
axis([1 1000 -0.5 0.5]);
title( 'y' );
subplot( 3,1,3)
plot(zmod, 'r');
axis([1 1000 -0.5 0.5]);
title( 'z' );
pause(0.001);
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!