Sending decimals to arduino using simulink

318 views Asked by At

As part of a project, I'm running a Hardware-In the-Loop (HIL) test using simulink and arduino. To give a brief overview, I'm building a satellite and using reaction wheels as my actuator. The physical satellite model is modelled in Simulink and my arduino controls how fast the wheel spins.

I'm trying to send data to my arduino uno using the following simulink setup:

Simulink Diagram

and the following is my arduino code to receive and send the data back to simulink:

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);

}

I've noticed that I am only to send intergers as uint8 variables, which limits my numbers to be as big as 256. Also, whenever I try to send a decimal, what I get back on matlab is rubbish.

Is there a workaround for this? Or am I doing something wrong in my arduino code.

Thanks!

0

There are 0 answers