diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b70077e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 FABLAB BH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..57d2a52 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# FABLAB_BH_Library + +**Author:** Fatima Idrees +**Maintainer:** FABLAB BH +**License:** MIT + +## Description + +FABLAB_BH_Library is an Arduino library designed to [briefly describe what the library does, e.g., "control custom hardware developed at FABLAB BH"]. + +## Installation + +1. Download the latest release from [GitHub/website]. +2. In the Arduino IDE, go to **Sketch > Include Library > Add .ZIP Library...** and select the downloaded file. + +## Usage + diff --git a/Master/Master.ino b/examples/Master/Master.ino similarity index 100% rename from Master/Master.ino rename to examples/Master/Master.ino diff --git a/Slave/Slave.ino b/examples/Slave/Slave.ino similarity index 100% rename from Slave/Slave.ino rename to examples/Slave/Slave.ino diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..ac9c659 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=FABLAB StripLED +version=1.0.0 +author=Fatima +maintainer=FABLAB BH +sentence=Arduino library for FABLAB BH projects. +paragraph=This library provides useful functions for FABLAB BH hardware. +category= Communication +url=https://github.com/fablabbh/FABLAB_BH_Library +architectures=* diff --git a/src/I2CCommands.h b/src/I2CCommands.h new file mode 100644 index 0000000..2ae5463 --- /dev/null +++ b/src/I2CCommands.h @@ -0,0 +1,6 @@ +#ifndef I2C_COMMANDS_H +#define I2C_COMMANDS_H + +#define CMD_CHANGE_ADDR 0xAA // Use the same value as in your slave + +#endif diff --git a/src/I2CMasterUtils.cpp b/src/I2CMasterUtils.cpp new file mode 100644 index 0000000..b8b04c4 --- /dev/null +++ b/src/I2CMasterUtils.cpp @@ -0,0 +1,36 @@ +#include "I2CMasterUtils.h" +#include "I2CCommands.h" + +void I2CMasterUtils::scanI2C(Stream &output) { + output.println("Scanning for I2C devices..."); + for (uint8_t addr = 1; addr < 127; addr++) { + Wire.beginTransmission(addr); + if (Wire.endTransmission() == 0) { + output.print("Found device at 0x"); + output.println(addr, HEX); + } + } +} + +void I2CMasterUtils::changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output) { + Wire.beginTransmission(oldAddr); + Wire.write(CMD_CHANGE_ADDR); // Use the command code from I2CCommands.h + Wire.write(newAddr); + Wire.endTransmission(); + output.print("Sent address change command to 0x"); + output.print(oldAddr, HEX); + output.print(" -> 0x"); + output.println(newAddr, HEX); +} + +bool I2CMasterUtils::parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr) { + if (!input.startsWith("ch")) return false; + int o, n; + int matched = sscanf(input.c_str(), "ch %x %x", &o, &n); + if (matched == 2) { + oldAddr = (uint8_t)o; + newAddr = (uint8_t)n; + return true; + } + return false; +} diff --git a/src/I2CMasterUtils.h b/src/I2CMasterUtils.h new file mode 100644 index 0000000..5be05b9 --- /dev/null +++ b/src/I2CMasterUtils.h @@ -0,0 +1,14 @@ +#ifndef I2CMASTERUTILS_H +#define I2CMASTERUTILS_H + +#include +#include + +class I2CMasterUtils { +public: + static void scanI2C(Stream &output = Serial); + static void changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output = Serial); + static bool parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr); +}; + +#endif