Jump to content

DCS-BIOS - Converting Automotive Gauges


Inverted

Recommended Posts

A DCS BIOS noob here.

Has anyone used automotive gauges with DCS BIOS?

 

As they are very cheap from China and would seem to make building a sim pit quicker and cheaper.

 

So has anyone done this before, if so, how did you do it?


Edited by Inverted
Link to comment
Share on other sites

What we are missing is one general thread about DCS-Bios and Instruments. Some of guys here have already build instruments using DCS-BIOS and stepper motors or servos, but it is hard to collect information’s because there are usually in different builds-threads. Can someone write short guide ,,How to“ where will be described used hardware, code examples and so on...

It will be for sure help to DCS community...

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to comment
Share on other sites

I'm using many automotive stepper motors for my A-10C cockpit build. I've had very good luck with the VID29 / X.25.168 motors. These are/were commonly used in GM vehicles. They are available on ebay and also Amazon. Here's a link -

 

https://www.amazon.com/dp/B00LQ9AQOY/_encoding=UTF8?coliid=I3GJY1C1ABFDFS&colid=25UHEBSM29ZLZ

 

As for code - (not my own) I've had great luck using the below reference. Just use the DCS-BIOS documentation to find the correct hex value for the instrument you want to slave to the stepper motor. I agree more docs are needed and I believe this is in work. Folks on this forum have been a big resource for me.

 

#define DCSBIOS_IRQ_SERIAL

#include <AccelStepper.h>
#include "DcsBios.h"

struct StepperConfig {
 unsigned int maxSteps;
 unsigned int acceleration;
 unsigned int maxSpeed;
};


class Vid29Stepper : public DcsBios::Int16Buffer {
 private:
   AccelStepper& stepper;
   StepperConfig& stepperConfig;
   unsigned int (*map_function)(unsigned int);
   unsigned char initState;
 public:
   Vid29Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned int (*map_function)(unsigned int))
   : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), map_function(map_function), initState(0) {
   }

   virtual void loop() {
     if (initState == 0) { // not initialized yet
       stepper.setMaxSpeed(stepperConfig.maxSpeed);
       stepper.setAcceleration(stepperConfig.acceleration);
       stepper.moveTo(-((long)stepperConfig.maxSteps));
       initState = 1;
     }
     if (initState == 1) { // zeroing
       stepper.run();
       if (stepper.currentPosition() <= -((long)stepperConfig.maxSteps)) {
         stepper.setCurrentPosition(0);
         initState = 2;
         stepper.moveTo(stepperConfig.maxSteps/2);
       }
     }
     if (initState == 2) { // running normally
       if (hasUpdatedData()) {
         unsigned int newPosition = map_function(getData());
         newPosition = constrain(newPosition, 0, stepperConfig.maxSteps);
         stepper.moveTo(newPosition);
       }
       stepper.run();
     }
   }
};

/* modify below this line */

/* define stepper parameters
  multiple Vid29Stepper instances can share the same StepperConfig object */
struct StepperConfig stepperConfig = {
 475,  // maxSteps
 100, // maxSpeed
 100 // acceleration
 };


// define AccelStepper instance
AccelStepper stepper;
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper apu(0x10be, stepper, stepperConfig, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 0, 65535, 0, stepperConfig.maxSteps);
}); 


void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

Link to comment
Share on other sites

Can you please also post your hardware - ardunio type, are motors connected directly or via driver board, how many of motors are connected to one ardunio and so on....

 

Sure.

 

I'm using Arduino 'Mini' boards. These are very cheap to obtain from China on eBay (like $3 a piece). You will need to solder the leads on the boards, but this is pretty easy to do if you have some soldering experience. Out of the ~50 Arduino mini boards I've purchased, I've only had ONE bad board. Pretty good.

 

Link to eBay seller I've had good luck with

http://www.ebay.com/itm/5Pcs-MINI-USB-CH340G-Nano-V3-0-16M-5V-ATmega328P-Micro-Controller-Board-Arduino-/361919929243?hash=item54441bdb9b

 

I'm also using an Adafruit H-Bridge to drive the motors.

 

Link to the H-bridge

https://www.adafruit.com/product/2448

 

Here are a few photos of my hardware - hopefully you can see the wiring OK. This will work with the code I posted above.

 

20170708_212432.jpg

20170708_212503.jpg

20170708_212532.jpg

20170708_212922.jpg

 

I hope this is helpful to you and others.

Link to comment
Share on other sites

Very nice writeup WhoMadeWho :thumbup:

 

@Inverted & @Draken152 you may also use an EasyDriver Shield instead; http://www.ebay.com/itm/A3967-EasyDriver-Shield-Stepper-Motor-Driver-Module-V44-For-Arduino-3D-Printer-/400522271040?epid=581015416&hash=item5d40fcd940:g:fc0AAOSwq1JZLplm

 

In that case you need to use this code by Warhog/Ian

#define DCSBIOS_IRQ_SERIAL

#include <AccelStepper.h>
#include "DcsBios.h"

struct StepperConfig {
 unsigned int maxSteps;
 unsigned int acceleration;
 unsigned int maxSpeed;
};


class Vid29Stepper : public DcsBios::Int16Buffer {
 private:
   AccelStepper& stepper;
   StepperConfig& stepperConfig;
   unsigned int (*map_function)(unsigned int);
   unsigned char initState;
 public:
   Vid29Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned int (*map_function)(unsigned int))
   : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), map_function(map_function), initState(0) {
   }

   virtual void loop() {
     if (initState == 0) { // not initialized yet
       stepper.setMaxSpeed(stepperConfig.maxSpeed);
       stepper.setAcceleration(stepperConfig.acceleration);
       stepper.moveTo(-((long)stepperConfig.maxSteps));
       initState = 1;
     }
     if (initState == 1) { // zeroing
       stepper.run();
       if (stepper.currentPosition() <= -((long)stepperConfig.maxSteps)) {
         stepper.setCurrentPosition(0);
         initState = 2;
         stepper.moveTo(stepperConfig.maxSteps/2);
       }
     }
     if (initState == 2) { // running normally
       if (hasUpdatedData()) {
         unsigned int newPosition = map_function(getData());
         newPosition = constrain(newPosition, 0, stepperConfig.maxSteps);
         stepper.moveTo(newPosition);
       }
       stepper.run();
     }
   }
};

/* modify below this line */

/* define stepper parameters
  multiple Vid29Stepper instances can share the same StepperConfig object */
struct StepperConfig stepperConfig = {
 120,  // maxSteps
 1200, // maxSpeed
 10000 // acceleration
 };


// define AccelStepper instance
[b]AccelStepper stepper(AccelStepper::DRIVER, 11, 10);[/b]
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper vvi(0x10a0, stepper, stepperConfig, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 0, 65535, 0, stepperConfig.maxSteps);
}); 


void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

It is almost identical to WhoMadeWho's code except for the highlighted part where you define which two pins are used for the the Step and Direction.

 

Advantage with this is that it only uses 2 pins from the Arduino. Just make sure you have the correct 'AccelStepper.h' version as otherwise you get a compiling error. WhoMadeWho was kind enought to lead me to the correct one; http://www.airspayce.com/mikem/arduino/AccelStepper/index.html

 

Cheers

Hans

Link to comment
Share on other sites

  • 4 months later...
  • 2 months later...

You'll want separate instances of hardware for running that many steppers.! I'm running 1 Arduino + h-bridge for each stepper. So for my engine panel, that's twelve (12) Arduinos and (12) h-bridges. Is there a better way? Probably with a more powerful Arduino + an externally powered motor driver.

 

I've found separate instances work best for me.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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