Update README.md
This commit is contained in:
parent
7cc0a9c558
commit
da59ffb827
101
README.md
101
README.md
@ -1,20 +1,91 @@
|
|||||||
# Relay8I2C Library
|
# I2C Communication Library
|
||||||
**By Fatima @ FABLAB Bahrain**
|
|
||||||
|
|
||||||

|
This library provides functionalities for I2C communication, specifically designed for controlling devices that support the I2C protocol. It includes utilities for scanning I2C buses, changing slave addresses, and handling commands.
|
||||||
|
|
||||||
Control 8-relay modules via I2C with dynamic address configuration. Designed for ESP8266 and Arduino platforms.
|
## Table of Contents
|
||||||
|
|
||||||
## Features
|
1. [Overview](#overview)
|
||||||
- I2C communication protocol
|
2. [Files](#files)
|
||||||
- Dynamic slave address configuration
|
3. [Class: I2CMasterUtils](#class-i2cmastertools)
|
||||||
- Master controller with serial interface
|
4. [Class: I2CRelay](#class-i2crelay)
|
||||||
- Active LOW relay support
|
5. [Usage Example](#usage-example)
|
||||||
- EEPROM storage for persistent addressing
|
|
||||||
|
|
||||||
## Installation
|
## Overview
|
||||||
1. Download the library ZIP
|
|
||||||
2. Arduino IDE: Sketch > Include Library > Add .ZIP Library
|
|
||||||
3. Select the downloaded ZIP file
|
|
||||||
|
|
||||||
## Usage
|
The library provides functionalities for I2C communication, specifically designed for controlling devices that support the I2C protocol. It includes utilities for scanning I2C buses, changing slave addresses, and handling commands.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
The library is composed of several files, each with a specific role:
|
||||||
|
|
||||||
|
1. **I2CMasterUtils.h** [3]
|
||||||
|
- This header file defines the `I2CMasterUtils` class which contains static methods for I2C operations such as scanning for devices and changing slave addresses.
|
||||||
|
|
||||||
|
2. **I2CMasterUtils.cpp** [2]
|
||||||
|
- Contains the implementation of methods defined in `I2CMasterUtils.h`.
|
||||||
|
|
||||||
|
3. **I2CRelay.h** [5]
|
||||||
|
- Defines the `I2CRelay` class, which extends the functionality to control relays over I2C.
|
||||||
|
|
||||||
|
4. **I2CRelay.cpp** [4]
|
||||||
|
- Contains the implementation of methods for the `I2CRelay` class.
|
||||||
|
|
||||||
|
## Class: I2CMasterUtils
|
||||||
|
|
||||||
|
### Static Methods
|
||||||
|
|
||||||
|
- **scanI2C(Stream &output = Serial)**
|
||||||
|
- Scans the I2C bus for connected devices and prints their addresses.
|
||||||
|
|
||||||
|
- **changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output = Serial)**
|
||||||
|
- Sends a command to change the slave address of a device.
|
||||||
|
|
||||||
|
- **parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr)**
|
||||||
|
- Parses an input string to extract the old and new slave addresses from a "ch" command.
|
||||||
|
|
||||||
|
## Class: I2CRelay
|
||||||
|
|
||||||
|
### Methods
|
||||||
|
|
||||||
|
- **I2CRelay(uint8_t slaveAddress)**
|
||||||
|
- Constructor that initializes the `I2CRelay` object with the given slave address.
|
||||||
|
|
||||||
|
- **begin()**
|
||||||
|
- Initializes the I2C bus for communication.
|
||||||
|
|
||||||
|
- **setRelay(uint8_t relayIndex, bool state)**
|
||||||
|
- Sets the state of a specific relay on the slave device.
|
||||||
|
|
||||||
|
- **scanDevices(uint8_t* foundAddresses, uint8_t maxDevices)**
|
||||||
|
- Scans the I2C bus for connected devices and returns their addresses up to `maxDevices`.
|
||||||
|
|
||||||
|
- **setAddress(uint8_t newAddress)**
|
||||||
|
- Changes the address of the relay slave.
|
||||||
|
|
||||||
|
- **handleI2CCommand()**
|
||||||
|
- Handles incoming I2C commands.
|
||||||
|
|
||||||
|
## Usage Example
|
||||||
|
|
||||||
|
To use this library, you would typically include the necessary files and create instances of `I2CMasterUtils` and `I2CRelay`. Here’s a simple example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "I2CMasterUtils.h"
|
||||||
|
#include "I2CRelay.h"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
I2CMasterUtils::scanI2C();
|
||||||
|
|
||||||
|
uint8_t newAddress = 0x54;
|
||||||
|
uint8_t oldAddress = CMD_CHANGE_ADDR; // Assuming CMD_CHANGE_ADDR is defined in I2CCommands.h
|
||||||
|
I2CMasterUtils::changeSlaveAddress(oldAddress, newAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Example usage of I2CRelay
|
||||||
|
I2CRelay relay(0x54); // Use the newly assigned address
|
||||||
|
relay.begin();
|
||||||
|
relay.setRelay(1, HIGH); // Set relay 1 to ON
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user