Arduino - MATLAB Serial Communication (different data)

3 Ansichten (letzte 30 Tage)
valio
valio am 22 Mai 2020
Hi,
I have this system in Arduino: 3 IMUs and 2 Sensors EMG. I need to transfer data through serialport obj at different time. For the first ones the sampling rate has to be 100 Hz, and for the other 10 KHz,
What I have in Arduino is that:
  • For EMG, when comes out the interrupt OVF (each 100us, then 10KHz):
int16_t sensorValue = analogRead(A0);
int16_t sensorValue1 = analogRead(A1);
byte H = highByte(sensorValue);
byte L = lowByte(sensorValue);
byte H1 = highByte(sensorValue1);
byte L1 = lowByte(sensorValue1);
byte reading [] = {H,L,H1,L1};
Serial.write(reading, 4);
  • And this is what happens when are gone 10 ms (100Hz) referring the iteration for IMU data (where gyro is gyroscope, acc is accelerometer and mag is magnetometer and each one is numered:
byte reading[] = {gyro_x_H, gyro_x_L, gyro_y_H, gyro_y_L, gyro_z_H, gyro_z_L, gyro_1_x_H, gyro_1_x_L, gyro_1_y_H, gyro_1_y_L, gyro_1_z_H, gyro_1_z_L,
gyro_2_x_H, gyro_2_x_L, gyro_2_y_H, gyro_2_y_L, gyro_2_z_H, gyro_2_z_L, mag_x_H, mag_x_L, mag_y_H, mag_y_L, mag_z_H, mag_z_L,
mag_1_x_H, mag_1_x_L, mag_1_y_H, mag_1_y_L, mag_1_z_H, mag_1_z_L, mag_2_x_H, mag_2_x_L, mag_2_y_H, mag_2_y_L, mag_2_z_H, mag_2_z_L,
acc_x_H, acc_x_L, acc_y_H, acc_y_L, acc_z_H, acc_z_L, acc_1_x_H, acc_1_x_L, acc_1_y_H, acc_1_y_L, acc_1_z_H, acc_1_z_L,
acc_2_x_H, acc_2_x_L, acc_2_y_H, acc_2_y_L, acc_2_z_H, acc_2_z_L
};
SerialUSB.write(reading, 54);
Now, given that I have to put one more byte in each data transmission, for instance 0x01 for EMG and 0x02 for IMU, the question is: In Matlab I have to put a control about the first byte?
Something like this pseudocode:
first_byte = (read(SerialPort,1,'uint8'))
if first_byte == 0x02 {
raw_data(count,:) = (read(SerialPort,54,'uint8'))
}
if first_byte == 0x01 {
raw_data(count,:) = (read(SerialPort,4,'uint8'))
}
This code I think will provide several delays. Am I wrong? Could it work? Is there any other possibility more reliable?
Your help is really appreciated.

Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by