Welcome to Cockpitbuilders.com. Please login or sign up.

April 26, 2024, 12:47:40 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
349 Guests, 1 User
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,641
  • Total Topics: 7,853
  • Online today: 354
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 1
Guests: 349
Total: 350

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Video of latest project

Started by 727737Nut, December 03, 2015, 07:21:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

727737Nut

I retrofitted a Switek X25-168 gauge cluster stepper to inside of this real gauge. Using Teensy LC driving it directly from 4 output pins as you can see it stops on 0 perfectly each time. Was fairly easy to accomplish and super easy code. I highly recommend these steppers for any single needle gauge.  They make 315deg and 360deg versions for less than 2.00!

Rob
https://youtu.be/rBU14gAjDDw
737 Junkie

Sam Llorca

That's just awesome!!!

Cheers, Rob.

Jan737

Looks great! I've ordered these steppers too.
Are you willing to share your code?

Regards

Jan

727737Nut

Quote from: Jan737 on December 04, 2015, 06:49:40 AM
Looks great! I've ordered these steppers too.
Are you willing to share your code?

Regards

Jan
No problem Jan and thanks Sam!  ;)

Quote//Secondary Engine Gauges

float map1 (float x, const float& x0, const float& x1, const float& y0, const float& y1)
{
  if (x <= x0) return y0;
  if (x >= x1) return y1;

  float gradient = (y1 - y0) / (x1 - x0);
  return y0 + (x - x0) * gradient;
}

#include <AccelStepper.h>

AccelStepper stepper1(4, 0, 1, 2, 3); //(Coils A1 A2 B1 B2
AccelStepper stepper2(4, 13, 14, 15, 16); //(Coils A1 A2 B1 B2
AccelStepper stepper3(4, 17, 18, 19, 20); //(Coils A1 A2 B1 B2
AccelStepper stepper4(4, 12, 11, 10, 9); //(Coils A1 A2 B1 B2

FlightSimFloat OilTemp1;
FlightSimFloat OilTemp2;
FlightSimFloat OilQty1;
FlightSimFloat OilQty2;
FlightSimFloat OilPres1;
FlightSimFloat OilPres2;

void setup() {
  pinMode(23, OUTPUT); //PWM out to #1 Eng Oil Quantity
  pinMode(22, OUTPUT); //PWM out to #2 Eng Oil Quantity
  stepper1.setMaxSpeed(100.0);
  stepper1.setAcceleration(100.0);
  stepper2.setMaxSpeed(100.0);
  stepper2.setAcceleration(100.0);
  stepper3.setMaxSpeed(100.0);
  stepper3.setAcceleration(100.0);
  stepper4.setMaxSpeed(100.0);
  stepper4.setAcceleration(100.0);
  stepperHome(); //runs routine to home motors

  OilTemp1  =  XPlaneRef("FJS/732/Eng/OilTemp1Needle");
  OilTemp2  =  XPlaneRef("FJS/732/Eng/OilTemp2Needle");
  OilQty1  =  XPlaneRef("FJS/732/Eng/OilQuantity1Needle");
  OilQty2   =  XPlaneRef("FJS/732/Eng/OilQuantity2Needle");
  OilPres1  =  XPlaneRef("FJS/732/Eng/OilPress1Needle");
  OilPres2  =  XPlaneRef("FJS/732/Eng/OilPress2Needle");

  delay(5000);
}

void stepperHome() { //this routine should run the motor to the internal stop

  stepper1.runToNewPosition(-450);
  stepper2.runToNewPosition(-450);
  stepper3.runToNewPosition(-450);
  stepper4.runToNewPosition(-450);
  stepper1.setCurrentPosition(0);
  stepper2.setCurrentPosition(0);
  stepper3.setCurrentPosition(0);
  stepper4.setCurrentPosition(0);
}

void loop() {
  FlightSim.update();

  float val = OilTemp1;
  val = map1(val, -50, 120, 0, 400);
  stepper1.moveTo(val);
  stepper1.run();
 
  float val2 = OilTemp2;
  val2 = map1(val2, 0, 120, 120, 410);
  stepper4.moveTo(val2);
  stepper4.run();

  float L2 = map1(OilPres1, 0, 60, 0, 385);
  stepper2.moveTo(L2);
  stepper2.run();

  float L3 = map1(OilPres2, 0, 60, 0, 385);
  stepper3.moveTo(L3);
  stepper3.run();

  float LO = map1(OilQty1, 0, 5, 22, 255);
  analogWrite(23, LO);

  float L1 = map1(OilQty2, 0, 5, 26, 255);
  analogWrite(22, L1);

}
737 Junkie

Caflyt

You're a genius Rob.
Great job!!

Craig

Jan737

Thanks for the code. That helped a lot.

Regards
Jan

727737Nut

Quote from: Jan737 on December 05, 2015, 07:13:24 AM
Thanks for the code. That helped a lot.

Regards
Jan

Glad it did but remember I am using Teensy and X-Plane so coding is a little different.
Rob
737 Junkie

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate