Jump to content

Need help to build Airspeed Gauge using arduino


Recommended Posts

hey guys.

 

im trying to make a physical airspeed gauge, but i have no idea where to begin..

i just ordered an arduino uno board.

 

im hoping to do a test with the arduino and a LED in which i would plug the board to a PC running DCS, and program it to have the LED light up fully at a certain speed, and dim when the speed is 0..

 

HELP!!!

 

so far resources i have encountered are

https://www.arduino.cc/en/Guide/HomePage

 

http://dcs-bios.a10c.de/docs/v0.2.0/userguide.html

 

https://github.com/dcs-bios/dcs-bios/blob/master/Scripts/DCS-BIOS/lib/A10C.lua

 

https://learn.adafruit.com/16-channel-pwm-servo-driver/hooking-it-up

 

http://forums.eagle.ru/showthread.php?t=131052

 


Edited by hannibal

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

What you need to do is to start reading. Begin with the users guide at

http://dcs-bios.a10c.de/docs/v0.2.0/userguide.html and follow the steps precisely as documented. This guide was written for the layperson\novice so it won't be difficult to understand.

 

Next, go through this thread

http://forums.eagle.ru/showthread.php?t=141096 where you will find lots of good info. At that point you will be building stuff. Not an air speed indicator but you have to walk before you run.

 

Have fun and we will see you in a couple of weeks.:thumbup:

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to comment
Share on other sites

First thing you're going to need to think of is how is your PC going to talk to your arduino. USB or ethernet? If ethernet, you'll need a expansion board.

 

Which DCS module are you going to use? Only a few of them are supported at the moment. If using the A10, get the master caution light example working to prove your DCS->Arduino comms work.

 

Then you can start on the airspeed portion of it. You'll need to decide on using a servo or stepper motor.

Link to comment
Share on other sites

Warthog.. many many thanks for the info, and references!!!

 

Toxaq.. ideal i would like to use any aircraft. i dont plan to work on anything else but the airspeed / IAS gauge.

 

would you recommend USB or ethernet? i would take the route in results on less of an impact on the computer running DCS!


Edited by hannibal

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

Hannibal you need to look here:

http://dcs-bios.a10c.de/docs/v0.3.0/control-reference.html

 

Select 'common data' from the drop down and you'll see

 

DcsBios::ServoOutput altMslFt(0x0408, PIN, 544, 2400);

 

That will send the altitude in feet to a service configured on pin at var PIN (ie change PIN to the actual pin you've connected the PWM output of your arduino too).

 

Of course if you want to get really funky, you can get the raw value by putting the following in the dcsbioswrite method:

if (address == 0x0408) {
   unsigned int altMslFtValue = (value & 0xffff) >> 0;
   /* your code here */
}

 

Where the commented line "your code here" is is where you can write your own code to interface to any arduino functionality at all. The value you seek will be available as altMslFtValue. So if you want to send it to an led, stepper or laser pointer you just need that code from any arduino source. It might not be obvious but you're in the update loop here so you don't want to do anything too taxing...

 

In terms of USB vs ethernet, well it's really up to you. I'm just playing with the USB functionality at the moment so there's some added complexity in setting up socat to forward the IP stuff to serial. However if you have to pay for and setup an ethernet extension board on your arduino, that's probably as much work. So basically 6 of one, half a dozen of the other.

Link to comment
Share on other sites

That will send the altitude in feet to a service configured on pin at var PIN (ie change PIN to the actual pin you've connected the PWM output of your arduino too).

 

And if you want to have the airspeed available in the CommonData module too, you'd need to modify this Lua file. It's only a small modification, anyone who has a little experience with the Export.lua environment could do it. Unfortunately I don't have time at the moment to fire up a dev environment, make the change, test it, and release a new version (busy with exams).

Link to comment
Share on other sites

I would just keep it simple for the moment. If you use a USB connection you won't have to worry about anything else other than the code to run the speed indicator.

 

At the moment DCS-BIOS only provides data for specific planes. So start with the A-10 module and get it running as toxaq has suggested. I know Ian has been planning to find a way to extract a common airspeed, direction, altitude etc regardless of the module. but that won't happen anytime soon.

 

Your first priority should be to get a good understanding of DCS-BIOS. As well you will want to get a good handle on writing code for the Arduino. The DCS-BIOS users guide has a number of simple examples you can use. Examples are all based on using the Arduino Uno but you can use pretty much any other Arduino board. I use, almost exclusively, the Pro Mini, a rather inexpensive board ($2.50) if ordered from China. That way I don't get all pissed off if I accidentally fry one cause I got 10 more in my parts bin.:music_whistling:

 

Once you have gone through all that info and you are in the building phase, post any additional questions to the "Cockpit Building" section.

 

Good luck and happy building.

John

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to comment
Share on other sites

Ian;2468527']And if you want to have the airspeed available in the CommonData module too' date=' you'd need to modify this Lua file. It's only a small modification, anyone who has a little experience with the Export.lua environment could do it. Unfortunately I don't have time at the moment to fire up a dev environment, make the change, test it, and release a new version (busy with exams).

 

OK, im stuck again..

 

So, so far i am seeing great example of making a altimeter from the resources you guys have linked me too...

im attempting to look at the "airspeed" in the lua files.

from the default script C:\Program Files\Eagle Dynamics\DCS World\Scripts\export.lua

i see variables "LoGetIndicatedAirSpeed()"

http://dcs-bios.a10c.de/docs/v0.3.0/control-reference.html, commondata doesnt include airspeed yet.

 

at this point i dont know what variables to use to modify... :/

 

i am wondering where all the variables for DCS-BIOS comes from, and im curious how exports actually happens, from the youtube video, the tutorial just runs that command line.

I see all the fucntions the DCSBIOS.ccp file but how it grabs .lua exports, i cant see clearly...


Edited by hannibal

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

Heh, oops. Brain fade I was reading airspeed but seeing altitude.... So you'd need to modify commondata as per [FSF]ian's comments. You can find some more of what's exported by LoGetSelfData on this site https://simmeters.com/wiki/index.php?title=DCS_World_Wrapper

 

A cursory scan reveals

 

table.insert(flightData,"XXX="..LoGetTrueAirSpeed() * 1.94) 									-- TRUE AIRSPEED (M/S TO KNOTS)
table.insert(flightData,"ASI00="..LoGetIndicatedAirSpeed() * 1.94) 								-- INDICATED AIRSPEED (M/S TO KNOTS)

 

So I'd guess something like

 


local as_t = selfData.LoGetTrueAirSpeed()
local as_i = selfData.LoGetIndicatedAirSpeed()

 

and then

 

defineIntegerFromGetter("ASPD_TRUE", function() return math.floor(as_t) end, 65535, "Airspeed", "Airspeed true (m/s)")

defineIntegerFromGetter("ASPD_IND", function() return math.floor(as_t) end, 65535, "Airspeed", "Airspeed ind (m/s)")

 

Obviously I've not tested this and to get knots you'd need to do the conversion as per the linked site (1.94) looks like the ratio.

 

Hopefully that's enough to get you started. I'd make sure you have an example of something else working before you play with commondata. You need prove your existing system is working before adding to it or you'll be chasing gremlins more than being productive.

Link to comment
Share on other sites

Hopefully that's enough to get you started. I'd make sure you have an example of something else working before you play with commondata. You need prove your existing system is working before adding to it or you'll be chasing gremlins more than being productive.

 

that is definitely a good idea and a must.

let say i try to implement an altimeter,

i see a youtube video of an example of an implementation using a small display panel..

 

or can i make some of kind program that just sends verbose text in some some kind of command prompt?

 

what im asking is, there an easier way to implement the altimeter, but with out actually making a gauge or screen... even something like a indication by LED~such as the higher altitude you are the brighter the LED, and at ground level, LED is dim...

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

I used the landing gear light on the p51 when I was doing it. That's the whole point of the A10C master switch example. Simplest proof that your connection from DCS -> Arduino is working. What planes do you have? If A10C then make the master switch work.

 

If you're using socat to forward over USB then serial writes will appear in the socat output. You can't attach arduino's serial monitor to the USB as socat is already connected.

 

Break it down:

1) Get DCS-> arduino working. Flashing a light in reaction to the sim is your goal

2) Get your output working how you want. Completely unrelated to DCS, get it so you can send a value to your screen or whatever you're wanting to make work.

3) Extend commondata.lua to send your info to your arduino with a way of verifying you're getting it.

4) Merge the results with a away of rolling back to any of your previous states (github or smart file saving strategy a prerequisite here)

 

I had a bit of frustration in getting my P51 stuff sorted because even though I did each step, I'd forget to restart socat, or not save the file in the editor, or change a pin, or bump a switch. Get a beer, take your time, have a strategy. Worst case, you drink a beer.

Link to comment
Share on other sites

socat is outlined in the dcs-bios github page. Basically you run the .cmd file https://github.com/dcs-bios/dcs-bios/blob/master/connect-serial-port.cmd The only thing you need to do is change the cmd file to point to the right usb port.

 

socat is very clever software that converts incoming traffic to outgoing traffic of whatever you like (laymens interpretation, I'd not heard of it before this). In this case, we're using it to take DCS's feed which is broadcast to a local IP address and pass it on to serial over USB. Socat is the IP end point and the serial broadcaster. It's also bi-directional. Quite stunning really. Shoulders of giants and all that.

Link to comment
Share on other sites

Socat will simply open two data streams and shovel data back and forth in both directions. Think of socat as a hose that connects two pipes.

A pipe can be just about anything you can read and write bytes to/from, including a file, a serial port, UDP and TCP network connections or the terminal (great for debugging).

 

When using DCS-BIOS with an Arduino that is connected over USB, the role of socat is to connect the DCS-BIOS UDP data stream to the serial port.

Link to comment
Share on other sites

Here's a data flow diagram:

20103192-e145-4cce-a1a5-61b9813c37fc.png

 

It shows DCS, the Arduino, and what happens between them, but it's not really a flowchart.

 

Does it help if I tell you that there's "DCS-BIOS", which strictly speaking only refers to the Lua code inside DCS, and then there is the "DCS-BIOS Arduino Library", which is the part that runs on your Arduino board and handles talking to the other part?

 

Feel free to ask more specific questions. I have the feeling that there is a lot of confusion around about how this works and which parts do what, but I find it difficult to write good documentation because I never was in the situation of learning everything at once.

 

Maybe I should do a video where I press an NMSP button and the button's LED lights up on the Arduino, and comment about what things happen behind the scenes to make that work or something.

Link to comment
Share on other sites

Ian;2472085']Here's a data flow diagram:

20103192-e145-4cce-a1a5-61b9813c37fc.png

 

It shows DCS, the Arduino, and what happens between them, but it's not really a flowchart.

 

Feel free to ask more specific questions. I have the feeling that there is a lot of confusion around about how this works and which parts do what, but I find it difficult to write good documentation because I never was in the situation of learning everything at once.

 

this is a cool overview!

 

im just trying to understand the variables being used in the data "stream" you described.

 

im also wondering where certain variables come from. earlier i found variables in the "export.lua" file

in

so for the commondata variables used i think i saw some of the same variables in the export.lua.

in the case of buttons and switches, i see all the commands in the inputs folder for the keyboard.lua and in controller config lua files as if someone were using a joystick.

from the video tutorials on youtube, i see the user run DCS-BIOS without even dropping in a custom export.lua file???

 

im just looking at some kind of flow like variable X from DCS export over UDP gets sent to program X, which takes variable X and processes it (like multiplying it by 1.038 and put into a memory table) as result X and then sends it over to arduino via virtual serial over USB, which then takes that result to have it do something.

 

i think back then, i think the LockOn Virtual Panel required you place a custom export.lua file... maybe helios does the same

 

you made a great interface for us DCS users.

im just trying to understand where things come from, and if understood, i or others can expand on what you did to other functions and aircraft.

 

maybe an example (a youtube video even?) of how you coded a switch function such as the NMSP button, as in how you got the variables where in the DCS-BIOS files takes what and which leads into the current tutorials you have on the DCS-BIOS example webpage...

 

thanks for advice so far :)

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

from the video tutorials on youtube, i see the user run DCS-BIOS without even dropping in a custom export.lua file???

 

im just looking at some kind of flow like variable X from DCS export over UDP gets sent to program X, which takes variable X and processes it (like multiplying it by 1.038 and put into a memory table) as result X and then sends it over to arduino via virtual serial over USB, which then takes that result to have it do something.

 

The magic words in the video are "I have already downloaded and installed DCS-BIOS and the Arduino library from the website and set everything up according to the instructions in the User Guide." Those instructions include modifying your Export.lua file so DCS-BIOS gets called.

 

DCS-BIOS (the Lua part) has a concept of an "address space". Think of it as a 64 KiB block of memory that you can write data to. Once you are in a mission, DCS-BIOS checks what the current aircraft is and determines which export modules should run for that aircraft. Usually, that will be MetadataStart, CommonData, an aircraft-specific one (e.g. A10C.lua), and MetadataEnd. Each of those export modules (found under "Scripts/DCS-BIOS/lib") will register a bunch of hook functions on startup which are called 30 times a second. Each hook function gets a value from the sim (usually with GetDevice(0):get_argument_value), translates it to an integer number or a string (the only two datatypes DCS-BIOS knows about), and writes them to a specific location in that 64K memory block. Any scaling of the value (often from a range of 0...1 to 0...65535) happens at this point. DCS-BIOS does not export floating point values because they are inconvenient to handle on a microcontroller.

 

After all the hook functions have run, DCS-BIOS determines which sections of that 64K memory block have changed and sends it out to the export data stream, which usually means local multicast UDP and to any connected TCP clients. You can define additional targets (e.g. IP address and UDP port) that should get a copy of the export data in BIOSConfig.lua.

 

Each export module has an instance of a MemoryMap object (implemented in Util.lua) that manages this module's chunk of address space. It hands out MemoryAllocation objects which represent a specific sub-range of that memory. This way, we make the export data stream as memory-efficient as possible (if we only need two bits for a three-position switch state, we will only use that much). That allows us to send everything to each panel, so we don't have to tell the software to only send specific data to a panel (one of the design goals was that all configuration for a panel should be kept in that panel's microcontroller firmware).

 

To handle input, DCS-BIOS listens for lines of plaintext on an UDP port and on all TCP connections. Each export module can register functions that will be called for a certain input command. For example, the A-10C module registers a function to handle the "AHCP_CICU" command, which will then set the CICU power switch to the desired value.

 

The data format of the input and export data streams, the "low-level" API for how to define an export module and get a MemoryAllocation object, and how to register input hooks is described in the developer guide.

Usually, export modules won't call the low-level API directly. Instead, they will call one of the convenience functions from Util.lua (e.g. defineToggleSwitch) which will get a MemoryAllocation, register the input and export hook functions, and make an entry in the documentation table which will be saved to a JSON file so the control shows up in the reference documentation.

 

 

On the Arduino side, the Arduino library provides a ProtocolParser class that will take the data coming from DCS-BIOS and call a function for each 16-bit word that has changed. If you define a DcsBios::LED instance, that object will register a hook function to be called when new data comes in. That function will check if the address matches the one of this LED. If it does, it extracts the relevant bit using the mask value and calls digitalWrite() to update the pin state.

 

A DcsBios::Switch2Pos object will register a function to be called once every loop() from DcsBios::PollingInput::pollInputs(). That function checks if the physical switch state has changed. If it detects a change, it calls sendDcsBiosMessage() to send a command to DCS-BIOS.


Edited by [FSF]Ian
Link to comment
Share on other sites

really apprieciate your time to write back and educate me and everyone about dcs-bios.

i have to follow the website all the way thru.. that socat stuff is deep.

i need to stop beating around the bush and start doing the examples!

 

again, very humbled by your reply!

hope to have something going soon, and should i get the examples actually working, hope that will enlighten me to work out the IAS/airspeed function!

find me on steam! username: Hannibal_A101A

http://steamcommunity.com/profiles/76561197969447179

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...