diff --git a/README.md b/README.md index f984e7e..022a38a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ ### Installation 1. Download or clone this repository. -2. Copy the `I2CMotor`, `I2CMasterUtils`, and related library folders to your Arduino `libraries` directory. +2. Copy the `I2CMotor`, and related library folders to your Arduino `libraries` directory. 3. Restart the Arduino IDE. #### File Overview @@ -61,8 +61,6 @@ | File/Folder | Purpose | |---------------------|-------------------------------------------------------------| | `I2CMotor.h/.cpp` | Arduino class for controlling a DC motor via I2C | -| `I2CMasterUtils.h/.cpp` | Utility functions for scanning I2C bus and changing addresses | -| `I2CCommands.h` | I2C command definitions (e.g., address change command code) | | `Master.ino` | Example sketch for I2C master (controller) | | `Slave.ino` | Example sketch for I2C slave (motor driver) | | `keywords.txt` | Arduino IDE syntax highlighting | @@ -81,18 +79,36 @@ The I2CMotor offers exceptional versatility, as it can function as a standalone #### 1. Include the Library ```cpp -#include #include "I2CMotor.h" -#include "I2CMasterUtils.h" ``` #### 2. Master Example + + - Upload `Master.ino` to your Arduino master device. -- Use the serial monitor to: - - Scan for devices: enter `s` - - Change a device address: enter `ch ` (e.g., `ch 55 56`) - - Set motor speed and direction: enter ` ` (e.g., `75 1` for 75% speed, forward) +- Use the following functions to control and configure your motor: + + - `motor.identify();` + *Scan and identify the connected motor.* + + - `motor.setDeviceName("Name");` + *Assign a new name to the motor.* + + - `motor.setMinMax(Min, Max);` + *Set the minimum and maximum speed limits for the motor.* + + - `motor.setMotorDirection(MotorNum, Direction);` + *Set the rotation direction for a specific motor. + - `MotorNum`: The number of the motor you want to control. + - `Direction`: Use `1` for clockwise, `2` for counter-clockwise.* + + - `motor.setMotorSpeed(MotorNum, Speed);` + *Set the speed for a specific motor. + - `MotorNum`: The number of the motor you want to control. + - `Speed`: Desired speed value.* + +--- #### 3. Slave Example @@ -103,44 +119,28 @@ The I2CMotor offers exceptional versatility, as it can function as a standalone ### API Overview -**I2CMotor** -- `I2CMotor(uint8_t address = 0x55);` - Create a motor object with a given I2C address. -- `void begin();` - Initialize I2C communication. -- `void setSpeed(uint8_t speed, uint8_t direction);` - Set motor speed (0–100) and direction (0 or 1). -- `void stop();` - Stop the motor. -- `void setAddress(uint8_t newAddress);` - Change the I2C address used by this object. - -**I2CMasterUtils** - -- `scanI2C(Stream &output = Serial);` - Scan and print all I2C device addresses. -- `changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output = Serial);` - Send command to change a device's I2C address. -- `parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr);` - Parse address change command from serial input. - ---- - -### Example Serial Commands - -- `s` - Scan I2C bus for devices. -- `ch 55 56` - Change device address from `0x55` to `0x56`. -- `75 1` - Set motor speed to 75%, direction to forward (1). +| Function | Description | Parameters | Return Type | +|----------|-------------|------------|-------------| +| `I2CMotor()` | Default constructor. | – | – | +| `I2CMotor(uint8_t sda, uint8_t scl, uint32_t freq)` | Constructor with I2C pin and frequency configuration. | `sda` (I2C SDA pin), `scl` (I2C SCL pin), `freq` (I2C frequency) | – | +| `void begin()` | Initializes I2C communication and scans for the motor controller. | – | – | +| `bool found()` | Checks if a motor controller was found. | – | `bool` | +| `uint8_t address()` | Returns the detected motor controller I2C address. | – | `uint8_t` | +| `String identify()` | Requests and returns the identification string from the motor controller. | – | `String` | +| `void setDeviceName(const char* newname)` | Sets a new name for the motor controller. | `newname` (C-string) | – | +| `void setMinMax(uint8_t min_pwm, uint8_t max_pwm)` | Sets minimum and maximum PWM (speed) values. | `min_pwm`, `max_pwm` | – | +| `void setMotorDirection(uint8_t motor, uint8_t dir)` | Sets direction for a specified motor. | `motor` (motor number), `dir` (1: CW, 2: CCW) | – | +| `void setMotorSpeed(uint8_t motor, uint8_t speed_percent)` | Sets speed (as percentage) for a specified motor. | `motor` (motor number), `speed_percent` | – | +| `void emergencyStop()` | Sends an emergency stop command to the motor controller. | – | – | +| `uint8_t scanForMotorController()` | Scans the I2C bus for a compatible motor controller and returns its address. | – | `uint8_t` | +| `String queryIdentification(uint8_t addr)` | Requests and returns identification string for a given I2C address. | `addr` (I2C address) | `String` | --- ### Notes -- The default I2C address is `0x55`. You can change it using the provided command. +- The default I2C address is `0x08`. You can change it using the provided command. - The slave stores its address in EEPROM and will remember it after reset. - Modify pin definitions in `Slave.ino` as needed for your hardware.