Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 4
  • *Guests: 84
  • *Total: 88

Our Discord

Author Topic: Ray's Fuel and Flap Code using ARDREF plugin...  (Read 2101 times)

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 817
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Ray's Fuel and Flap Code using ARDREF plugin...
« on: April 06, 2015, 01:13:43 AM »
Code!

You'll need a few plug-ins, like ARDREF for X-Plane (If you are using X-Plane... if you're using FSX or some other derivative, this might not be of much use.

So without delay, here's my Arduino code to get L/R fuel tank levels and flap position for setting my 3-section d'Arsenval Beechcraft flap gauge...

#include <SoftwareSerial.h>
#include <SPI.h>         
#include <Ethernet.h>
#include <Wire.h>
#include <XP_ARDref.h>         // -- include XPlane ARDref library
#include <Servo.h>

//#define txPin 2
#define fuel_L 4
#define fuel_R 5

#define txPWM 3
#define txPWM_1 5
#define txPWM_2 6
#define txPWM_3 7

//====================================================
byte Ard_MAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // MAC-Address of this  ethernet shield
int ARP = 5080;               // ARDref port
int IP[] = {10,0,0,49};   // This board IP address (0,0,0,0 -  if auto) .
                                        // If you have router with DHCP - you may set auto (0, 0, 0, 0)

//====================================================
ARDref XP (ARP, IP, Ard_MAC);   //  Create  XPlaneData object (XP)
//====================================================

// Vars to hold X-Plane data
  int Flaps;      // Flaps, current
  float Fuel_1;      // Flaps, current
  float Fuel_2;      // Flaps, current

// Vars for Flap Gauge
  int _Loop = 0;
  int Loop_1 = 0;
  int Loop_2 = 0;
  int Loop_3 = 0;


void setup()  {
 
  XP.begin(1);  // init, use Number of this Arduino ( always 1 )
         // if you use more than one Arduino with Ethernet shield, use 2, 3...)
//-------------------------------------   
  //XP.Pins_In (2, 12); 
  //XP.Pins_In (14, 29);     // Assign pins for inputs (first#, last# including)
  //XP.Pins_In (33, 49); 
  //XP.Pins_Out (13, 13);
  //XP.Pins_Out (30, 32);     // Assign pins for Outputs (first#, last# including)

}

//=================================================
void loop() { 
 
  XP.GetData();   //this function must be in each loop , for X-Plane data reading

  // Read X-Plane data from ARDREF
  Fuel_1 = XP.DataOut[1]; // Get value of parameter (#1 from your "out_1.cfg" list)
  Fuel_2 = XP.DataOut[2]; // Get value of parameter (#2 from your "out_1.cfg" list)
  Flaps =  XP.DataOut[3] * 100.0; // Get value of parameter (#3 from your "out_1.cfg" list)

  //_seconds = XP.DataOut[4] *100.0;

  Serial.println(Fuel_1); //Just so we can see what's going on

  analogWrite(3, (Fuel_1 / 3) + 5); // Simple stuff once you scale the output
  analogWrite(4, (Fuel_2 / 3) + 9); // for the desired d'arsenvol movements
 
   _Loop = (Flaps * 2.20) + 14 ;

  //--------------------------------
  // Flap Range: 0 - 35
  //--------------------------------
  if (_Loop >=0 && _Loop <= 85)
  {
    Loop_1 = (_Loop * 3)  ;
    analogWrite( txPWM_1, 0);     // Hold PWM_1 LOW
    digitalWrite(txPWM_2, HIGH);  // Hold PWM_2 HI
    analogWrite(txPWM_3, Loop_1); // PWM
   }
   
   
  //--------------------------------
  // Flap Range: 35-70
  //--------------------------------
  if (_Loop >=86 && _Loop <= 170)
  {
    Loop_2 = ((_Loop * 3) * -1);
    analogWrite( txPWM_1, 0);      // LOW
    analogWrite(txPWM_2, Loop_2);  // PWM
    digitalWrite(txPWM_3, HIGH);   // HIGH
   }

 
  //--------------------------------
  //  Flap Range: 170 - FULL DOWN
  //--------------------------------
  if (_Loop >=171 && _Loop <= 239)
  {
    Loop_3= (_Loop * 3)+2; 
    analogWrite( txPWM_1, Loop_3);  // PWM
    analogWrite(txPWM_2,  0);       // LOW
    digitalWrite(txPWM_3, HIGH);    // HIGH
   }

// Reset Each Individual Loop as they track through full range
if(Loop_1 >=254) {Loop_1 = 14; }
if(Loop_2 >=254) {Loop_2 = 0; }
if(Loop_3 >=240) {Loop_3 = 243; }

 }   //-- End-----------------






Ray Sotkiewicz

Offline Trevor Hale

  • Administrator
  • I am chained to this website!
  • *
  • Posts: 3,838
    • Cockpitbuilders.com
  • First Name: Trevor
  • Home Location: New Liskeard, Ontario
Re: Ray's Fuel and Flap Code using ARDREF plugin...
« Reply #1 on: April 06, 2015, 06:49:36 AM »
Great Code Ray,  thanks for sharing.

Trev
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

Offline VladSim

  • CockpitBuilder
  • *
  • Posts: 5
  • Aviation Enthusiast
    • Arduino for home cockpit
  • First Name: Vlad
  • Home Location: Russia
Re: Ray's Fuel and Flap Code using ARDREF plugin...
« Reply #2 on: July 17, 2015, 11:27:29 AM »
Hi Ray,
With new ArdSim library and plugin the code for analog Flaps and fuel gauges looks very simple.
This example is included in ArdSim package.
It is for linear scaled gauges, but can be easy transformed for non-linear scales:

/*
Analog gauge outputs
Download ArdSim Library on the site.
http://arduino.svglobe.com
 */
#include <SPI.h>         
#include <Ethernet.h>
#include <ARDsim.h>         // -- include ARDsim library
#include <Servo.h>
//====================================================
byte MAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};// MAC-Address of Arduino
unsigned int XP = 5080;           // port to receive Data from Xplane
byte IP[] = {192, 168, 1, 9};     //IP of this Arduino
//====================================================

#define Flaps     5, 0, 1            // Flaps gauge on pin #5
#define Fuel1     6, 10, 300     // -- fuel 1 (10-300 kgs)  - pin #6
#define Fuel2     7, 10, 300    // -- fuel 2 (10-300 kgs)   - pin #7

void setup()  {
 
  SimStart (XP, MAC, IP);    //-- ArdSim initialization

}
//----------------------------------------------------------
void loop() {
 
   SimScan(); //  this function must be in each loop
   
Gauge(6, Flaps);     // flaps controlled with dataref #6
Gauge(9, Fuel1);     // dataref #9 (in the in_1.cfg file)
Gauge(10, Fuel2);    // dataref #10

 }   //-- End------------------------------------------------


Best regards
Arduino interface http://arduino.svglobe.com - easy way to control your home cockpit

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 817
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Ray's Fuel and Flap Code using ARDREF plugin...
« Reply #3 on: July 17, 2015, 05:03:24 PM »
Thanks for keeping us up to date with your great library!

I've been working this past week to get your new ARDSim code installed and it works beautifully. My Flap gauge is a 3-core mechanism so I'll see what I can do with that this weekend.

Thanks for all your support!
Ray Sotkiewicz

 

FlightSimExpo 2019

FsExpo

Recent Posts

Flooring Installed!
by helloo
[Today at 04:00:36 PM]
How much room between center pedestal and seat?
by jackpilot
[Today at 08:19:42 AM]
PM MCP.ini Question...
by ScottThePilot
[Today at 03:14:37 AM]
2020 Microsoft Flight Simulator - new at E3 2019
by blueskydriver
[June 24, 2019, 02:29:16 PM]
How to install DZUS fasteners?
by Buster99
[June 22, 2019, 04:12:34 PM]
Desert Air Spares - Trustworthy?
by kattz
[June 22, 2019, 12:40:51 PM]
Wanted - 737 Audio Panels - OEM
by jackpilot
[June 20, 2019, 12:26:51 PM]
Throttletek 737 Throttle For Sale
by kevinsayre
[June 19, 2019, 03:57:33 PM]
For sale - rudder pedals and linkages - pending to Craig
by Caflyt
[June 19, 2019, 07:49:14 AM]
737-800 Arduino X-Plane Build
by kurt-olsson
[June 18, 2019, 11:26:12 AM]
737 Throttle Conversion OC + ProSim
by kattz
[June 16, 2019, 11:39:03 AM]
A friendly FYI on Boeing rudder pedals
by kattz
[June 15, 2019, 10:36:39 AM]
737 starter switch mechanism
by paulnd
[June 13, 2019, 02:58:39 PM]
Make up your mind, Microsoft!
by jmlohrenz
[June 12, 2019, 07:25:10 PM]
What have you done for your simulator today?
by C150DIY
[June 12, 2019, 12:53:27 PM]
Complete 737-800 cockpit - moving sale
by FaustoP
[June 12, 2019, 01:26:39 AM]
Flyengravity desktop MIP
by patiju
[June 10, 2019, 01:01:06 PM]
the perfect thing to complete your sim hanger
by fsaviator
[June 09, 2019, 03:12:50 PM]
Wanted - COMPLETE set of Boeing 727 or 737 rudder pedals
by kattz
[June 08, 2019, 01:26:09 PM]
Visual system screen by Northern Flight Sim for sale $500
by peterkwu
[June 08, 2019, 06:07:39 AM]
Wanted: GoFlight T8
by C150DIY
[June 07, 2019, 02:32:29 PM]
For Sale - CPFlight MCP737 + EFIS
by ZillaUK
[June 07, 2019, 09:54:58 AM]
737 FWD Overhead Switch Diagram
by bernard S
[June 07, 2019, 08:21:46 AM]
Change the Forum Theme to suit your own Needs.
by AdamMilstead
[June 07, 2019, 06:20:41 AM]
Aileron & Elevator jump back to center
by iwik
[June 06, 2019, 08:01:24 PM]
Join me on Vatsim Tonight
by Trevor Hale
[June 05, 2019, 05:17:13 PM]
Machinery for home cockpit building
by giaviv
[June 04, 2019, 04:12:10 PM]
PROMOCION STEERING FREE
by alvaro castillo
[June 04, 2019, 11:42:43 AM]
FLIGHTSIMEXPO LAUNCHES DISCOUNTED ADVANCE REGISTRATION FOR ORLANDO 2019 EVENT
by fsaviator
[June 03, 2019, 06:52:44 PM]
Question about linking the yokes
by jackpilot
[June 01, 2019, 02:22:10 PM]