Serial.Write Data to arduino and then read it in matlab

4 views (last 30 days)
katherine keogh
katherine keogh on 2 Mar 2022
I have an IMU set up on an arduino UNO, it uses Serial Write to make a dataframe with the gyro writing the X, Y and Z variables. I then open Matlab and want matlab to be able to read the varibles and I cannot get it to work
Here is the data frame, Someone told me how to write it, btu didn't really provide much info on why each thing is done a particular way. Any further info here would be helpful. (all variables are uint8_t)
Serial.write(3); %random number
Serial.write(9) ; % Number of serial writes
Serial.write(0); %Write a 0 here, packet sequence which is irrelevant
Serial.write(2) % random number
Serial.write(4) ; % random number
Serial.write(T) ; %First Varible I want to measure
Serial.write(X);%First Varible I want to measure
Serial.write(Y);%First Varible I want to measure
Serial.write(Z);%First Varible I want to measure
I don't really know what I am doing with the matlab code
arduinoObj = serialport("COM6",9600)
flush(arduinoObj)
data = read(arduinoObj,4,uint8)
  • the 4 is also a random number, as far as i can tell thats the number of varibles I want to read which is 4

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!