├── library.properties ├── .gitignore ├── keywords.txt ├── LICENSE ├── README.md ├── src ├── TCA9548A.h └── TCA9548A.cpp └── example └── simpleUsage └── simpleUsage.ino /library.properties: -------------------------------------------------------------------------------- 1 | name=Grove - 8 Channel I2C Hub 2 | version=1.0.0 3 | author=Seeed Studio 4 | maintainer=Seeed Studio 5 | sentence=Arduino library to control Grove - 8 Channel I2C Hub 6 | paragraph=Arduino library to control Grove - 8 Channel I2C Hub 7 | category=Display 8 | url= 9 | architectures=* -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | 3 | # Prerequisites 4 | *.d 5 | 6 | # Compiled Object files 7 | *.slo 8 | *.lo 9 | *.o 10 | *.obj 11 | 12 | # Precompiled Headers 13 | *.gch 14 | *.pch 15 | 16 | # Compiled Dynamic libraries 17 | *.so 18 | *.dylib 19 | *.dll 20 | 21 | # Fortran module files 22 | *.mod 23 | *.smod 24 | 25 | # Compiled Static libraries 26 | *.lai 27 | *.la 28 | *.a 29 | *.lib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | 2 | ####################################### 3 | # Syntax Coloring Map For 4 | ####################################### 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | 10 | TCA9548A KEYWORD1 11 | 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | TCA KEYWORD2 17 | openAll KEYWORD2 18 | closeAll KEYWORD2 19 | openChannel KEYWORD2 20 | closeChannel KEYWORD2 21 | 22 | TCA_CHANNEL_0 KEYWORD2 23 | TCA_CHANNEL_1 KEYWORD2 24 | TCA_CHANNEL_2 KEYWORD2 25 | TCA_CHANNEL_3 KEYWORD2 26 | TCA_CHANNEL_4 KEYWORD2 27 | TCA_CHANNEL_5 KEYWORD2 28 | TCA_CHANNEL_6 KEYWORD2 29 | TCA_CHANNEL_7 KEYWORD2 30 | 31 | 32 | 33 | ####################################### 34 | # Constants (LITERAL1) 35 | ####################################### -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Seeed Studio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Grove_8 Channel I2C Hub 2 | ===================================== 3 | 4 | ## features 5 | 6 | Grove_8 Channel I2C Hub is used to control the state of I2C channel. 7 | 8 | ## Usage 9 | 1.Git clone this resp to your Arduino IDE's libraries directory. 10 | 2.Run the demo "TCA9548A_Example" on examples directory. 11 | 12 | ---- 13 | 14 | This software is written by Wayen Weng for seeed studio and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
15 | 16 | Contributing to this software is warmly welcomed. You can do this basically by
17 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
18 | for operating guide). Adding change log and your contact into file header is encouraged.
19 | Thanks for your contribution. 20 | 21 | Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
22 | Benefiting from local manufacture power and convenient global logistic system,
23 | we integrate resources to serve new era of innovation. Seeed also works with
24 | global distributors and partners to push open hardware movement.
25 | 26 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/grove-human-presence-sensor)](https://github.com/igrigorik/ga-beacon) 27 | 28 | -------------------------------------------------------------------------------- /src/TCA9548A.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Author: Hongtai Liu (lht856@foxmail.com) 5 | * 6 | * Copyright (C) 2019 Seeed Technology Co.,Ltd. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef SEEED_TCA9548A_H 29 | #define SEEED_TCA9548A_H 30 | 31 | //#define SOFTWAREWIRE 32 | 33 | #if ARDUINO >= 100 34 | #include "Arduino.h" 35 | #else 36 | #include "WProgram.h" 37 | #endif 38 | 39 | #ifdef SOFTWAREWIRE 40 | #include 41 | #else 42 | #include 43 | #endif 44 | 45 | /************************************************************************** 46 | I2C ADDRESS/BITS 47 | **************************************************************************/ 48 | #define TCA9548_DEFAULT_ADDRESS 0x70 49 | 50 | /************************************************************************** 51 | Channel STATUS 52 | ------------------------------------------------------- 53 | ┆ B7 ┆ B6 ┆ B5 ┆ B4 ┆ B3 ┆ B2 ┆ B1 ┆ B0 ┆ | 54 | ┆-------------------------------------------------------┆ 55 | ┆ ch7 ┆ ch6 ┆ ch5 ┆ ch4 ┆ ch3 ┆ ch2 ┆ ch1 ┆ ch0 ┆ 56 | ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ 57 | **************************************************************************/ 58 | #define TCA_CHANNEL_0 0x1 59 | #define TCA_CHANNEL_1 0x2 60 | #define TCA_CHANNEL_2 0x4 61 | #define TCA_CHANNEL_3 0x8 62 | #define TCA_CHANNEL_4 0x10 63 | #define TCA_CHANNEL_5 0x20 64 | #define TCA_CHANNEL_6 0x40 65 | #define TCA_CHANNEL_7 0x80 66 | 67 | template 68 | class TCA9548A 69 | { 70 | public: 71 | TCA9548A(); 72 | ~TCA9548A(); 73 | 74 | void begin(T &wire = Wire, uint8_t address = TCA9548_DEFAULT_ADDRESS); 75 | 76 | void openChannel(uint8_t channel); 77 | void closeChannel(uint8_t channel); 78 | inline uint8_t readStatus(){return read();}; 79 | 80 | void closeAll(); 81 | void openAll(); 82 | 83 | private: 84 | 85 | T * _wire; 86 | uint8_t _address; 87 | uint8_t _channels; // status of channel 88 | 89 | void write(uint8_t val); 90 | uint8_t read(); 91 | 92 | 93 | }; 94 | 95 | #endif /*SEEED_TCA9548A_H*/ -------------------------------------------------------------------------------- /src/TCA9548A.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * The MIT License (MIT) 4 | * 5 | * Author: Hongtai Liu (lht856@foxmail.com) 6 | * 7 | * Copyright (C) 2019 Seeed Technology Co.,Ltd. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | #include "TCA9548A.h" 29 | 30 | #ifdef SOFTWAREWIRE 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | template 37 | TCA9548A::TCA9548A(void) 38 | { 39 | 40 | } 41 | 42 | template 43 | TCA9548A::~TCA9548A(void) 44 | { 45 | 46 | } 47 | 48 | template 49 | void TCA9548A::begin(T &wire, uint8_t address) 50 | { 51 | this->_address = address; 52 | this->_wire = &wire; 53 | this->_channels = 0x00; 54 | this->_wire->begin(); 55 | 56 | this->closeAll(); // defalut close all channel; 57 | } 58 | 59 | template 60 | void TCA9548A::openChannel(uint8_t channel) 61 | { 62 | this->_channels |= channel; 63 | 64 | write(this->_channels); 65 | } 66 | 67 | template 68 | void TCA9548A::closeChannel(uint8_t channel) 69 | { 70 | this->_channels ^= channel; 71 | 72 | write(this->_channels); 73 | } 74 | 75 | template 76 | void TCA9548A::openAll() 77 | { 78 | this->_channels = 0xFF; 79 | write(this->_channels); 80 | } 81 | 82 | template 83 | void TCA9548A::closeAll() 84 | { 85 | this->_channels = 0x00; 86 | write(this->_channels); 87 | } 88 | 89 | 90 | template 91 | void TCA9548A::write(uint8_t value) 92 | { 93 | this->_wire->beginTransmission(this->_address); 94 | this->_wire->write(value); 95 | this->_wire->endTransmission(true); 96 | } 97 | 98 | template 99 | uint8_t TCA9548A::read() 100 | { 101 | uint8_t status = 0; 102 | this->_wire->requestFrom((uint16_t)this->_address, (uint8_t)1, (uint8_t)1); 103 | 104 | if(!this->_wire->available()) 105 | return 255; 106 | 107 | status = this->_wire->read(); 108 | 109 | this->_channels = status; 110 | return status; 111 | } 112 | 113 | #ifdef SOFTWAREWIRE 114 | template class TCA9548A; 115 | #else 116 | template class TCA9548A; 117 | #endif -------------------------------------------------------------------------------- /example/simpleUsage/simpleUsage.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Author: Hongtai Liu (lht856@foxmail.com) 5 | * 6 | * Descript: This Usage show the basic use of TCA9548A. 7 | * 8 | * Copyright (C) 2019 Seeed Technology Co.,Ltd. 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | #include "TCA9548A.h" 30 | 31 | // if you use the software I2C to drive, you can uncommnet the define SOFTWAREWIRE which in TCA9548A.h. 32 | #ifdef SOFTWAREWIRE 33 | #include 34 | SoftwareWire myWIRE(3, 2); 35 | TCA9548A TCA; 36 | #define WIRE myWIRE 37 | #else 38 | #include 39 | TCA9548A TCA; 40 | #define WIRE Wire 41 | #endif 42 | 43 | #define SERIAL Serial 44 | 45 | void setup() 46 | { 47 | SERIAL.begin(115200); 48 | while(!SERIAL){}; 49 | 50 | //WIRE.begin(); 51 | TCA.begin(WIRE); 52 | //defaut all channel was closed 53 | //TCA.openAll(); 54 | //TCA.closeAll(); 55 | 56 | // Select the channels you want to open. You can open as many channels as you want 57 | TCA.openChannel(TCA_CHANNEL_0); //TCA.closeChannel(TCA_CHANNEL_0); 58 | //TCA.openChannel(TCA_CHANNEL_1); //TCA.closeChannel(TCA_CHANNEL_1); 59 | //TCA.openChannel(TCA_CHANNEL_2); //TCA.closeChannel(TCA_CHANNEL_2); 60 | //TCA.openChannel(TCA_CHANNEL_3); //TCA.closeChannel(TCA_CHANNEL_3); 61 | //TCA.openChannel(TCA_CHANNEL_4); //TCA.closeChannel(TCA_CHANNEL_4); 62 | //TCA.openChannel(TCA_CHANNEL_5); //TCA.closeChannel(TCA_CHANNEL_5); 63 | //TCA.openChannel(TCA_CHANNEL_6); //TCA.closeChannel(TCA_CHANNEL_6); 64 | //TCA.openChannel(TCA_CHANNEL_7); //TCA.closeChannel(TCA_CHANNEL_7); 65 | 66 | } 67 | 68 | void loop() 69 | { 70 | 71 | uint8_t error, i2cAddress, devCount, unCount; 72 | 73 | SERIAL.println("Scanning..."); 74 | 75 | devCount = 0; 76 | unCount = 0; 77 | for(i2cAddress = 1; i2cAddress < 127; i2cAddress++ ) 78 | { 79 | WIRE.beginTransmission(i2cAddress); 80 | error = WIRE.endTransmission(); 81 | 82 | if (error == 0) 83 | { 84 | SERIAL.print("I2C device found at 0x"); 85 | if (i2cAddress<16) SERIAL.print("0"); 86 | SERIAL.println(i2cAddress,HEX); 87 | devCount++; 88 | } 89 | else if (error==4) 90 | { 91 | SERIAL.print("Unknow error at 0x"); 92 | if (i2cAddress<16) SERIAL.print("0"); 93 | SERIAL.println(i2cAddress,HEX); 94 | unCount++; 95 | } 96 | } 97 | 98 | if (devCount + unCount == 0) 99 | SERIAL.println("No I2C devices found\n"); 100 | else { 101 | SERIAL.print(devCount); 102 | SERIAL.print(" device(s) found"); 103 | if (unCount > 0) { 104 | SERIAL.print(", and unknown error in "); 105 | SERIAL.print(unCount); 106 | SERIAL.print(" address"); 107 | } 108 | SERIAL.println(); 109 | } 110 | SERIAL.println(); 111 | delay(1000); 112 | } --------------------------------------------------------------------------------