piServoCtl
Overview
This is a servo motor control library for Raspberry Pi. In addition to normal servo motors, continuous rotation servo motors can also be controlled.
It utilizes hardware PWM. Therefore, the servo motor can be moved smoothly. Since you are using pigpio, you need to install pigpio and start pigpiod. To start pigpiod, you need to press the sudo pigpiod command or run pigpiod automatically.
In addition, you can easily make an RC car by using two rotation servo motors. Use the Drive class to set the GPIO pin and servo motor. You can easily implement the steering function by using the steering method.
Installation
sudo pip3 install piServoCtl
Usage
First, start pigpiod (if it is not started). Then import the module. The module name is "piservo". Please note that it is different from the name when it was installed.
sudo pigpiod
Servo
The easiest way is to use Servo(gpio) (where gpio is the GPIO pin number). Use GPIO that supports hardware PWM.
You can control the servo motor with the write method.
Drive
The easiest way is to use Drive(left_gpio, right_gpio) (left_gpio, right_gpio enter the GPIO pin number). Use GPIO that supports hardware PWM. You can swap the left_gpio and right_gpio to flip the front and back of the car.
You can control the car with the steering method.
Demo
Servo
from piservo import Servo
import time
myservo = Servo(12)
myservo.write(180)
time.sleep(3)
myservo.write(0)
time.sleep(3)
myservo.stop()
Drive
from piservo import Drive
import time
mycar = Drive(12, 13)
mycar.steering(50, 45)
time.sleep(1)
mycar.steering(-50, 0)
time.sleep(1)
mycar.stop()
Method
Servo
Servo(gpio, min_value=0, max_value=180, min_pulse=0.5, max_pulse=2.4, frequency=50)
gpio: The gpio pin number to which the servo motor is connected.
min_value: Minimum angle of servo motor (speed if it is a rotation servo motor).
max_value: Maximum angle of servo motor (speed if it is a rotation servo motor).
min_pulse: Minimum control pulse width of servo motor (millisecond).
max_pulse: Maximum control pulse width of servo motor (millisecond).
frequency: PWM frequency of the servo motor.
Create an instance.
Servo.write(value)
value: Servo motor drive angle (speed if it is a rotation servo motor).
Drives the servo motor.
Servo.read()
Read the current value of the servo motor.
Servo.start()
Starts control of the servo motor.
Servo.stop()
Stops control of the servo motor.
Drive
Drive(left_gpio, right_gpio, min_value=-100, max_value=100, min_pulse=0.5, max_pulse=2.4, frequency=50)
left_gpio: GPIO pin number to which the left servo motor is connected.
right_gpio: GPIO pin number to which the right servo motor is connected.
min_value: Minimum speed of servo motor.
max_value: Maximum speed of servo motor.
min_pulse: Minimum control pulse width of servo motor (millisecond).
max_pulse: Maximum control pulse width of servo motor (millisecond).
frequency: PWM frequency of the servo motor.
Create an instance.
Drive.steering(speed=50, direction=0)
speed: Speed of movement.
direction: Direction of movement.
It moves in the specified direction at the specified speed.
Drive.stop()
Stop moving.
Drive.start()
Start control.
Drive.set_speed(speed)
speed: Speed of movement.
Moves in the previously specified direction and at the specified speed.
Drive.set_direction(direction)
direction: Direction of movement.
Moves in the specified direction at the previously specified speed.
Drive.get_speed()
Get the current speed.
Drive.get_direction()
Gets the current direction.
License
MIT
Metadata
Release files for piServoCtl 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| piServoCtl-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
| piServoCtl-1.1.0-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 9.2 kB
Release files / piServoCtl-1.1.0-py3-none-any.whl
| Download URL | piServoCtl-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
437acd4b597f6e022eb67dbe9b481b1ca6a7abd01bf0bd47be6bc0b02b2ca5d3
|
|
BLAKE2b-256 checksum How to use checksums |
a3f73973564b3302de59dc3403168ac3944af16a5f650c9aadd9f09286748b98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/2.7.16
|
Release files / piServoCtl-1.1.0-py2-none-any.whl
| Download URL | piServoCtl-1.1.0-py2-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
d189dd1cf05ad5f80ee9bcea9ff9f28e4cd096384769bd1128092fc346a35bc4
|
|
BLAKE2b-256 checksum How to use checksums |
de8cf1eed5081ee32614c958cbb416edcd887a4c256f7bf11adde1e88cc6bf77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/2.7.16
|