Go Down

Topic: MATLAB Example (Read 204 times) previous topic - next topic

Electronique-Mixte

Jul 06, 2018, 04:40 pm Last Edit: Jul 25, 2018, 01:48 pm by Electronique-Mixte
This is an exemple to send infinite (x,y) data to Arduino:

% Matlab code
...
Startt='#';     % Start char
Endd='*';       % End char
WriteData1(xi,yi,Startt,Endd, SerialCOM); % Data Tx


function WriteData1(xi,yi,Separa,EndTrans, SerialCOM)

for i=1:length(xi)
  x_y=uint8([yi(i)-1, xi(i)-1]);
  x_y_c=int2str(x_y);
  fwrite(SerialCOM, Separa);pause(0.1);
  fwrite(SerialCOM, x_y_c); pause(0.1);
  fwrite(SerialCOM, EndTrans); pause(0.1);
end

end



// Arduino code

/* ****  Get data fom UART  **** */
...
while (1)
{
    // Get and set data
    y = Serial.parseInt();
    x = Serial.parseInt();

    if (Serial.read() =='#') break;

}
...

You may get more details here: https://www.electronique-mixte.fr/projets-matlab-microcontroleur-1-commande-graphique-dune-matrice-des-leds-avec-maltab/





Go Up