Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focusing with a 28BYJ #1249

Open
Mooflotic opened this issue May 6, 2024 · 3 comments
Open

Focusing with a 28BYJ #1249

Mooflotic opened this issue May 6, 2024 · 3 comments

Comments

@Mooflotic
Copy link

Mooflotic commented May 6, 2024

Add a focusing routine to drive a simple 28BYJ.
I currently manually drive through a python script on RPi 4 via SSL but it's cumbersome:

import curses
import RPi.GPIO as GPIO
from time import sleep

# Definizione dei pin del motore
IN1 = 17
IN2 = 18
IN3 = 27
IN4 = 22

# Sequenze per il motore 28BYJ
SEQ = [
    [1, 0, 0, 1],
    [1, 0, 0, 0],
    [1, 1, 0, 0],
    [0, 1, 0, 0],
    [0, 1, 1, 0],
    [0, 0, 1, 0],
    [0, 0, 1, 1],
    [0, 0, 0, 1]
]

# Inizializzazione dei GPIO
def setup():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(IN1, GPIO.OUT)
    GPIO.setup(IN2, GPIO.OUT)
    GPIO.setup(IN3, GPIO.OUT)
    GPIO.setup(IN4, GPIO.OUT)
    GPIO.setwarnings(False)  # Disabilita i warning sui pin GPIO già in uso

# Funzione per impostare i pin del motore
def set_step(w1, w2, w3, w4):
    GPIO.output(IN1, w1)
    GPIO.output(IN2, w2)
    GPIO.output(IN3, w3)
    GPIO.output(IN4, w4)

# Funzione per far ruotare il motore di un certo numero di passi
def step(steps, direction):
    if direction == 'clockwise':
        seq = SEQ
    elif direction == 'counterclockwise':
        seq = SEQ[::-1]  # Inverti la sequenza per il senso antiorario
    
    for i in range(steps):
        for j in range(8):
            set_step(*seq[j])
            sleep(0.005)  # Ritardo di 5 millisecondi tra ciascun passo

# Funzione per controllare il motore con input da tastiera
def control_motor(stdscr):
    stdscr.clear()
    stdscr.addstr("Usa le frecce direzionali per controllare il motore. Premi 'q' per uscire.\n")
    stdscr.refresh()
    setup()

    while True:
        key = stdscr.getch()
        if key == curses.KEY_UP:
            step(1, 'clockwise')
        elif key == curses.KEY_DOWN:
            step(1, 'counterclockwise')
        elif key == ord('q'):
            GPIO.cleanup()  # Pulizia dei pin GPIO prima di uscire
            break

# Eseguire il programma principale utilizzando curses
if __name__ == "__main__":
    curses.wrapper(control_motor)
@aaronwmorris
Copy link
Owner

Thanks for the code snippet. I am close to being able to start working on this.

@Mooflotic
Copy link
Author

Take your time, I'm here to help you if you need me.

@aaronwmorris
Copy link
Owner

Merged #1266 to support controlling a 28BYJ-48 stepper motor in indi-allsky.

I swapped the RPi.GPIO module for the Adafruit-Blinka module which is better maintained and supports a wide variety of systems, not just Raspi.

When you configure the focuser in the Config -> Devices view, an interface will appear in the Focus view were you can directly control the stepper motor to adjust focus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants