Skip to main content

A Python/MicroPython driver for the L9110 motor controller over I2C

Project description

Describe

A Python package to control the L9110 motor driver over I2C using smbus2.

Installation

  1. Create virtual environment: python3 -m venv your_env
  2. Activate virtual environment: source your_env/bin/activate
  3. install package: pip install MKE-M17

⚠️ Warning

  • Check hardware connection: Ensure your device is correctly connected to the I2C bus (SDA, SCL, VCC, GND) before using the package.
  • Verify I2C address: Use the command i2cdetect -y 1 on a Raspberry Pi to check the I2C address of the L9110 device.
  • Resource management: The package supports context manager (with statement) to automatically close the I2C bus after use, preventing resource leaks. It is recommended to use this syntax whenever possible.

How to use MKE_M17 lib

1. Initialize the Driver

Create an L9110 instance to control your device.

Parameters:

  • i2c_address (int): The I2C address of the L9110 chip. Default is 0x40.
  • i2c_bus_number (int): The number of the I2C bus to use. Default is 1.

Example:

⚠️ Warning: Run in virtual environment (your_env/bin/python3.11)

from MKE_M17 import L9110

# Default settings
l9110 = L9110()

# Custom address and bus
l9110 = L9110(address=0x42, bus_number=1)

# With context manager (recommended)
with L9110(address=0x42) as l9110:
    pass

2. Control Servos

Use control_servo() to set servo angles.

Args:

  • servo_id (int): 1 (S1) or 2 (S2).
  • degree (int): Angle in degrees (default: 0-180).

Returns:

True on success, False on failure.

Example:

l9110.control_servo(1, 150)  # Servo 1 to 150°
l9110.control_servo(2, 90)   # Servo 2 to 90°

3. Control DC Motors

Use control_motor() to set motor speed and direction.

Args:

  • motor_id (int): 0 (MA) or 1 (MB).
  • percent (float): Speed (0-100).
  • direction (int): 0 (CW) or 1 (CCW).

Returns:

True on success, False on failure.

Example:

l9110.control_motor(0, 50, 0)  # Motor A, 50%, clockwise
l9110.control_motor(1, 70, 1)  # Motor B, 70%, counterclockwise

4. Change I2C Address

Update the device’s I2C address with set_address().

Args:

  • new_address (byte): New address (0x40-0x44).

Returns:

True on success, False on failure.

Example:

l9110.set_address(0x42)
# Output: "Set address successful. New address: 0x42"

5. Customize Servo Range

Set new range degree.

using set_range_degree(min_degree, max_degree) to set new range degree for servo motor

Args:

  • min_degree(int): (0-359).
  • max_degree(int): (1-360).

Example:

l9110.set_range_degree(0, 270)

Set new range pulse.

using set_range_pulse(min_pulse, max_pulse) to set new range degree for servo motor

Args:

  • min_pulse(int): (0-2814).
  • max_pulse(int): (1-2815).

Example:

l9110.set_range_pulse(600, 2400)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mke_m17_v2-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mke_m17_v2-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file mke_m17_v2-0.1.1.tar.gz.

File metadata

  • Download URL: mke_m17_v2-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mke_m17_v2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c61cf30f511e63adb5198667467a81ac9c003b2196f1f94bfa769647fc37dbb1
MD5 c8359fa6b1ecf340838088b4260dab6b
BLAKE2b-256 25d3afc592b792595634493ac951a6cecb3e9960d127bf8f515f0d5ea194139f

See more details on using hashes here.

File details

Details for the file mke_m17_v2-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mke_m17_v2-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mke_m17_v2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c8bc5fae5d6a0cc125f1727b4100aae924af44586e6026d3389881e1c1929a27
MD5 e6cd401fad8e245c608cdc3a43b5a35f
BLAKE2b-256 e0d50a122a67a6b869e6a0778851e4ad9c01e5950dd4a5166efff6c9e9a7efc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page