Skip to main content

Posts

Showing posts with the label Matlab

Featured Post

Product Design of a 4 wheel differential drive robot

Use Matlab to read serial data

  Matlab is one big tool which you can play with.. Matlab can be configured to read serial data that can be send through a microcontroller. Here is the code for Matlab to read a single line and print. Assume that you are sending ascii character values through microcontroller separated by new line. Here is the Matlab code to receive the data. 1: obj1 = instrfind( 'Type', 'serial', 'Port', 'COM13', 'Tag', ''); 2: % Create the serial port object if it does not exist 3: % otherwise use the object that was found. 4: if isempty(obj1) 5: obj1 = serial( 'COM13'); 6: else 7: fclose(obj1); 8: obj1 = obj1(1) 9: end 10: obj1.BaudRate=4800; 11: set (obj1, 'Parity', 'even'); 12: set (obj1, 'StopBits', 2.0); 13: fopen(obj1); 14: data1=fscanf(obj1, '%s'); 15: data1=fscanf(obj1, '%s'); %Assume that you are sending characters and 8 bit binary no....