PDA

View Full Version : Arduino Interface Program DVA2FSX



diegov
01-04-2012, 04:47 AM
Hi Fellow Cockpitbuilders,

I've been a big fan of Phidget cards, but i think i have found a new favourite, the Arduino Uno!.. This card lets me have 6 analog inputs driven with pots and a mixture of 13 digital inputs or outputs, of which the outputs can not only be used to drive LED's and relays, etc.. but also Servos and dc motors!!!! The best bit of all this card cost $30! the equivalent with Phidgets would set you back $150+..

Anyway, i have written a small program to interface my hardware through the Arduino to FSX. Currently i am interfacing my ailerons,elevators and tiller, plus some push buttons, plus using a servo. If anyone out there is at a similar stage in their interfacing and is looking or has an arduino + a sensor shield and would like to help test this software.. please let me know... Here are some snaps of the early beta!

603160326033

Cheers
Diego

AK Mongo
01-04-2012, 09:52 AM
Diego,

This is a very clean looking interface! How is it different than what Jim is doing with Link2fs though? I don't mean to sound ignorant, but am looking into arduino for servo/stepper powered gauges due to their cost and versatility.

More info would be great!

Reid

diegov
01-05-2012, 07:25 PM
Hey Reid,

I reallly havent looked into Linkfs too much, so i cant really comment. This program is meant to be very close to plug and play, from the upload of the required Arduino code, to the configuration of the inputs/outputs and servos. It uses FSUIPC to communicate to Flight Simulator. It logically divides the card into 3 sections, Analog inputs, digital inputs and servo outputs. You have access to 6 analog sensor inputs, 6 digital/switch inputs and 6 servo outputs. Each of these is configured via the UI. The servo page allows you to apply a condition on when the servo should be powered for example for configuring a TQ's autothrottle.

Im believe Jim's program is more flexible in that it allows you to drive LCD displays and etc, where as my program is really built for converting inputs to Flight Simulator values and also powering servos...

I'm still working through my beta code, but as mentioned before, i have the sensors connected to my control column, and the servo is connected to my yoke and uses a conditional expression to power on and off, so when the MCP is on and HDG or LNAV is selected, the servo moves my yoke.

Cheers
Diego

AK Mongo
01-06-2012, 12:17 AM
That is really a neat way to go!

I would really like to build steam gauges for my GA setup. A user friendly interface to drive servos would be an outstanding start. Especially if it were arduino based instead of phidgets (much cheaper!)

Can your software recognize more than 1 card, or could it be custom configured so it could for example notice no inputs but drive 18 servos?

I presume you are using an Uno?

Thanks for your efforts, you are doing a pretty neat thing!

Reid

737dragon
01-06-2012, 06:11 PM
Hi Fellow Cockpitbuilders,

I've been a big fan of Phidget cards, but i think i have found a new favourite, the Arduino Uno!.. This card lets me have 6 analog inputs driven with pots and a mixture of 13 digital inputs or outputs, of which the outputs can not only be used to drive LED's and relays, etc.. but also Servos and dc motors!!!! The best bit of all this card cost $30! the equivalent with Phidgets would set you back $150+..

Anyway, i have written a small program to interface my hardware through the Arduino to FSX. Currently i am interfacing my ailerons,elevators and tiller, plus some push buttons, plus using a servo. If anyone out there is at a similar stage in their interfacing and is looking or has an arduino + a sensor shield and would like to help test this software.. please let me know... Here are some snaps of the early beta!

603160326033

Cheers
Diego

Am I very very interested in his software, have Aruduino Uno, Mega, and the MAx7219 and AS1106 to control LEds\Displays, PCB is made and I am interested in your soft, you can give me more information??

Here you have my mail 737dragon@gmail.com

diegov
01-07-2012, 07:33 AM
Hey Reid,

At the moment it is limited to one card per PC. I would have to figure out a way to allow multiple modules to work correctly on 1 PC independently of which com port it is connected to. Or i may look at upgrading the code to also work with the Mega which allows for more outputs. This requires a little more work as the Arduino itself has to be programmed and as you have pointed out, im only using the Uno at the moment, so small steps.

The one thing i have noticed is that to power more than 1 servo, you will need to wire in an external power supply as the onboard regulator will start to get really hot and possibly burn out above 1 amp. This is where phidgets servo card shines, its onboard regulator will hand up to 12 amps..., but its not a big problem i think, especially as the arduino card is so cheap!

Oscar,

Ill post a link to the beta in the next couple of days.. just cleaning up some code and you can have a play and let me know what you think.

Cheers
Diego

737dragon
01-07-2012, 11:12 AM
Hey Reid,

At the moment it is limited to one card per PC. I would have to figure out a way to allow multiple modules to work correctly on 1 PC independently of which com port it is connected to. Or i may look at upgrading the code to also work with the Mega which allows for more outputs. This requires a little more work as the Arduino itself has to be programmed and as you have pointed out, im only using the Uno at the moment, so small steps.

The one thing i have noticed is that to power more than 1 servo, you will need to wire in an external power supply as the onboard regulator will start to get really hot and possibly burn out above 1 amp. This is where phidgets servo card shines, its onboard regulator will hand up to 12 amps..., but its not a big problem i think, especially as the arduino card is so cheap!

Oscar,

Ill post a link to the beta in the next couple of days.. just cleaning up some code and you can have a play and let me know what you think.

Cheers
Diego

I wait for the link of the thread, some manual of since your system works?, thank you very much

AK Mongo
01-07-2012, 12:32 PM
Diego,

Thanks for your replies. I have ordered an Uno from Ebay, and would be very interested in playing with your software! Cost me less than $20 US. It is definitely worth a look at that price.

I have noticed on some Arduino threads that the servo power is an issue, but does not seem too huge.

How big a problem would it be for your software to allow access to all 18 pins for servos? This would allow me to cover all of the non-complex gauges in my pit.

Thanks for your generosity in allowing us to have access to your work!

Reid

zerog69
01-07-2012, 05:13 PM
Hi Diego-

Great work - nice to see some Arduino action. Echoing other sentiments - thank you for your willingness to share.

I'm a little behind you - I've just gotten a basic wrapper working to connect to FSX and move a basic servo. I goto to reading through Mike's X25 stepper motor article and decided that this may be the way to go so the software's taken a bit of a back seat while I try and work out how to get that interface working. The theory is fine but I've yet to find a resource that defines the pin connections for those X25.168's!

You have caused me to pause though. I'd hoped to be able to attach multiple arduino's on multiple Com ports.

I eagerly await the link for your beta too - I may have missed it (in which case, I apologize) but what language are you developing in?

Thanks again in anticipation.

Sincerely,

Sean

diegov
01-08-2012, 04:18 AM
OK guys,

Below is the link to the beta. Unzip into a directory and run the exe. This is written in C# .net and requires the .NET 3.5 framework.

Before you use this program you should have some familiarity with the Arduino and i recommend you at least do one of the included tutorials to get familiar with how it works.

My setup is an Arduino UNO with a Sensor Shield v4, to simplify connection to analog pots and servos.

Couple of simple things when using A2FSX:
1. Make sure you install your arduino drivers and can see the board from the Arduino IDE.
2. When you start A2FSX you will need to upload my firmware to the board.. You can do this via the TOOLS menu.
3. Serial interfaces are a little funny and sloow. The card was not really designed to be constantly connected to the serial interface with a lot of information pumping back and forth. The interface was to provide a delivery method to upload code. So while i have tried to take as much care as possible to limit serial communication and provide a level of error checking, the program may hang, which will then require a restart.. In saying this, it has been very stable on my system.
4. Digital PIN allocation is currently hard coded. I could change this in future. But at the moment, PINS 2-7 are for INPUT, PINS 8-13 are for servo connections.

Configuration of sensors through the UI should be fairly self explanatory. Just set Mins and Max for Pots and Servos. then provide the FSUIPC offsets you wish to work with..

Any questions let me know.

Cheers

Diego

http://www.sendspace.com/file/yhk1dt

iwik
01-08-2012, 01:31 PM
Thanks Diego,
Well done and nice to see someone else downunder contributing to Fsim.
Thanks again
Regards
Les
P.S i just tried it on a Duemilanove, dont know if it should work on this. Get comport error message. Telling me that Comport Name is invalid. Change the name in .ini to COM=
and this message dissappears. Still will not find the Board. In the ide the board is found and i can upload my program.Comport number is correct, used the same one as ide reports. Im using Win7 64 bit .
Thaks
Les

diegov
01-08-2012, 05:46 PM
Hi Les,

I would assume that the Duemilanove should work as it is the same chip, but i am not 100% certain as I do not own one.

Did you upload the A2FSX firmware first? This must be done otherwise my program will not recognise the Arduino card and you will receive an error.

You can do this as follows. Open up DVA2FSX. You will receive an error about the AutoDetection failing. Use the TOOLS menu - > Upload firmware. Then type in the com port you Arduino is connected to, eg COM1, COM2 ETC....

Restart the program.

If my firmware is not on the Arduino, A2FSX will not recognise the card...

Cheers
Diego

iwik
01-08-2012, 06:31 PM
[Hi Diego,
Thanks for replying. Yes i did what u suggested and this is what i get when trying to upload firmware.
Also if i use your statement in .ini file ie COMPORT=x then the following comport error is reported.Changing this to COM=1
and this error goes. I see that The UNO and my board use different usb drivers, dont know if this accounts for the problem.
Here are the two pics.

6044
6043

diegov
01-08-2012, 07:12 PM
Hi Les,

the COMPORT must be specified as COMX.. So in your case COMPORT=COM2.. however this wont help as the problem seems to be the upload of the firmware to the arduino which is done by AVRDUDE.EXE.. which is external to my program. This will need to be fixed first..

Lets try the following..
1. Delete 2 from COMPORT=2 so it is just COMPORT=.
2. Try uploading a simple project to the Arduino from the IDE eg maybe Example->Basic->AnalogReadSerial.
3. once that works... close the arduino ide.. reset your arduino unplug and replug and try to upload the firmware again via my program... Make sure you specify COM2 and not 2 when you are asked which comport you would like to upload the firmware to.
4. if this fails again, please try uploading the firmware manually with avrdude.exe (located in the same folder as DVA2FSX). The command is as follows "AVRDUDE.EXE -p atmega328p -c arduino -P COM2 -U flash:w:dva2fsxv10.hex"
5. If this fails you may need to specify your baud rate. ie "AVRDUDE.EXE -b 9600 -p atmega328p -c arduino -P COM2 -U flash:w:dva2fsxv10.hex"

let me know how you go
Cheers
Diego

iwik
01-08-2012, 07:53 PM
Diego,
Using option 4 gave me no errors, option 3 nogo. Now when i run your program ,i see com2,Connected, Firmware no entry and the box
lower left says Arduino Firmware and then i get message Timeout Please restart program.
So we are getting there. Thanks for all the effort.
Les

diegov
01-08-2012, 08:06 PM
Hi Les,

Thats wierd as option 4 is exactly what my program does in the background.

This new issue may now possibly be a com port baud/speed issue. DVA2FSX really needs to run at 115200. Maybe the USB Controller on your Arduino is not realible at that speed.

Open up your Arduino IDE set the baud to 115200 and use the Serial Monitor to see if you get a response from the board. The response should be DVA2FSXv10, which is the firmware version...

The program may need to be adjusted to a larger timeout, but in reality that is not feasible as it is currently set to 5 seconds, and if we have to wait 5 seconds for each response, we are in trouble!!!

Try the above let me know how you go.. Hopefully someone using this with the UNO can post their experiences.

Cheers
Diego

iwik
01-08-2012, 08:52 PM
Diego,
Nothing comming thru on serial monitor. Sorry i put you slightly wrong. When i run the avr software i get the same message
as i did when trying to upload in dva2fsxb01.
Maybe we wait till someone with UNO tests. If you come up with any other ideas im quite keen to test.
Take Care and Thanks
Les
P.S
Did some research and it looks like the uno bootloader can operate at 115k, the older board
i have doesnt. So im going to redo the bootloader(optibootloader) and then my board will
look like a Uno. Heres hoping, will make my board quicker also. I think the error on loading your firmware is baud rate.

iwik
01-09-2012, 05:23 AM
Hi Diego,
I updated my Board to a Uno by loading a new bootloader( Optiboot). Flashed the chip by your suggested manual method 1 and the board reports the version nicely. I couldnt program it via tools in your program, it just came with the timeout error.
Will try it out in Fsim tomorrow.
Regards
Les

iwik
01-09-2012, 05:09 PM
Good morning Diego,
Having a wee play and need a bit more info. Analogue inputs, put a pot on one input and turned it ot min and pressed min
button followed by max pos and the set with button. Saved the went back to front i/f and noticed when turning the pot
the values arnt what i set in cal. They tend drift up in value and no way near what i caled for.
With the servo,you say digital output 8-13, does this relate to the pin numbering on the board. If so i thought that onl
3 5 6 9 10 and 11 could only be used for PWM output to servos. What is correct way to cal these. As when fitting a servo
it just joggles around.
Hopfully you can clear up some confusion on my side.
Thanks
Les
P.S Maybe i just cant use the program because of the speed you are sending data to the Serial
chip.By manually loading your firmware,i am doing it at 4600. When doing from your software
its much faster isnt it. Maybe the other things mentioned above are related.We will wait and see
if any other UNO users have any problems first.
Would there be any chance you could slow it down just so i could satisfy myself. It just my curiosity. Just tried the serial monitor in iDE at 115k and it reports the Firmware version fine.
Be interested in your comments

diegov
01-09-2012, 06:44 PM
Morning Les,

Good to see some progress on your side.

With Analog inputs, the min and max button will control the minimum limit and maximum limit of the pot during calculation into FSX.. The numbers on the main form are the RAW figures coming from the pot. So yes you can set mins and max during calibration and on the main form you will see those figures exceed min and max if you turn your pots over those limits, but the calculations into FS respect the min and max. You can open FSX to see this. Does this make sense?

For servos, pins 8-13 are for SERVOS.. despite what it says in the manual regarding PWM, there is a debate that servos use PPM instead, which can be done on any pin... So connect your servos on PIN 8-13 and then use the Servo button to calibrate. They should jump around only when you first hook it up, then you can use the slider to move the position of the servo to work out mins and max. Ensure you have enough power to supply to the servo or wierd things may happen.. Also ensure proper grounding of the circuit as i have noticed the board is very sensetive.

Try the above.. let me know how you go.. i dont think what you are seeing is related to the baud rate, now that you are using the new bootloader.

Cheers

Diego

iwik
01-10-2012, 12:29 AM
Hi Diego,
Thanks for the reply and clarification. Ive tried connecting a servo,red wire to 5v on Arduino and black to ground.Have used
an external supply to dc power input jack. Found i was able to move the servo two or three times then the program locks up an d i have to exit the program to start again.P/S was a12v 1amp which should have been sufficient for 1 servo.
Do you have any thoughts on this.
Thanks
Les

diegov
01-10-2012, 07:07 PM
Hi Les,

Can you try a low powered servo staight off USB without the power supply and let me know what happens. I had a couple of issues with external power supplies.

Thanks
Diego

iwik
01-10-2012, 07:30 PM
Hi Diego,
Thanks but unfortunately i only have servos like hs511. What i was going to try was to power the servos from a seperate
supply and tie gnd back to Arduino. Thats how Opencockpits power their servos if need be
Regards
Les
P.S I did try to run from no external p/s and one servo, bit like i do with O/C card still the same result.

diegov
01-10-2012, 07:58 PM
Hi Les,

Not sure what the issue could be. I have no problems with the Arduino Uno, running 2 servos off the USB port and running calibration, moving servos back and forth numerous times and have no crashes, very stable. The only reason the program would crash would be a serial communication issue with the arduino. Also tried with a 9v powersupply, all seems good. Im running this off a laptop, so maybe with your power supply there is a grounding issue?

While this seems all good for low powered gauges, Im at a stage where i need to look at he best way to bypass the onboard voltage regulator as i have some big servos that i need to move.. I'll let you know if i figure out the best way to do this. The trick is that if you have your arduino connected via usb and an external regulated powersupply which bypasses the onboard regulator, all of it needs to be grounded together as you have pointed out, and if you are using an external powersupply and bypass the regulator, the arduino will also be drawing power from the usb line due to the Uno autoselect power, which may or may not cause an issue. Im not sure, im not the best with electronics.. There is a couple of things i will try and then post my results.

Cheers
Diego

iwik
01-11-2012, 12:09 AM
Hi Diego,
Thanks for your comments, i will try a few more things as i noticed that not connectinga servo i can play about with both
options ie cal anlogue and cal servos with no hangup.It could be something with the servo i tried, going to try another
better quality one.
Re your question about bypassing the regulator. To cut off USB 5v feed all you have to do is feed Vin with a voltage.
The circuit has a FET witch switches off the 5v from usb when Ext p/s fitted.This fet is fed from a op amp which is toggled by
applying Vin.
Will keep in touch and let you know how it pans out.
Regards
Les
P.S Update:All is fine, had a chance to try another Servo hs511. Had my suspicions about
the one i tried. Thanks for all the help and when i find some more time will try it out
in Fim

diegov
01-15-2012, 12:38 AM
Hi Les,

Have another beta to release soon... I spotted a few bugs with the older version.. Will send through on your PM so you can test.

Thanks
Diego

iwik
01-15-2012, 03:09 AM
Thanks,
Yes now i'm having trouble with the Analogue input. Servo is reliable, analogue cal gives me a error saying its the analogue
input giving an exception handling error. If i delete data for an analogue input so i can disable it. It reports an error that
a value in the .ini file is incorrect.
Will keep an eye out for the update.
Les
P.s The analogue error comes about if you have had a pot connected to analogue input. Then if this is removed and the the program is started all is ok till you hit Analogue Cal but. Then the
error appears. Appears it doesnt like a calibrated input with nothing connected.

diegov
01-15-2012, 06:30 PM
Hi Les,

That issue is more a corruption of the ini file, which may happen if you edit the ini file manually possibly while running a2fsx and don't provide a new line for each value.

1. Shutdown the program and open the ini file in notepad. Check that each value is on a seperate new line. EG
OFFSET=
MAXVALUE=
MINVALUE=
and not
OFFSET=MAXVALUE=MINVALUE
2. Once corrected you should be able to open the calibration window with no problems.
3. To disable an analog input from simply set the OFFSET to 0 in the calibration window and Save.

Cheers
Diego

iwik
01-16-2012, 02:05 PM
Hi Diego,
Thanks for that, i tried to make the fields blank spaces and obviously this causes a corruption to the ini file as you suggested.
If one needs to use the servos to drive gauges, how do you provide corrections as some gauges dont have a linear scale.
I dont really follow what or where this can be done in your i/f or is that not possible. If so a small example would help.
Thanks gain
Les

Roland
01-21-2012, 04:22 AM
Hi Diego,

This looks like a very neat & simple way to control servos from FS.
You mention you use FSUIPC offsets as interface between your program and FSX
Can this setup also be used for FS9?

Thanks!

diegov
01-22-2012, 06:45 AM
Hi Roland,

It should work with FS9 as i am using FSUIPC to read/write information from/to the flight simulator.

Les,

Only linear at the moment. Will look at non linear after the base code is stable. New release out in a few days.

Cheers
Diego

iwik
01-23-2012, 04:52 AM
Hi Diego,
Ive been trying to get some action out of a servo when in fsim. If i want to show flap position, what do i have to enter and where. Just a little help to get me going.
Thanks
Les

diegov
01-25-2012, 10:21 PM
Hi Les,

Firstly here is the new beta:

http://www.sendspace.com/file/gt33ih

Please update as there are a number of bugs i have squashed. You will also need to upgrade the Arduino firmware as part of this update as per the instruction we went through originally.

Once you have completed the upgrade, flap calibration should be straight foward taking into account there is only linear support at the moment.

Copy the settings as per the snapshot below, and that should get your flaps going:

6126

Cheers
Diego

iwik
01-26-2012, 12:51 AM
Hi Diego,
Thanks for the update. Great improvement, even though i had my settings as you stated in your post i could not get the flaps to work.
Now i can use your Tools menu to Update Firmware and the the servos now work from Fsim.
Any further testing you want done just let me know.
Thanks Again
Les