Page 1 of 1

Simple tkinter and Python3 help

Posted: Mon Aug 27, 2018 11:50 pm
by Hardball1911
I know I'm missing something simple, but I've not worked with python previously.

My question is, I have a tkinter GUI that I am using to control servos via tkinter button presses.

I can get servos to move properly in both directions, and even get them to "center" for calibration (setup).

I'm missing something simple in the fact that I want to also control the step speed. I have seen this thread and semucon's response with example code, but I can't figure out how to apply it. I'm old, I'm tired, and I'm learning a new programming language (python...).

Any assistance is freakin awesome!

Re: Simple tkinter and Python3 help

Posted: Tue Aug 28, 2018 9:13 am
by scotty101
I'm not sure what your question is.... You want to control the step speed but what part are you having trouble with? The GUI part or the servo control part?

Re: Simple tkinter and Python3 help

Posted: Tue Aug 28, 2018 1:54 pm
by moderatelyfunky
I am working through the stepper learning process too, so take whatever I say with a grain of salt.

Check out Joan's incredible pigpiod library -

If you're looking for one speed all the time, there is PWM and the set_PWM_frequency method.

Code: Select all

            pi.set_PWM_dutycycle(self.stepPin, 128) 
            pi.set_PWM_frequency(self.stepPin, 500)
If you want variation, you can use waves to contruct an array of pulses with different delay lengths. I have this for loop that builds up motor speed

Code: Select all

        maxDelay = 1100 #higher number, lower frequency
        minDelay = 400 #the fastest the motor will run 
        step = 1 #how quickly to move between lowest and highest frequency
        wfStart []
        for delay in range(maxDelay, minDelay, -step):
            wfStart.append(pigpio.pulse((1<<stepPin), 0, delay))
            wfStart.append(pigpio.pulse(0, (1<<stepPin), delay))
       startRamp = pi.wave_create()

Re: Simple tkinter and Python3 help

Posted: Tue Aug 28, 2018 3:35 pm
by Hardball1911

The trouble I’m having is figuring out how to apply the step_speed as was in the example that I posted in the link when handing the command off with the button.

I have gotten the servos working with a simple lambda: set_servo(servo_max) as the command of the button, but I couldn’t get the example code to work more than that. I think what I’m looking for is a suggestion as to how to hand off the step speed along with the “set_servo”. In the example he handles it within the function by range of min to max and step-speed being the steps in the for loop. I understand what he does there, but it isn’t working when called outside the while loop. Not because his example is jacked, because I’m jacked.

I’d post my code but I wiped it out and started over.

I know it’s something simple, but as stated earlier, I’m newly learning python as stated before so bear with me.

Re: Simple tkinter and Python3 help

Posted: Tue Aug 28, 2018 3:38 pm
by Hardball1911

I’ll look that over closely when I get home, thank you all, by the way, for your responses. I do have coding experience, but I work mostly with hardware now, leaving the coding to those who aren’t under doctor’s orders to cut back on energy drinks. :D

Re: Simple tkinter and Python3 help

Posted: Mon Sep 10, 2018 8:03 pm
by Hardball1911
Nothing? Noone? Still a relevant question for me...

Re: Simple tkinter and Python3 help

Posted: Mon Sep 10, 2018 8:22 pm
by pws
Not clear what you are waiting for....

Re: Simple tkinter and Python3 help

Posted: Tue Sep 11, 2018 7:17 am
by pootle
You need to explain what you are trying to achieve, and where you have got to, as well as what hardware you are using.

All we seem to have established for certain is that you are using stepper motors and have some buttons.

What are you using to drive the steppers?

An Adafruit DC & stepper motor hat?

A driver breakout board like a pollolu A4988?

A bunch of transistors wired as an H bridge?

A trinamic breakout board?

And what do you want the user controls to be?

Goto functionality?

move (direction) at speed X?

Accelerate as long as button is pressed?