Home > Net >  My goal is to run a Stepper through Python, but the values such as angular velocity and degrees are
My goal is to run a Stepper through Python, but the values such as angular velocity and degrees are

Time:05-19

Thanks for the help! My progress so far... Issues: 1 - I need the program to store the values inputted by user when start button is pressed. 2 - I need the stepper to keep rotating and also stop at a specific direction. This is my code:

https://pastebin.com/2wcwpZx5

import random
 
from itertools import count
 
import pandas as pd
 
import matplotlib.pyplot as plt
 
from matplotlib.animation import FuncAnimation
 
import tkinter as tk
 
from time import sleep

CodePudding user response:

I had to move quite a bit of things around. There may be some issues with this still as I am not familiar with all the context of the original code. However, hopefully it is good enough that you can see how to accomplish your goal.

from tkinter import *
from pymata4 import pymata4

top = Tk()
top.geometry("450x300")
pins = [8,9,10,11]
board = pymata4.Pymata4()

# These variables need to be declared to be in the global space.
angularvelocity = 0.0  # I assumed this is a float type.
numsteps = 0  # I assumed this is an int type.
complete = False  # I added this to show how to stop running.


def actuate():
    global angularvelocity, numsteps, complete
    board.stepper_write(angularvelocity, numsteps)
    if complete:
        pass
    else:
        top.after(1000, actuate)  # This will run actuate after 1000 ms
    

def set_input():
    global pins, angularvelocity, numsteps
    angularvelocity = angular_velocity_var.get() # run .get() on DoubleVar object instead
    numsteps = num_steps_var.get()  # run .get() on IntVar object instead
    board.set_pin_mode_stepper(numsteps, pins)  # it was num_steps?
    actuate()

num_steps = Label(top, text="Steps").place(x=40, y=60)
angular_velocity = Label(top, text="Angular Velocity").place(x=40,y=100)
# Button requires a command definition or it is just for looks
submit_button = Button(top, text ="Submit" command=set_input).place(x=40,y=130)
num_steps_var = IntVar()  # These are tkinter built in. There is also a StringVar
num_steps_input_area = Entry(top, width=30, textvariable=num_steps_var).place(x=180,y=60)
angular_velocity_var = DoubleVar()  # and a BooleanVar
angular_velocity_input_area = Entry(top, width=30, textvariable=angular_velocity_var).place(x=180, y=100)



top.mainloop()

Let me know if it works for you. I didn't run this.

  • Related