fehlfarbe / arduino-motorfocus

Arduino motorfocus with moonlite protocol for telescopes
MIT License
48 stars 13 forks source link

Random movements #15

Closed PdP03 closed 2 years ago

PdP03 commented 2 years ago

when I power the motor up (5v Arduino), it starts to move, then when i connect it to ekos or moonlite single focuser and I gave a goto (ex: 10000 steps) it goes where it has to go, but after 10 second it starts again spinning. I have tried to change everything, but nothing seem to have any affect, may be a bug in the code?

fehlfarbe commented 2 years ago

Hmm sounds a bit like wrong wiring or interference :thinking:

Can you try the examples from the AccelStepper library? Maybe some example with longer pauses between moving commands to check if it's wiring related or a bug in the code.

If AccelStepper examples are working:

cybye commented 2 years ago

got the same problems right now on esp8266 D1 mini. the sketch is moving the motor - one direction - probably endlessly and N.I.N.A. // ascom is patiently waiting in initialization(did not debug yet, was there any reason for movement on initialization in the code?). btw. aside the capacitator, it looks like keeping the RST pin supplied with 5V/3.3V via a <1k resistor is an alternative. had no capacitator at hand. (movement is periodic, i.e. move for a while. stop. move for a while .. aso, no buttons at all, pins well connected)

cybye commented 2 years ago

(early) success with defining the 'unconnected buttons as HIGH.

   int btn_in = HIGH; // digitalRead(BTN_IN);
   int btn_out = HIGH; // digitalRead(BTN_OUT);

ps. buttons are actually defined correctly for my board, no bad pointing to nowhere. testing for low might be the thing here. pps. needed to change the timer on ESP8266 (to ESP8266TimerInterrupt) and maybe therefore had some problems with EEPROM commit (also missing in the code). But disabling the timer before EEPROM ops and adding short delay after commit before reenabling it, did it.

PdP03 commented 2 years ago

Hmm sounds a bit like wrong wiring or interference 🤔

Can you try the examples from the AccelStepper library? Maybe some example with longer pauses between moving commands to check if it's wiring related or a bug in the code.

If AccelStepper examples are working:

  • Does the motor always move in the same direction with the motofocus code?
  • Are the buttons connected? Maybe there is a broken button?

I don't use buttons. One thing I forgot to mention is that if I upload the code, disconnect the Arduino and reconnect it starts spinning. When I stop it through software (Moonlite Single Focuser, tried with Ekos, same result) it slows down but whatever the direction where it was spinning, it starts going up with the number of steps. This happens both with an Arduino Uno and a nano. I even tried to change the motor and the driver with no results.

cybye commented 2 years ago

Hmm sounds a bit like wrong wiring or interference 🤔 Can you try the examples from the AccelStepper library? Maybe some example with longer pauses between moving commands to check if it's wiring related or a bug in the code. If AccelStepper examples are working:

  • Does the motor always move in the same direction with the motofocus code?
  • Are the buttons connected? Maybe there is a broken button?

I don't use buttons. One thing I forgot to mention is that if I upload the code, disconnect the Arduino and reconnect it starts spinning. When I stop it through software (Moonlite Single Focuser, tried with Ekos, same result) it slows down but whatever the direction where it was spinning, it starts going up with the number of steps. This happens both with an Arduino Uno and a nano. I even tried to change the motor and the driver with no results.

could you try locating these two lines in the sketch

   int btn_in = digitalRead(BTN_IN);
   int btn_out = digitalRead(BTN_OUT);

and replace them with


   int btn_in = HIGH; // digitalRead(BTN_IN);
   int btn_out = HIGH; // digitalRead(BTN_OUT);

?

PdP03 commented 2 years ago

Don't know why, but it seems to work. Tomorrow I'll do some other tests, I'll let you know if everything checks out.

fehlfarbe commented 2 years ago

Hey,

sorry, I don't have much time at the moment. It sounds like the Button input Pins are floating so they get some random signals.

The pinMode setup should prevent this already with activating the internal PULLUP resistor so the input should always be HIGH if nothing is connected (or the button is open)

  pinMode(BTN_IN, INPUT_PULLUP);
  pinMode(BTN_OUT, INPUT_PULLUP);

https://github.com/fehlfarbe/arduino-motorfocus/blob/master/src/arduino-motorfocus.cpp#L101

But maybe there is a problem with some boards or so. If you don't need the buttons you can just change the code like @cybye suggested or you can add external pullup resistors. Just add a 10K resistor between BTN_IN and 5V (or 3.3V for ESP8266) and do the same for BTN_OUT and 5V/3.3V.

Maybe I will find some time for further investigations this week.

PdP03 commented 2 years ago

Hmm sounds a bit like wrong wiring or interference 🤔 Can you try the examples from the AccelStepper library? Maybe some example with longer pauses between moving commands to check if it's wiring related or a bug in the code. If AccelStepper examples are working:

  • Does the motor always move in the same direction with the motofocus code?
  • Are the buttons connected? Maybe there is a broken button?

I don't use buttons. One thing I forgot to mention is that if I upload the code, disconnect the Arduino and reconnect it starts spinning. When I stop it through software (Moonlite Single Focuser, tried with Ekos, same result) it slows down but whatever the direction where it was spinning, it starts going up with the number of steps. This happens both with an Arduino Uno and a nano. I even tried to change the motor and the driver with no results.

could you try locating these two lines in the sketch

   int btn_in = digitalRead(BTN_IN);
   int btn_out = digitalRead(BTN_OUT);

and replace them with


   int btn_in = HIGH; // digitalRead(BTN_IN);
   int btn_out = HIGH; // digitalRead(BTN_OUT);

?

With this fix, everything works fine, thanks a lot man!