beta version
Project description
MPU6050 Servocontrol (Raspberry Pi)
A small library to control a servomotor via an mpu6050 accelerometer . This library is based on the i2c connection and it is necessary to install the smbus module first. In fact, it is made only for raspberry pi systems .
Installation
First get smbus
pip install smbus
Then install mpu-servocontrol
pip install mpu-servocontrol
ServoControl class
ServoControl(servo_pin , i2c_port)
i2c_port=1 or 0 (depends of raspberry pi model) and for servo_pin pick a pin that have pwm
Initialize mpu sensor
ServoControl.setup_mpu()
Pick an axis (x/y/z) This method returns data that has been read
ServoControl.read_data_x() / .read_data_y() / .read_data_z()
Start servocontrol As argument put the data read from an axis
ServoControl.start_control(data)
Stop servocontrol
ServoControl.stop_control()
Get started
This is an exemple
import RPi.GPIO as g
from mpu_servocontrol.mainclass import ServoControl #Import
import time
import sys
g.setwarnings(False)
g.setmode(g.BCM)
sc = ServoControl(servo_pin=12 , i2c_port=1) #Make an instance of ServoControl class
sc.setup_mpu() #Initialize mpu6050 accelerometer
try:
while True: #Main loop
data = sc.read_data_y() #Read data from y axis
sc.start_control(data=data) #Start
time.sleep(0.08) #Add a little delay
except KeyboardInterrupt:
sc.stop_control()
g.cleanup()
sys.exit(0) #Press ctrl+c to stop
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpu-servocontrol-0.1.2.tar.gz.
File metadata
- Download URL: mpu-servocontrol-0.1.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2e17f3eecd7f49b6080f044c090cf2b990ea5373a4c2c24f7f33ee62522e93a
|
|
| MD5 |
45e80ddaeff448a5e370c0c926be71b0
|
|
| BLAKE2b-256 |
732d1645f74c6a3f6970579b558379f3310628806f5607dc6e02d6a8783bf94d
|
File details
Details for the file mpu_servocontrol-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mpu_servocontrol-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
594c8ffac7f80ff075fcb9f86af71d67fae5d96c19e986e9c6db731dad6f1fc6
|
|
| MD5 |
2cfe92a2a1b2f8c5c2375e34bcdd872d
|
|
| BLAKE2b-256 |
be19ca79f2cb52da105dc488373c7b7c2806663ebba92f1caa73af9a3cc36766
|