Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 0
  • *Guests: 59
  • *Total: 59

Our Discord

WORLDFLIGHT 2019 - TEAM USA SUPPORTERS (HERO'S)

 
Worldflight 2019
Donations Starting Early
With 50 Days Left, it's time to start Counting Down to Worldflight 2019.  Beginning in August, we had 2 kind gentleman lead the way on our quest for donations to this amazing Charity Event.  Over the Past 6 Years, we (This community) Has helped to raise over $25,000.00USD to help the kids and their families of the All Children's Hospital in St. Petersburgh, Florida.  Kicking off the donations this year these Two Hero's are leading the way to another Successful Year.  I personally want to thank these two Gentleman and use this opportunity to have all of you donate to our wonderful cause. 
Thank you in advance for your help and please wish us much success for our 2019 event.
       
  ---Worldflight 2019 HEROS---

 James Williams, Warren Soeldner,  Sam Llorca, Doug Snow, Ryan O'Keefe, Edwin Burton        





Thanks to all of you, You are all helping to make Worldflight 2019 a success..
Because of all you wonderful people so far we have raised a total of:

$1245.00 USD


Author Topic: Wet Compass Code (Arduino/Teensy)  (Read 5400 times)

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 824
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Wet Compass Code (Arduino/Teensy)
« on: November 22, 2016, 06:29:38 PM »
The code below runs on a Teensy 3.2 but could be easily ported to run on an Arduino.
It uses the Stepper libraries and the Teensy-Duino library found here:
https://www.pjrc.com/teensy/td_flightsim.html

Project uses a 720-steps per revolution stepper motor and an optical sensor so it can slave to
a known starting point before feeding it heading info.

================================================================
#include <SoftwareSerial.h>
#include <serLCD.h>
#include <Stepper.h>

const int stepsPerRevolution = 720;  // change this to fit the number of steps per revolution
// for your motor
    int Direction = 0; // 0 = CCW, 1 = CW
    int sensorVal = 0;
     
// initialize the stepper library on pins 2 through 5:
    Stepper myStepper(stepsPerRevolution, 2,3,4,5);

// X-Plane Stuff
FlightSimFloat aircraftHeading;

int _aircraftHeading = 0;
int compassHeading;
   
void setup() {
  pinMode(23, INPUT_PULLUP);
  pinMode(13, OUTPUT);

  // set the speed at 60 rpm:
  myStepper.setSpeed(30);
 
  // SET UP X-PLANE REFS
  aircraftHeading = XPlaneRef("sim/cockpit/misc/compass_indicated");

   //---- Start Seek To Zero ----//
   // Test if we're blocking the sensor
      sensorVal = digitalRead(23);
      if (sensorVal == LOW)
      {
      Direction = 1;
      myStepper.step(80); // Get it out of the way
      }

      sensorVal = digitalRead(23);
      while (sensorVal == HIGH)
      {
      Direction = 1;
      myStepper.step(1);
      sensorVal = digitalRead(23);
      } 

  // Now Slew to North
  myStepper.step(196); //<< Your results may vary

  delay(1000);
  // Set Known starting points   
  _aircraftHeading = 0;
  compassHeading  = 0;

 
}

void loop() {
   // Query X-Plane Data
  FlightSim.update();
  _aircraftHeading = (int)aircraftHeading;

  // Compensate for zero-crossing
  if(compassHeading - _aircraftHeading > 180) {_aircraftHeading = _aircraftHeading + 360;}
  else if (compassHeading - _aircraftHeading < -180) {_aircraftHeading = _aircraftHeading - 360;}
 
  // Slew Right (Delay(5) adds rotational dampening)
  if(_aircraftHeading > compassHeading)
  {
    compassHeading += 1;
    myStepper.step(1);
    delay(5);   
    myStepper.step(1);
    delay(5);
    if (compassHeading > 359) {compassHeading = 0;}
    }


  // Slew Left (Delay(5) adds rotational dampening)
  else if(_aircraftHeading < compassHeading)
  {
    compassHeading -= 1;
    myStepper.step(-1);
    delay(5);   
    myStepper.step(-1);
    delay(5);
    if (compassHeading < 1) {compassHeading = 360;}
   }
   
}


 


Ray Sotkiewicz

Offline sagrada737

  • 737NG Home Cockpit:
  • I may as well be Staff!
  • *
  • Posts: 507
  • N737CM - Keep your airspeed up !
    • Imaging The Heavens
  • First Name: Mike
  • Home Location: Las Cruces, New Mexico USA
Re: Wet Compass Code (Arduino/Teensy)
« Reply #1 on: November 23, 2016, 05:28:18 AM »
Hi Ray,

Thanks for posting your code for the Teensy control of a magnetic compass function.   I understand that you are using XPlane, but do you know of a way that this could be done with P3D?

Also, any photos/videos of your prototype setup for this project?

Keep up the good work - sounds like a fun project.

Mike
P3d v3.x with Sim-Avionics (two computers), FDS MIP, 3-Optoma HD GT180 projection display driven by a single nvidia GTX980.

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 824
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Wet Compass Code (Arduino/Teensy)
« Reply #2 on: November 23, 2016, 11:51:54 AM »
Hi Mike,

Unfortunately I don't know too much about interfacing P3D with Arduino/Teensy, although I imagine it might look something like the attached picture...  ;) :angel:

You might find some good tidbits here:
https://code.google.com/archive/p/arduino-fs/

That's the really cool thing about X-Plane and Teensy. The libraries are already in place and it's just a simple matter of writing a few dozen lines of code to get it to interact.



« Last Edit: November 23, 2016, 11:52:36 AM by RayS »
Ray Sotkiewicz

Offline Trevor Hale

  • Administrator
  • I am chained to this website!
  • *
  • Posts: 3,877
    • Cockpitbuilders.com
  • First Name: Trevor
  • Home Location: New Liskeard, Ontario
Re: Wet Compass Code (Arduino/Teensy)
« Reply #3 on: November 23, 2016, 03:00:54 PM »
Mike if you have a look around in the arduino forum, I have posted some examples of my arduino code.  the language is basically the same and can almost integrate directly into the program I wrote.  Just need to define the Stepper info.

I am using my arduino with FSX and FSUIPC, no reason it wouldn't work with P3D.

Trev
Trevor Hale

Owner
http://www.cockpitbuilders.com

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

VATSIM:

Offline fsaviator

  • I am chained to this website!
  • *
  • Posts: 1,396
  • Aviation Enthusiast
    • Boeing 737 Next Generation Simulator
  • First Name: Warren
  • Home Location: Riverview, Florida
Re: Wet Compass Code (Arduino/Teensy)
« Reply #4 on: November 24, 2016, 04:14:02 AM »
Ray, Happy Thanksgiving!

I'll be home on the 6th of December.  Let's try to fit some time in over the holidays at some point.  Definitely want to sit with you for some help getting started (finally) with arduino and this compass is perfect.  It is exactly what I need to literally top off my budget GA pit!  Of course it will then help out as it is the last piece of my 737 that I haven't sourced yet.

I want to get this thing up and running as I head out to Thailand, Cambodia, and Nepal in mid-February for almost a month.

I'll go ahead and order a couple of teensy's in the meantime as I needed one anyway.  Should I get the 3.2 or 3.6?  Pins or no pins?  One of each?

 ;D ;D
Warren "MTN385"
Florida

http://www.B737NG-SIM.com and https://www.facebook.com/fsaviator on facebook
FSX, Prosim737 Suite, FDS DSTD 2.0 MIP, RevSim Proline TQ, ACE Dual-linked Yokes, Intel 3.5GHz i7-3770K, MSI Z77A-G45, 16GB G.Skill TridentX DDR3-2400, Galaxy GTX670 GC 4GB, OCZ 60GB Vertex 3

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 824
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Wet Compass Code (Arduino/Teensy)
« Reply #5 on: November 24, 2016, 11:04:49 PM »
Hi Warren,

Great to hear from you again!

I forgot if you were X-Plane or P3D/FSX. If X-Plane, definitely get yourself a couple of Teensy 3.2 boards with the pin and header kits. The code will logically work with an Arduino but you will need to jump through a few more hoops than you would need to if you were using X-Plane / Teensy.

The parts you'll need:

OBP990L11Z (Or similar device) Opto-Interrupter.
You can cross-reference thse at:
http://hu.farnell.com/photo-interrupters/prl/talalatok/5

Stepper motor:
X27 168 720 Steps/Revolution
Cross reference here:
https://www.adafruit.com/product/2424
(You can pick these up on eBay for MUCH cheaper though..)

I'll be posting a how-to video shortly. I'll post the link to it here...

Hope this helps!
Ray Sotkiewicz

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 824
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Wet Compass Code (Arduino/Teensy)
« Reply #6 on: November 25, 2016, 12:15:09 AM »
And the how-to video:
https://youtu.be/1zuljwyB92E
Ray Sotkiewicz

Offline fsaviator

  • I am chained to this website!
  • *
  • Posts: 1,396
  • Aviation Enthusiast
    • Boeing 737 Next Generation Simulator
  • First Name: Warren
  • Home Location: Riverview, Florida
Re: Wet Compass Code (Arduino/Teensy)
« Reply #7 on: November 25, 2016, 05:53:17 AM »
Ordered.  I am using FSX so I'll have to figure that out.
I have everything I need, to include these speedo steppers.  I just need a hands on walkthrough to figure out the process.
Warren "MTN385"
Florida

http://www.B737NG-SIM.com and https://www.facebook.com/fsaviator on facebook
FSX, Prosim737 Suite, FDS DSTD 2.0 MIP, RevSim Proline TQ, ACE Dual-linked Yokes, Intel 3.5GHz i7-3770K, MSI Z77A-G45, 16GB G.Skill TridentX DDR3-2400, Galaxy GTX670 GC 4GB, OCZ 60GB Vertex 3

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 824
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Wet Compass Code (Arduino/Teensy)
« Reply #8 on: November 26, 2016, 03:27:00 PM »
Warren,

Have you seen this guy?
http://www.mobiflight.com/

I just found him and haven't really tried anything out yet from him but it looks WAY easier than the route I took...

One look at my #include header is a dead giveaway as to the complexity of interfacing Arduino with FSX/X-Plane....

#include <thisisreallyugly.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <EthernetClient.h>
#include <Servo.h>
#include <SPI.h>         
#include <Wire.h>
#include <XP_ARDref.h>         // -- include XPlane ARDref library
#include <SoftwareSerial.h>
« Last Edit: November 26, 2016, 05:17:35 PM by RayS »
Ray Sotkiewicz

Offline fsaviator

  • I am chained to this website!
  • *
  • Posts: 1,396
  • Aviation Enthusiast
    • Boeing 737 Next Generation Simulator
  • First Name: Warren
  • Home Location: Riverview, Florida
Re: Wet Compass Code (Arduino/Teensy)
« Reply #9 on: November 26, 2016, 04:05:21 PM »
That is pretty nice.  I think I can get started with that!

Thanks!
Warren "MTN385"
Florida

http://www.B737NG-SIM.com and https://www.facebook.com/fsaviator on facebook
FSX, Prosim737 Suite, FDS DSTD 2.0 MIP, RevSim Proline TQ, ACE Dual-linked Yokes, Intel 3.5GHz i7-3770K, MSI Z77A-G45, 16GB G.Skill TridentX DDR3-2400, Galaxy GTX670 GC 4GB, OCZ 60GB Vertex 3

Offline XOrionFE

  • I am chained to this website!
  • *
  • Posts: 1,704
  • First Name: Scott
  • Home Location: Chicago, IL
Re: Wet Compass Code (Arduino/Teensy)
« Reply #10 on: November 26, 2016, 07:44:14 PM »
Thank you for this code and the video Ray.   I have had mine up there over my head lit up but immobile more as a static item but now I will make it work.   

Very nice!

Scott

 

Recent Posts

727/737 yokes
by Caflyt
[Today at 02:11:06 PM]
WORLDFLIGHT 2019 - Scenery Check Volunteers Needed
by Vincent T.
[September 14, 2019, 03:08:00 PM]
WORLDFLIGHT 2019 - FLIGHT BIDS
by Vincent T.
[September 14, 2019, 03:00:40 PM]
WORLDFLIGHT 2019 - AVAILABILITY
by Trevor Hale
[September 14, 2019, 07:25:32 AM]
WORLDFLIGHT 2019 - Employer matching for Donations...
by RayS
[September 14, 2019, 12:03:45 AM]
SimFest-West 2019 Videos
by RayS
[September 13, 2019, 07:27:16 PM]
737 MAX Build
by helloo
[September 13, 2019, 04:41:17 PM]
A little pucker factor here, I'm sure... nerves of steel
by RayS
[September 12, 2019, 06:30:45 PM]
Which size fuses to use in fuse block supplying FDS boards?
by blueskydriver
[September 11, 2019, 05:56:37 PM]
I finally got the shell pulled off the ATC-810...
by geneb
[September 11, 2019, 07:29:51 AM]
Wanted: Optoma GT1080Darbee Short Throw Projector
by Flightdeck57
[September 11, 2019, 12:24:08 AM]
F16 Simulator For Sale
by blueskydriver
[September 06, 2019, 03:52:34 PM]
Ebay Assistance
by iwik
[September 06, 2019, 02:00:00 PM]
Matrox 3
by jackpilot
[September 05, 2019, 10:45:00 AM]
So I got a big crate the other day...
by geneb
[September 05, 2019, 09:20:22 AM]
Official WF 2019 Route
by fsaviator
[September 05, 2019, 08:20:10 AM]
Are some sellers off their trolly
by kurt-olsson
[September 02, 2019, 12:39:54 PM]
Display Glare FDS w/Pic
by Joe Lavery
[September 01, 2019, 02:33:47 AM]
MCP
by Caflyt
[August 27, 2019, 06:57:41 PM]
Dispatch and Career Add-on
by fsaviator
[August 26, 2019, 10:42:45 AM]
What have you done for your simulator today?
by B763
[August 25, 2019, 04:58:46 PM]
Free Jet Ranger.
by geneb
[August 23, 2019, 06:16:52 PM]
items/oem from overhead
by gufau
[August 23, 2019, 12:49:15 PM]
Hi everyone!
by jskibo
[August 23, 2019, 08:05:33 AM]
737-800 Front window post size
by kurt-olsson
[August 23, 2019, 03:35:11 AM]
Shipping Woes
by Caflyt
[August 22, 2019, 10:47:49 AM]
Worldflight 2019 Open for Business
by Trevor Hale
[August 21, 2019, 08:28:13 AM]
More ?'s - annunciators?
by kattz
[August 21, 2019, 05:44:21 AM]
Looking for annunciators
by kattz
[August 19, 2019, 10:36:39 PM]
OK, So here we go!
by Caflyt
[August 19, 2019, 02:32:28 PM]