Hello,
I am trying to send 16bits read analog value of a servo motor to Simulink/Matlab software through serial communication protocol. Actually, I already sent an 8bit value & I read it on matlab, but I couldn't do the same with 16bits value read (0-1023 analog read). here is the arduino code I am using :
#include <SCServo.h>
SCSCL sc;
union Data{ uint16_t now; } data;
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
Serial.begin(115200);
Serial1.begin(1000000);
sc.pSerial = &Serial1;
}
void loop() { // put your main code here, to run repeatedly:
uint16_t sensorVal = sc.ReadPos(2);
union Data data;
data.now = sensorVal;
Serial.write(0xCC); // Send the start byte
Serial.write((sensorVal >> 8) & 0xFF); // Send the upper byte first
Serial.write(sensorVal & 0xFF); // Send the lower byte
delay(10); }
and here is the simulink model:
As you can see in the arduino code, I am trying to separate the 16bits data to 2 of 8bits data but in vain...
the display shows wrong data values
Can you please give me some ideas about where how could this work?


