Xplane flap gauge and Teensy 2++

Status
Not open for further replies.

Raggedone

New member
I have a Teensy 2++ and I have tried to get my flap gauge to work with the following code:

#include <Servo.h>
Servo fmotor; // an RC Servo motor for flaps
FlightSimFloat FLAPRAT; // access to X-Plane's FLAPRAT
const int fmotorPin = 2;
long encoder_prev=0; // for detecting rotary position change
elapsedMillis inactivityTimeout;// an inactivity timeout
int previousAnalog = -100;
void setup() {
fmotor.attach(fmotorPin);
FLAPRAT = XPlaneRef("sim/flightmodel/controls/flaprat");
FLAPRAT.onChange(viewFLAPRAT);
Serial.begin(9600);
Serial.println("FLAPRAT");
}
void loop() {
FlightSim.update();
}
void viewFLAPRAT(float val)
{
int angle = val *172.0 + 0.0;
fmotor.write(angle);
Serial.print("(X-Plane) FLAPRAT = ");
Serial.println(FLAPRAT);
}

The servo hits the stop limit and then gets hot. Can you tell me what I am doing wrong. I have been fighting this for over a week now.

Thanks
 
Can you tell us the range of the values that are written by Serial.println? Maybe you could also try output the angle you're actually writing to fmotor.
 
So to be more exact, when I move the flaps back to 0 or fully up is when the servo hits the stop limit, vibrates and gets hot.
 
wrong Dataref

So to be more exact, when I move the flaps back to 0 or fully up is when the servo hits the stop limit, vibrates and gets hot.

The DataRef you are using is not the flaps in degrees but a flap-ratio
To drive your servo, you need to use : Flaps = XPlaneRef ("sim/flightmodel/controls/wing1l_fla1def");
This dataref is in actual Degrees

Thus you could write: myservo.write(Flaps);

IMPORTANT NOTE
Some servos do only 90 degrees
The most common ones 180 degrees
Going over their limit will burn out the servo and eventually your Teensy board

In some cases you can modify a servo to do approx 270 degrees (limited by the internal potentiometer)
 
Status
Not open for further replies.
Back
Top