Sending matrices with decimal elements from Simulink to arduino and vice versa

Hi,

To give a brief overview of my project, I am making a satellite, I'm using arduino as my controller and simulating my satellite model and sensors in simulink to test if my controller works. I intend to send data from simulink to arduino, have my arduino process the data and perform some calculations, and then send it back to simulink.

Right now I am just trying to send a receive my data from my arduino, the arduino code I'm using is as shown:

#include <MatrixMath.h>

float x;

void setup() 
{

  Serial.begin(9600);
 
}

void loop() 
{

if(Serial.available()>0){
  x = Serial.read();
}

Serial.write((byte*)&x, sizeof(x));
Serial.print(x);
delay(1000);

}

My simulink model is the attached image.

Right now I am only able to transmit integers to and from my arduino.
When I try to transmit a matrix of integers, I receive the elements of the matrix one by one.
When I send a decimal (Eg. 0.002) , the data I receive is rubbish.

The data I'm required to send is a matrix signal which decimal elements varying from 0~1. How can I achieve this?

Thanks!

When I send a decimal (Eg. 0.002) , the data I receive is rubbish.

The data you receive is the data you send.
How you interpret that data is a different matter, but that doesn't necessarily mean it is rubbish.

Serial data is sent a byte (not a float) at a time - unlike satellites, it's not rocket science.

Start here

AWOL:
The data you receive is the data you send.
How you interpret that data is a different matter, but that doesn't necessarily mean it is rubbish.

Serial data is sent a byte (not a float) at a time - unlike satellites, it's not rocket science.

Start here

I understand that the data is sent back to Simulink as a byte or bytes. But sometimes my decimals may require more than a byte. I'm looking for a way to collect all the bytes and then get the decimal number.

I'm looking for a way to collect all the bytes and then get the decimal number.

Is the sender sending binary data or ASCII data?

Did you READ AWOL's link?

PaulS:
Is the sender sending binary data or ASCII data?

Did you READ AWOL's link?

My bad, I didn't see that AWOL's guide was spread out across multiple posts.

Simulink sends binary data to the Arduino. I have the option to add a header and terminator to my binary data too. I'll try to code something out and post back here if I have any issues.

Thanks for the tips!

mngeow:
My bad, I didn't see that AWOL's guide was spread out across multiple posts.

Yeah, I missed that too.