Hello, all.
This is my first post in the forum. I discovered Arduino earlier this year after a lucky internet search.
I would really appreciate some assistance here with coding which is giving me major headaches!
I am in the process of interfacing real aircraft gauges with Switec X25 stepper motors for use with Microsoft Flight Simulator 9. My aircraft is a Boeing 727-200.
There is a separate interface program called 'Link2FS' which is a true blessing and FSUIPC (which captures 'numbers' from the flight simulator program itself) in integrates them into the Link2FS program.
I've previously interfaced using 28BYJ48 stepper motors using these applications/programs but do not like them for my purposes; they operate at high temperatures and their accuracy is less than stellar.
Also, their 're-set to zero' at the beginning of the application leaves something to be desired (its never the same twice).
As a result, I've discovered automotive gauges (in the Switec X25 range of products and similar stepper motors manufactured by a company called 'MCR.' I'm using the MCR MR1109 steppers which have an internal stop and offer 315-degrees of movement.
I've been fortunate enough to also discover the Switec X25 library, courtesy of Guy Carpenter.
I am using his library for my project.
After numerous attempts, I'm happy to say that I am close....VERY close. Yet, I'm having an issue in the actual operation of the gauge I'm currently attempting to operate.
In the following code, it compiles correctly to my Arduino Uno (which I'm just using as a testbed for now...down-the-road, I will move to one of the many Arduino Mega 2560s I have).
Here's my code:
#include "SwitecX25.h"
#define STEPS (315*3)
SwitecX25 motor1(STEPS, 8, 9, 10, 11);
int CodeIn;
int motor1Position;
int motor1Delay = 1100;
void setup() {
Serial.begin(115200);
Serial.println("LET'S GO!");
motor1.zero();
}
void loop() {
motor1.update();
if (Serial.available()) {
CodeIn = getChar();
if (CodeIn == '#') {POUND();}
}
}
char getChar()
{
while (Serial.available() == 0);
return((char)Serial.read());
}
void POUND() {
CodeIn = getChar();
switch(CodeIn) {
case 'a':
String motor1Link2FS;
int motor1Position;
motor1Link2FS += getChar();
motor1Link2FS += getChar();
motor1Link2FS += getChar();
motor1Position = motor1Link2FS.toInt();
stepTo(motor1Position);
motor1Position = map(motor1Position, 0, 100, 0, 250);
}
}
void stepTo(int targetPosition) {
do {
if (motor1Position < targetPosition) {
clockwise();
motor1Position ++;
}
else if (motor1Position > targetPosition) {
anticlockwise();
motor1Position --;
}
}
while (motor1Position != targetPosition);
}
void clockwise() {
for (int i = 7; i >= 0; i--)
{
motor1.setPosition(i);
motor1.updateBlocking();
}
}
void anticlockwise() {
for (int i = 0; i < 8; i++)
{
motor1.setPosition(i);
motor1.updateBlocking();
}
}
It compiles and when activated, resets to ZERO on start-up, which is exactly what I want.
However, when I advance my aircraft's thrust lever for this particular stepper (motor1), the gauge and needles just vibrate...there is no needle movement to the correct indication.
I know its probably something ridiculously simple and something I've definitely overlooked.
I am asking for assistance and feedback on this.
In advance, I thank you for the set of eyes on my project.
Thanks!
Jay
KFLL