sam0314
Posts: 4
Joined: Wed Apr 11, 2018 10:31 pm

Servo hat interface

Wed Apr 11, 2018 10:55 pm

I have an adafruit servo hat and have it working but I would like an interface of sorts, something that allows me to define and zero connected servos. I'm not that familiar with the terminal and got forced into a school project with others who wont do anything.

pcmanbob
Posts: 3592
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Servo hat interface

Sat Apr 14, 2018 3:23 pm

Hi.

I doubt there is a ready built interface available , that is something you would normally build for yourself to provide what ever display / options you require.

if you tell use exactly which hat you have we may be able to guide to to something helpful.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

sam0314
Posts: 4
Joined: Wed Apr 11, 2018 10:31 pm

Re: Servo hat interface

Mon Apr 16, 2018 1:44 am

Something that allows me to ID which Ports have servos and what type (continuous, 270) as well set the pulse rate.
The ability to set patterns would be nice but it's not necessary.

pcmanbob
Posts: 3592
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Servo hat interface

Mon Apr 16, 2018 9:32 am

sam0314 wrote:
Mon Apr 16, 2018 1:44 am
Something that allows me to ID which Ports have servos and what type (continuous, 270) as well set the pulse rate.
The ability to set patterns would be nice but it's not necessary.
There is no way for a servo controller to be able to identify what type of servo is connected to it, or I suspect if one is even connected, as this information is not available form the servo , data flow in as much as a PWM signal is one way from the driver board to the servo.

but you still have not told us exactly what hardware you have, remember we cant see you pi so we can only help using the information you provide.

so we need to know exactly which hat you have .
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
joan
Posts: 13234
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Servo hat interface

Mon Apr 16, 2018 10:04 am

I doubt you can tell which ports have servos connected or what type of servo is connected to a port. Hobby servos generally do not supply that information, neither will the HAT. Generally a servo is a dumb device accepting power, ground, and a control line. The control line expects pulses at 50 Hz, generally between 1000 and 2000 microseconds long. That pulse width determines the horn angle for a normal servo, and the speed/direction of rotation for a continuous rotation servo.

sam0314
Posts: 4
Joined: Wed Apr 11, 2018 10:31 pm

Re: Servo hat interface

Mon Apr 16, 2018 6:16 pm

Pi 3v: Adafruit 16 x 12 bit servo hat. I want the ability to manually set what servo type is in what port. Again setting patterns would be nice but not necessary.

pcmanbob
Posts: 3592
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Servo hat interface

Tue Apr 17, 2018 6:55 am

Assuming this is the correct hat you have from the information supplied, https://www.adafruit.com/product/2327
there is not user interface provided for it only a python library which allows you to control the servos.

https://learn.adafruit.com/adafruit-16- ... st-the-hat
https://learn.adafruit.com/adafruit-16- ... on-library

So if you want a user interface you are going to have to write your own using the provided python library as the base for controlling your servos.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

scotty101
Posts: 2726
Joined: Fri Jun 08, 2012 6:03 pm

Re: Servo hat interface

Tue Apr 17, 2018 9:26 am

If you want a way to create a text based interface in python, I'd suggest the cmd module as a starting point.

It will allow you to define a set of commands that you can type to set/get/control various things. You would combine this with a servo library to allow users to control the servos by typing specific commands

A simple example below

Code: Select all

import cmd

class ServoControl(cmd.Cmd):
    prompt = '->'
    intro = 'Servo Control System'
    def __init__(self):
        super(ServoControl, self).__init__()
    
    def do_setservoangle(self, args):
        """Set the servo angle
Usage: setservoangle [pin] [angle]
Example: setservoangle 1 15"""
        args = args.split(" ")
        if len(args) == 2:
            pin = args[0]
            angle = args[1]
            print("Set Servo {} to angle {} ".format(pin,angle))
        else:
            print(len(args), " arguments provided")
            print("Incorrect number of arguments\nsetservoangle <pin> <angle>")

    def do_quit(self, args):
        """Quit the program"""
        print("Goodbye!")
        return True

def main():
    sc = ServoControl()
    sc.cmdloop()

if __name__ == '__main__':
    main()
When you run the program it will give the following prompt

Code: Select all

Servo Control System
->
There are a few built it command like help

Code: Select all

Servo Control System
->help

Documented commands (type help <topic>):
========================================
help  quit  setservoangle
"help setservoangle" gives the following

Code: Select all

->help setservoangle
Set the servo angle
Example: setservoangle 1 15
The command to 'set the servo angle' (doesn't actually do anything yet)

Code: Select all

->setservoangle 1 15
Set Servo 1 to angle 15
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

sam0314
Posts: 4
Joined: Wed Apr 11, 2018 10:31 pm

Re: Servo hat interface

Wed Apr 18, 2018 12:46 am

scotty101 wrote:
Tue Apr 17, 2018 9:26 am
If you want a way to create a text based interface in python, I'd suggest the cmd module as a starting point.

It will allow you to define a set of commands that you can type to set/get/control various things. You would combine this with a servo library to allow users to control the servos by typing specific commands
Thank you I'll use this as a basis for my interface.

Return to “Beginners”

Who is online

Users browsing this forum: kmabry2007, youkiddin and 12 guests