Modified README.md file

This commit is contained in:
Ghassan Yusuf 2025-05-12 10:04:11 +03:00
parent d15488eedf
commit ddeba773a5

View File

@ -53,7 +53,7 @@
### Installation ### Installation
1. Download or clone this repository. 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. 3. Restart the Arduino IDE.
#### File Overview #### File Overview
@ -61,8 +61,6 @@
| File/Folder | Purpose | | File/Folder | Purpose |
|---------------------|-------------------------------------------------------------| |---------------------|-------------------------------------------------------------|
| `I2CMotor.h/.cpp` | Arduino class for controlling a DC motor via I2C | | `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) | | `Master.ino` | Example sketch for I2C master (controller) |
| `Slave.ino` | Example sketch for I2C slave (motor driver) | | `Slave.ino` | Example sketch for I2C slave (motor driver) |
| `keywords.txt` | Arduino IDE syntax highlighting | | `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 #### 1. Include the Library
```cpp ```cpp
#include
#include "I2CMotor.h" #include "I2CMotor.h"
#include "I2CMasterUtils.h"
``` ```
#### 2. Master Example #### 2. Master Example
- Upload `Master.ino` to your Arduino master device. - Upload `Master.ino` to your Arduino master device.
- Use the serial monitor to: - Use the following functions to control and configure your motor:
- Scan for devices: enter `s`
- Change a device address: enter `ch ` (e.g., `ch 55 56`) - `motor.identify();`
- Set motor speed and direction: enter ` ` (e.g., `75 1` for 75% speed, forward) *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 #### 3. Slave Example
@ -103,44 +119,28 @@ The I2CMotor offers exceptional versatility, as it can function as a standalone
### API Overview ### API Overview
**I2CMotor**
- `I2CMotor(uint8_t address = 0x55);` | Function | Description | Parameters | Return Type |
Create a motor object with a given I2C address. |----------|-------------|------------|-------------|
- `void begin();` | `I2CMotor()` | Default constructor. | | |
Initialize I2C communication. | `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 setSpeed(uint8_t speed, uint8_t direction);` | `void begin()` | Initializes I2C communication and scans for the motor controller. | | |
Set motor speed (0100) and direction (0 or 1). | `bool found()` | Checks if a motor controller was found. | | `bool` |
- `void stop();` | `uint8_t address()` | Returns the detected motor controller I2C address. | | `uint8_t` |
Stop the motor. | `String identify()` | Requests and returns the identification string from the motor controller. | | `String` |
- `void setAddress(uint8_t newAddress);` | `void setDeviceName(const char* newname)` | Sets a new name for the motor controller. | `newname` (C-string) | |
Change the I2C address used by this object. | `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) | |
**I2CMasterUtils** | `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. | | |
- `scanI2C(Stream &output = Serial);` | `uint8_t scanForMotorController()` | Scans the I2C bus for a compatible motor controller and returns its address. | | `uint8_t` |
Scan and print all I2C device addresses. | `String queryIdentification(uint8_t addr)` | Requests and returns identification string for a given I2C address. | `addr` (I2C address) | `String` |
- `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).
--- ---
### Notes ### 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. - The slave stores its address in EEPROM and will remember it after reset.
- Modify pin definitions in `Slave.ino` as needed for your hardware. - Modify pin definitions in `Slave.ino` as needed for your hardware.