The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.
- Home
- Help and Support
- Knowledge Base
- Code & Languages
- C++ Library and Demos
- I2C Switch Library for C++
-
Raspberry Pi
- PCB Header Assembly Jig
- Raspberry Pi GPIO Pins
- Samba Setup on Raspberry Pi
- Set a static IP Address on Raspberry Pi OS Bookworm
- I2C Part 1 - Introducing I2C
- I2C Part 2 - Enabling I2C on the Raspberry Pi
- I2C Part 3 - I2C tools in Linux
- I2C Part 4 - Programming I2C with Python
- SPI and Python on Raspberry Pi OS
- Using Pythonpath with our Python Libraries
- Connecting Development Boards to the Raspberry Pi 400
- General
- Code & Languages
- Raspberry Pi Pico Tutorials
- 1 Wire Pi Tutorials
- ADC Pi Tutorials
- ADC DAC Pi Zero Tutorials
- ADC Differential Pi Tutorials
- Expander Pi Tutorials
-
IO Pi Plus Tutorials
- IO Pi Plus FAQ
- IO Pi Plus Tutorial 1 - The Blinking LED
- IO Pi Plus Tutorial 2 - Push the Button
- IO Pi Plus Tutorial 3 - Introducing Interrupts
- IO Pi Plus Tutorial 4 - More Interrupts
- IO Pi Plus Tutorial - MQTT Reading the Ports
- IO Pi Plus with Raspberry Pi Pico
- IO Pi Plus Tutorial - MQTT Control
- Driving Relays or Higher Loads with the IO Pi Plus
- 16 Channel Opto-Isolated Input Board
- Relay Board for the IO Pi Plus 2.1
- IO Zero 32 Tutorials
- RTC Pi Tutorials
- Serial Pi
- Servo PWM Pi Tutorials
-
Home Assistant
- Using 1 Wire with Home Assistant and the Raspberry Pi OS
- Using I2C Devices on the Raspberry Pi with Home Assistant
- Using the ADC Differential Pi with Home Assistant on the Raspberry Pi
- Using the ADC Pi with Home Assistant on the Raspberry Pi
- Using the IO Pi Plus with Home Assistant on the Raspberry Pi
-
Legacy Products
- ADC DAC Pi (Discontinued)
- ADC Pi (Discontinued)
- Buffer Pi - Legacy Product
- Com Pi (Discontinued)
- Delta-Sigma Pi (Discontinued)
- Expander Pi (Discontinued)
- IO Pi (Discontinued)
- IO Pi Plus 1.0 (Discontinued)
- IO Pi Zero (Discontinued)
- Logic Level Converter (Discontinued)
- RTC Alarm Pi (Discontinued)
- RTC Pi (Discontinued)
- Serial Pi (Discontinued)
- 1 Wire Pi (Discontinued)
- 1 Wire Pi Plus 1.0 (Discontinued)
- Other Supported Platforms
I2C Switch Library for C++
I2C Switch C++ Library Installation and Usage
C++ Library to use with I2C Switch Raspberry Pi development board.
The example C++ files can be found in /ABElectronics_CPP_Libraries/I2CSwitch/demos
Downloading and Installing the library
To download to your Raspberry Pi type in the terminal:
git clone https://github.com/abelectronicsuk/ABElectronics_CPP_Libraries.git
Class:
I2CSwitch(uint8_t address)
The I2CSwitch class provides control over the I2C Switch outputs on the PCA9546A controller. Methods include setting and getting the I2C channel and resetting the switch.
Parameters: address - Initialise with the I2C address for the I2C Switch. Supported I2C addresses are 0x70 to 0x77. The default address is 0x70.
Returns: null
Methods:
switch_channel(uint8_t channel)
Switch on the selected channel and switch off all other channels.
Parameters: channel - 1 to 4.
Returns: null
set_channel_state(uint8_t channel, uint8_t state)
Set the state for the selected channel. All other channels remain in their previous state.
Parameter: channel - 1 to 4
Parameter: state - 1 or 0. 1 = channel on, 0 = channel off.
Returns: null
get_channel_state(uint8_t channel)
Get the state for the selected channel.
Parameters: channel - 1 to 4
Returns: (uint8_t) 1 or 0. 1 = channel on, 0 = channel off.
reset()
Reset the PCA9546A I2C switch. Resetting allows the PCA9546A to recover from a situation in which one of the downstream I2C buses is stuck in a low state. All channels will be set to an off-state.
Returns: null