Newcomer question regarding X-Sim & Arduino comms

New member? Introduce yourself here!

Newcomer question regarding X-Sim & Arduino comms

Postby MikeyTT » Thu 10. Jan 2013, 18:41

Hi all. Certainly had my eyes opened recently to the "sim rig" world, never knew it existed. I only started looking after getting into pCars and seeing a self made dash on YouTube and thought, "I could do that........ Surely.....How hard could it be?" ;-)

So far I'm pretty happy with my progress of a self made dash (maybe get to a full motion rig one day). I have X-Sim running with rFactor2 (pCars has no API yet) and I'm receiving data, which took a while, but I got there. I also have an Arduino that's now receiving the data and I can get Revs, Speed, Gear and I can drop that onto a 4-digit 7-segment display. I only have 1 at present, so with a quick code change I can get it displaying all info from x-sim.

What I want the dash to do tho is to send info back from the Arduino to the game, this is for switches, etc. So without x-sim in the equation I can send data from the Arduino to a C# app and although I've not done it yet I think it's fairly easy to then send keystrokes to rFactor2. But if I put x-sim back in the loop there doesn't appear to be a way I can extract data from the Arduino, it's a 1-way street if I understand it correctly.

This is where I'm a little stuck. I can think of two ways around this so far, but neither is particularly great:
  • Get another Arduino connected via USB to run the switches and output from this Arduino to a C# app
  • Create a virtual serial device in the PC and get x-sim to send data to that. I'll create a C# app to then attach to the Arduino, which will grab data from the x-sim feed and just offload it to the Arduino unchanged. But as the serial port to the Arduino is connected to the C# app I can also read from it and then pass that to rFactor as keypresses, etc.

The latter approach is double handling the data, which is never good and the first requires additional hardware and USB connectivity + more to go wrong. So I'm hoping that there is some obvious route, existing library, plugin or something I'm missing that will set me right.

Mike...

** I posted this on another forum as well in the hope to get the widest coverage of ideas [Doesn't appear I can name it as I get a * instead of the name] **
MikeyTT
 
Posts: 2
Joined: Sat 22. Dec 2012, 04:09
Has thanked: 0 time
Been thanked: 0 time

Re: Newcomer question regarding X-Sim & Arduino comms

Postby sirnoname » Thu 10. Jan 2013, 18:51

You can make the arduino usb port to be a keyboard, a serial port and a joystick at the same time.
A component device is the virtual HUB.

An Joystick example:
http://hunt.net.nz/users/darran/weblog/a3599/
This example can be expanded by another HID device which can be used as control pipe like you use a serial port but with the HID libraries. Axelsons book "USB Complete" is usefull here.

And yes, USO is one way, you need to use the plugin source code for bidirectional communication. The receiving way can call global keyboard events out of the plugin.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: Newcomer question regarding X-Sim & Arduino comms

Postby MikeyTT » Thu 28. Feb 2013, 21:08

Apologies for the late reply. I did read your post and I've since bought a Leonardo to try it out, but not managed to get that far yet. The Uno can't do what you suggested.

What I did, while I was waiting for the Leonardo, was to look a little harder at X-Sim and found that it can output over the network as well as or instead of a COM port. So I wrote a bit of C# to be in the middle, but it at least now gives me the option of controlling in and out data to the Arduino.

I've been busy at work, so I've not had much chance to take this any further.

Thanks for pointing me in the HID direction tho, Mike...
MikeyTT
 
Posts: 2
Joined: Sat 22. Dec 2012, 04:09
Has thanked: 0 time
Been thanked: 0 time


Return to New users start here - FAQ

Who is online

Users browsing this forum: No registered users and 3 guests

cron