# Empowering Innovation **Unlocking Unlimited Possibilities with Our Modular IoT Devices** At **FABLAB Bahrain**, we're revolutionizing the world of IoT devices with our cutting-edge, ESP32C3-based modules. Not only do they come pre-programmed as I2C slave devices, ready to be controlled via a simple interface, but they're also designed to be fully programmable and reconfigurable by end-users themselves. Our comprehensive library provides an intuitive way for developers to customize and fine-tune their products, whether it's changing addresses or integrating BLE or WiFi connectivity. But that's not all - we've also made it possible for users to upload their own firmware, empowering them to transform our modules into anything they can imagine. From smart home automation to industrial control systems, our devices are the perfect building blocks for your next innovation project. With our modular design and open-source approach, you'll have complete freedom to shape your IoT vision # I2C Communication Library **I2CRelay** is an 8-relay module built around the ESP32-C3 Super Mini, featuring an I2C interface that allows it to be controlled by another MCU, enabling easy integration into complex control systems. Additionally, when paired with an ESP32-C3-based controller, it can leverage Wi-Fi and Bluetooth LE connectivity, expanding control options beyond wired I2C communication for wireless operation and enhanced flexibility in IoT and robotics applications. This combination of compact size, low power consumption, and versatile communication protocols makes the module indispensable for remote and automated control of multiple devices, offering scalable and reliable switching solutions for smart homes, industrial automation, and advanced robotics. ## Table of Contents 1. [Technical Drawings](#technical_drawings) 2. [Features](#Features) 3. [Hardware Components Used](#hardware_components_used) 4. [Installation](#installation) 5. [Versatility](#versatility) 6. [Usage](#usage) 7. [API Overview](#api-overview) 8. [Example Serial Commands](#example-serial-commands) 9. [Notes](#notes) 10. [Credits](#credits) 11. [License](#license) 12. [Project Image](#project-image) --- ### Technical Drawings --- ### Features ### Key Features of the 8-Relay Module with ESP32-C3 Super Mini - **8-Channel Relay Control:** Enables switching of up to 8 high-power devices independently. - **ESP32-C3 Super Mini Integration:** Compact, powerful RISC-V processor with built-in Wi-Fi and Bluetooth 5.0 for versatile connectivity. - **I2C Communication Interface:** Allows easy control from another MCU with minimal wiring and reliable data transfer. - **Wireless Control Capability:** Supports Wi-Fi and Bluetooth when paired with an ESP32-C3-based controller, enabling remote and flexible device management. - **Low Power Consumption:** Efficient power usage suitable for battery-powered and IoT applications. - **Compact and Lightweight Design:** Ideal for space-constrained projects and embedded systems. - **High Reliability and Safety:** Optocoupler isolation and built-in protection circuits to safeguard both the relay module and connected devices. - **Wide Application Range:** Perfect for home automation, industrial control, robotics, and smart IoT solutions. --- ### Hardware Components Used - 8-Channel Relay Module. - Esp32C3 Super Mini. - Flywheel. --- ### Installation 1. Download or clone this repository. 2. Copy the `I2CRelay`, `I2CMasterUtils`, and related library folders to your Arduino `libraries` directory. 3. Restart the Arduino IDE. #### 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. --- ### Versatility The I2CMotor offers exceptional versatility, as it can function as a standalone device and can be adapted to be USB-controlled instead of relying solely on I2C communication. This flexibility allows users to easily integrate the motor into a wide range of projects and control environments. Furthermore, the motor’s firmware can be reprogrammed to support Wi-Fi and Bluetooth connectivity, enabling wireless control and making it ideal for modern applications in robotics, automation, and IoT. This adaptability ensures that the I2CMotor can meet diverse requirements and evolve with your project’s needs. --- ### API Overview - **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. #### 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 }