Advertisement
jasirgo

Read Arduino data (Matlab code)

Oct 17th, 2012
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.54 KB | None | 0 0
  1. %Delete previous connections
  2. delete(instrfind({'Port'},{'/dev/tty.usbmodem621'}));
  3. %Create a serial connection
  4. s = serial('/dev/tty.usbmodem621','BaudRate',9600,'Terminator','CR/LF');
  5. warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
  6. %Open Port
  7. fopen(s);
  8. %Initialize the variables
  9. Nvalues=100; %Number of values ​​we want to read
  10. m1=zeros(1,Nvalues);
  11. i=1;
  12. k=0;
  13.  
  14. while k<Nvalues
  15. %Read the serial port
  16. a = fscanf(s,'%f.%f')';
  17. m1(i)=a(1);
  18. %Draw the figure
  19. figure(1);
  20. plot(m1);
  21. %Increment the counter
  22. i=i+1;
  23. k=k+1;
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement