Hi all, I am using the Switec X27-168 stepper motor in order to output a gauge in a flight sim game. I have used programs using EasyDriver an A4988 stepper driver boards for a while, but found the EasyDrivers to be very fragile, plus the driver boards required a 12v power supply when the X27 steppers function with very low voltages and power.
As part of the ongoing process, i ended up trying to run the X27 steppers direct from 4 pins of an Arduino nano, and to my amazement I found that not only did it work, but It seemed to be more reliable and when using an RS485 connection was more stable and easier to get working. As a result I have continued to experiment with them woking directly from a Nano. I had three gauges all being displayed simultaneously from one Nano with no lag, perfectly reliably, and after months of use they still work fine.
Now, this is going to be contentions, because every post I've read says to use a stepper driver, for a number of reasons, not least because there may be back EMF or drive..... ok, that may be the case, but my experience has been extremely positive using direct control. I therefore ask for patience (tolerance?) and for you to suspend your impulse to direct me back to a driver board, and help me find a solution to one of the niggles that is a result of abandoning the 'old' thinking.
The issue concerns the fact that if you discontinue the game without essentially parking everything and so restoring the gauges to their Zero positions, they will logically start the next session with 'zero' being the point at which they were last depowered. The guys who set up the commonly used sketches that work via driver boards have such a zeroing subroutine in their sketches, where the stepper is commanded to move 101% positive rotation ( which as the X27 stepper has a stop means it will rotate and stall aginst the positive stop) then command exactly the same in the negative direction, zeroing the stepper. I as an engineer don't understand the need for the first part as logically (for me at least) 101% negative will always take you to min position, but maybe there is an electronic reason.
So what I would like is to have a zeroing routine for the steppers. Looking at the sketch which was derived from one pulled from an old site, it looks like there's some code in there to attempt to do so, but it doesn't seem to do anything.
I have tried lines in the sketch in the setup to say
setPosition (currentPosition-900);
Motor1.update
and similar. It compiles fine, but does nothing
Can I therefore ask for advice on codes to try and achieve a zeroing function for this? I understand that probably none of you have the DCS world game that this functions with, but maybe you have access to an X27 stepper to play with!
If it comes to nothing I have lost nothing but I would really appreciate any guidance
Thanks
Les
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include "SwitecX25.h"
// 315 degrees of range = 315x3 steps = 945 steps int newValue;
unsigned int maxSteps = 800; // declare motor1 with 945 steps on pins
SwitecX25 motor1(maxSteps, 6, 5, 7, 8);
void setup(void)
{
DcsBios::setup(); motor1.zero(); // this is a slow, blocking operation motor1.setPosition(500);
}
void onApuTempChange(unsigned int newValue)
{
unsigned int position = map(newValue, 0, 65535, 0, maxSteps);
motor1.setPosition(position);
}
DcsBios::IntegerBuffer apuTempBuffer(0x10c0, 0xffff, 0, onApuTempChange);
void loop(void)
{
motor1.update();
DcsBios::loop(); }