Metadata-Version: 2.4
Name: MKE-M17-MicroPython
Version: 0.1.2
Summary: A MicroPython driver for the L9110 motor controller over I2C
Author-email: Quy-An <quyan18b@gmail.com>
Project-URL: Homepage, https://github.com/Quy-An/MKE-M17-V2
Project-URL: Documentation, https://github.com/Quy-An/MKE-M17-V2/blob/main/README.md
Classifier: Programming Language :: Python :: Implementation :: MicroPython
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Embedded Systems
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Describe
A MicroPython package to control the L9110 motor driver over I2C.

# Installation


# How to use `mke_m17_micropython` lib

## 1. Initialize the Driver
> Create an `L9110` instance to control your device.

**Parameters:**

* `address` (int): The I2C address of the L9110 chip. Default is `0x40`.
* `bus` (I2C): A pre-initialized `machine.I2C` object (optional). If not provided, a default I2C bus is used.
* `bus_number` (int): The I2C bus number (default is `1`). Ignored if `bus` is provided.

**Example:**

```python
from machine import I2C, Pin
from L9110_I2C import L9110

# Default settings (bus_number=1)
l9110 = L9110()

# Custom I2C bus (e.g., for ESP32)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
l9110 = L9110(address=0x42, bus=i2c)

# With context manager
with L9110(address=0x42, bus=i2c) 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:**
```python
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 as a percentage (0-100).
* `direction` (int): 0 (CW) for clockwise, 1 (CCW) for counterclockwise.

**Returns:**
> `True` on success, `False` on failure.

**Example:** 
```python
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:**
```python
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:**
```python
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:**
```python
l9110.set_range_pulse(600, 2400)
```
