Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Aula šŸ’”šŸ•Šļø
Published

Controlling a Servo Motor with Raspberry Pi and Python GUI

In this tutorial we are going present how to precisely control a servo using the Raspberry Pi and Python TK GUI.

IntermediateFull instructions provided1 hour12,139
Controlling a Servo Motor with Raspberry Pi and Python GUI

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
Ɨ1
Adafruit servo HiTEC HS-322HD
Ɨ1
Breadboard (generic)
Breadboard (generic)
Ɨ1
Jumper wires (generic)
Jumper wires (generic)
Ɨ1

Story

Read more

Schematics

Circuit Diagram

Code

The code in python 3

Python
from tkinter import *
#Thinter in python 2
import RPi.GPIO as io
import time
io.setmode(io.BOARD)
io.setup(11,io.OUT)
p=io.PWM(11,50)
p.start(2.5)
root = Tk()
Label(root, text="Angle").grid(row=0)
e1 = Entry(root)
e1.grid(row=0, column=1)

def cal():
    global dc
    deg1 =e1.get()
    deg = abs(float(deg1))
    dc = 0.056*deg + 2.5
    p.ChangeDutyCycle(dc)
    print(deg, dc)
   
b1= Button(root, text = "Enter",bg="pink", command =cal)
b1.grid(row=2, column=1)
b3 = Button(root, text='Quit', bg= "cyan", command=root.quit)
b3.grid(row=2, column=3)
root.mainloop()
 

Credits

Aula šŸ’”šŸ•Šļø
60 projects • 226 followers
Electronic Engineering
Contact

Comments

Please log in or sign up to comment.