Well, I thought, I have plenty of spare cheapduino uno's, surely I could rig something up.
So, de-soldered the wires off the pots in the yoke, done a little bit of copy/mixing/coding for the arduino, linked the output from the pots to input protocol, and the deadband was gone, bonus.
But, a whole arduino using just two pins seems a waste. What else could I use the arduino pins for...., a bit of hole making, a bit of soldering, and 8 buttons later, I have a bit of a modded yoke.
I'll put all the code and stuff I've used to get this going on here, in case it will be any help for others.
Bear in mind, I'm still learning about this flightgear malarky, but I'll try to help if I can. And, I'll add, most of th stuff I needed, I gleened from the forum. I've just put my stuff in one place.
Arduino Code:
- Code: Select all
/*
//Keypad Tester 01. Created by Martyn Currey
// Global Variables
const byte keypadPin = A5;
int val = 0;
void setup()
{
Serial.begin(9600);
while (!Serial) { ; }
Serial.println(F("Start\n"));
// set the analogue pin for input and turn on the internal pullup resistor
pinMode(keypadPin, INPUT_PULLUP);
}
void loop()
{
val = getKeyValue();
Serial.println( val );
delay(100);
}
int getKeyValue()
{
int pinVal;
pinVal = analogRead(keypadPin);
return pinVal;
}
*/
// -------------------------------------------------------------------------------
// /*
//Keypad Tester 02. Created by Martyn Currey, modified by John
const int ailPin = A0; const int elevPin = A1; // potentiometer pins
const int buttonsPin = A5; // buttons analog pin on A5
int bState[8]; // Array for button states
int bCount = 8; // number of buttons
int vLow[8] = { 0, 217, 352, 445, 516, 571, 614, 649 } ; //Array for low button analog readings
int vHigh[8] = { 35, 237, 372, 465, 536, 591, 634, 669 } ; //Array for high button analog readings
unsigned long interval = 90; unsigned long previousMillis = millis(); // milli timer for debounce
void setup()
{
Serial.begin(9600);
while (!Serial) { ; }
pinMode(buttonsPin, INPUT_PULLUP); // sets analog pin for input
// sets analog buttons as LOW
for (int thisBut = 0; thisBut < bCount; thisBut++) {
int (bState[thisBut], LOW);
}
}
void loop()
{
// print analog readings
Serial.print(mapf(analogRead(ailPin), 188, 892, -1, 1)); Serial.print(",");
Serial.print(mapf(analogRead(elevPin), 182, 902, -1, 1)); Serial.print(",");
// print button presses to serial
getKey(); // run analog pin reading
for (int thisBut = 0; thisBut < bCount; thisBut++) {
Serial.print(bState[thisBut]); Serial.print(",");
}
Serial.println();
}
int getKey() // convert analog button pin readings to button states
{
int val = analogRead(buttonsPin); // Read analog pin
// Momentary swich resets
bState[1] = 0;
bState[3] = 0;
if ((millis() - previousMillis) >= interval) {
// Which button was pressed
for (int thisBut = 0; thisBut < bCount; thisBut++) {
if ( (val >= vLow[thisBut]) && (val <= vHigh[thisBut]) ) {
bState[thisBut] = !bState[thisBut];
}
}
previousMillis = millis();
}
}
// map analog pot pins to values
float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
float result;
result = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
return result;
}
Arduino pins:
http://www.martyncurrey.com/keypads/
Protocol XML stuff:
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
<input>
<var_separator>,</var_separator>
<line_separator>\n</line_separator>
<!-- Pot 1 -->
<chunk>
<name>aileron</name>
<type>float</type>
<node>/controls/flight/aileron</node>
</chunk>
<!-- Pot 2 -->
<chunk>
<name>elevator</name>
<type>float</type>
<node>/controls/flight/elevator</node>
</chunk>
<!-- But 0 -->
<chunk>
<name>Battery</name>
<node>/controls/switches/master-bat</node>
<type>int</type>
</chunk>
<!-- But 1 -->
<chunk>
<name>Primer</name>
<node>/controls/arduino/button1</node>
<type>int</type>
</chunk>
<!-- But 2 -->
<chunk>
<name>Avionic Master</name>
<node>/controls/switches/master-avionics</node>
<type>int</type>
</chunk>
<!-- But 3 -->
<chunk>
<name>Heading Bug</name>
<type>int</type>
<node>/autopilot/settings/heading-bug-deg</node>
<relative>true</relative>
<min>1</min>
<max>360</max>
<wrap>true</wrap>
</chunk>
<!-- But 4 -->
<chunk>
<name>Start</name>
<node>/controls/arduino/button4</node>
<type>int</type>
</chunk>
<!-- But 5 -->
<chunk>
<name>Alternator</name>
<node>/controls/switches/master-alt</node>
<type>bool</type>
</chunk>
<!-- But 6 -->
<chunk>
<name>Lights</name>
<node>controls/lighting/instruments-norm</node>
<type>int</type>
</chunk>
<!-- But 7 -->
<chunk>
<name>Pitot</name>
<node>controls/anti-ice/pitot-heat</node>
<type>int</type>
</chunk>
</input>
</generic>
</PropertyList>
nas Code(for the trickier buttons)
- Code: Select all
setlistener("/controls/arduino/button1", func {
if (getprop("/controls/arduino/button1") == 1) {
fgcommand(c172p.pumpPrimer());
}
}, 0, 0);
setlistener("/controls/arduino/button4", func {
if (getprop("/controls/arduino/button4") == 1) {
fgcommand(controls.startEngine(1));
}
}, 0, 0);
xml file goes in fgdata/Protocol folder
nas file goes in .fgfs/Nasal folder
Arduino code gets uploaded to arduino board
This gets entered in settings - additional settings box:
--generic=serial,in,30,/dev/ttyUSB0,9600,arduyoke