Cockpitbuilders.com
Main => General Discussion Board. => Topic started by: 727737Nut on December 03, 2015, 07:21:15 PM
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 (https://youtu.be/rBU14gAjDDw)
That's just awesome!!!
Cheers, Rob.
Looks great! I've ordered these steppers too.
Are you willing to share your code?
Regards
Jan
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);
}
You're a genius Rob.
Great job!!
Craig
Thanks for the code. That helped a lot.
Regards
Jan
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