Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 3
  • *Guests: 75
  • *Total: 78

Our Discord

Author Topic: Wet Compass Code for Teensy (Updated)  (Read 1146 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
Wet Compass Code for Teensy (Updated)
« on: June 30, 2017, 09:46:01 PM »
Updated the math calculation for the zero-crossing issue. This code is solid.

Note that when I slew the motor left or right, I do it twice per call. The stepper motor is a 720-step, so a 1-degree compass change requires 2 steps.

#include <SoftwareSerial.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;
int Slew;
unsigned long previousMillis = 0;
unsigned long interval = 300000;
   
void setup() {
  pinMode(23, INPUT_PULLUP);
  pinMode(13, OUTPUT);

  // set the speed at 50 rpm:
 
  myStepper.setSpeed(50);

  // 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);
      }
   
      sensorVal = digitalRead(23);
      while (sensorVal == HIGH)
      {
        Direction = 1;
        myStepper.step(1);
        sensorVal = digitalRead(23);
      } 

  delay(200);
   myStepper.step(195);

  delay(1000);

  //TEST HARNESS: Manage aircraftHeading
  //   aircraftHeading = 0;
  //   compassHeading  = 0;

 
}

void loop() {
    FlightSim.update();
    _aircraftHeading = (int)aircraftHeading;
 
  // Compensate for zero-crossing
  Slew = _aircraftHeading - compassHeading;
  if(Slew < -180)  {Slew += 360;}
  if(Slew >  180)  {Slew -= 360;}
 
    // RIGHT TURNS
  if(Slew > 0)
  {
    compassHeading += 1;
    myStepper.step(1);
    delay(4);   
    myStepper.step(1);
    delay(4);
  }

  // LEFT TURNS
  if(Slew < 0)
  {
    compassHeading -= 1;
    myStepper.step(-1);
    delay(4);   
    myStepper.step(-1);
    delay(4);
   }
   
}

void seekToZero()
{
//---- Start Seek To Zero ----//
  // Test if we're blocking the sensor
      sensorVal = digitalRead(23);
      if (sensorVal == LOW)
      {
        Direction = 1;
        myStepper.step(80);
      }
   
      sensorVal = digitalRead(23);
      while (sensorVal == HIGH)
      {
        Direction = 1;
        myStepper.step(1);
        sensorVal = digitalRead(23);
      } 

  delay(5);
   myStepper.step(196);
}
 





Ray Sotkiewicz

Offline Bob Reed

  • Administrator
  • I am chained to this website!
  • *
  • Posts: 2,378
  • Bob the Builder!
  • First Name: Bob
  • Home Location: Holley, New York
Re: Wet Compass Code for Teensy (Updated)
« Reply #1 on: July 01, 2017, 10:18:21 AM »
 :P mind boggling!  :D

Offline iwik

  • Forum GURU
  • *
  • Posts: 368
  • GA Jockey
  • First Name: Les
  • Home Location: Christchurch New Zealand
Re: Wet Compass Code for Teensy (Updated)
« Reply #2 on: July 01, 2017, 07:33:55 PM »
Ray,
A quick question re compass card. I see you removed bar magnet assembly. Does the brass gear just pull off the  rotating disc shaft? Any tips as this seems very fragile. Cant see any other way to remove bar mech.
Thanks
Les

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: Wet Compass Code for Teensy (Updated)
« Reply #3 on: July 01, 2017, 08:10:49 PM »
That brass gear is here to stay. She ain't goin' nowhere. :-)

What I did was super-glue a small flat-head machine screw onto the brass gear so the pointy end is facing rearwards.

Then, after gauging where shaft would align on the back plate, I drilled a hole in the back plate where the stepper shaft will fit through. I used heat shrink tubing to link the stepper shaft to the screw on the brass gear. After everything was aligned, I used rubber cement to mount the stepper motor to the rear of the compass housing.

It's a little tricky because it's pretty much a one-way process. Once everything is mounted there's little option to go back in and align or work on the internals.
Ray Sotkiewicz

Offline iwik

  • Forum GURU
  • *
  • Posts: 368
  • GA Jockey
  • First Name: Les
  • Home Location: Christchurch New Zealand
Re: Wet Compass Code for Teensy (Updated)
« Reply #4 on: July 01, 2017, 08:17:05 PM »
Thanks,
I gathered that the brass gear is fixed and thought you may have had  a trick to
get the screw centered on the the gear as if this is off center then the disc wont rotate freely.
Les

 

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]