Pages: [1]   Go Down
Author Topic: how to extract data from x-sim to arduino?  (Read 2295 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using X-sim  to get the game data from Life For Speed. from the x-sim, i have to send data to arduino. i have no idea about the program to extract the speed value from x-sim. i need help with the programming.  smiley-roll-sweat i'm using this program (i don't know it's right or wrong) :

int Speed;
char kind_of_data;

void setup(){

  Serial.begin(115200);

  pinMode(9, OUTPUT);

}

void loop()
{
 
  while(Serial.available() > 0)
  {

    kind_of_data = Serial.read();
    if (kind_of_data == 'S' ) Read_Speed();


  }
 

}

void Read_Speed(){

  delay(2);
  int Speed100 = Serial.read()- '0';
  delay(2);
  int Speed10 = Serial.read()- '0';
  delay(2);
  int Speed1 = Serial.read()- '0';

  Speed = 100*Speed100 + 10*Speed10 + Speed1;
  analogWrite(9,map(Speed,127,255,0,710));
  Serial.print(“Speed”);
  Serial.print(Speed);
  Serial.print(‘\n’);
}

: but still cannot extract the value.  smiley-cry could anyone please help me about this extracting the data. thanks  smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void Read_Speed(){

  delay(2);
  int Speed100 = Serial.read()- '0';
  delay(2);
  int Speed10 = Serial.read()- '0';
  delay(2);
  int Speed1 = Serial.read()- '0';

  Speed = 100*Speed100 + 10*Speed10 + Speed1;
  analogWrite(9,map(Speed,127,255,0,710));
  Serial.print(“Speed”);
  Serial.print(Speed);
  Serial.print(‘\n’);
}
If there is a byte of serial data to read, read it. If that byte is an 'S', call this function. Wait around doing nothing for two milliseconds, and hope like hell that another character arrives while we're taking a nap. Then, repeat twice more.

That's a lot of hoping.

But, suppose we do get lucky and get 3 characters. You assume that they are all represent numbers. That is not necessarily a valid assumption.

But, suppose that that does happen. Now, I don't know what numbers you are sending. But, suppose that the number 210 was sent (that is in the from range of the map, so it might happen). Speed will be 210 as input to the map() call, so the output will be about 460.

Now, what do you suppose that analogWrite() does with a value that is out-of-bounds, as most of the values output by map will be?

Finally, what is on the receiving end of the Serial data that the Arduino is sending?

There is a lot that is missing from your post. Does the RX light on the Arduino blink when x-sim is sending it data? Do you have a clue what x-sim is actually sending it? Do you understand the issues with how you are reading data? Where did the numbers in the map() call come from? Do you understand that most of the output values will be invalid for the analogWrite() call?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-sad I'm totally lost right now. I'm new to both x-sim and arduino. it's a group project and my task is to extract the game data from x-sim to arduino uno.. I search through forums and got the above-mentioned program in some posts of the forums.. I'm still don't fully understand what am I suppose to do and how am I suppose to get the values...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm still don't fully understand what am I suppose to do and how am I suppose to get the values.
You are going to need some external device on which to display data, like an LCD. Simply echo each character that arrives at the serial port to that device. When you know what the incoming stream looks like, you can figure out how to parse it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

first of all, thanks for the reply.. smiley
so, do i need external device like LCD to see the data arrived from x-sim profiler? can monitor the value on arduino without the external device? the main thing is that RX light from ardunio doesn't light up. i'm connecting profiler and arduino by TX, RX of sparkfun FTDI Basic. i plug in the FTDI basic in profiler PC, TX and RX of FDTI go to TX and RX of arduino, and USB of arduino goes to another laptop which is doing arduino programming and receiving value(i'm not sure about using this but my friend from our group also using it.). i write simple programming on arduino like " if(Serial.available()) { int val = Serial.read() - '0'; Serial.print(val); } and for the profiler USO output parser, "S~a01~E" . while i'm sending data, TX from FTDI basic is light up but there is no light on arduino RX and arduino didn't receive anything. could you please guide me whether it might be profiler setting problem or i need to do more on programming or the connection on the hardware is wrong.. thanks alot..
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so, do i need external device like LCD to see the data arrived from x-sim profiler? can monitor the value on arduino without the external device?
Sure, the Arduino can read it, but it can't tell you what it received without some means of doing so, can it?

Logged

Pages: [1]   Go Up
Jump to: