This page shows how to perform an I2C scan to demonstrate how to use the LTC4316 for both a CircuitPython microcontroller and a Raspberry Pi single board computer running Linux. You'll connect two AHT20 sensors, which have the same I2C address (0x38), to experiment with translating the address for one of them. Remember that you need to restart the LTC4316 every time you adjust the DIP switch.
Then, you'll use the Adafruit_CircuitPython_AHTx0 driver to use two AHT20 sensors, with the help of the LTC4316, to read temperature and humidity data.
You can use the AHT20 driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
Remember that you need to restart the LTC4316 every time you adjust the DIP switch.

CircuitPython Microcontroller Wiring
First wire up the sensors and LTC4316 to your board exactly as follows. The following are the breakouts wired to a Feather RP2040 using the STEMMA connector:
-
Board STEMMA 3V to sensor 1 VIN (red wire)
-
Board STEMMA GND to sensor 1 GND (black wire)
-
Board STEMMA SCL to sensor 1 SCL (yellow wire)
- Board STEMMA SDA to sensor 1 SDA (blue wire)
- Sensor 1 VIN to LTC4316 VIN (red wire)
- Sensor 1 GND to LTC4316 GND (black wire)
- Sensor 1 SCL to LTC4316 SCI (yellow wire)
- Sensor 1 SDA to LTC4316 SDI (blue wire)
- LTC4316 VIN to sensor 2 VIN (red wire)
- LTC4316 GND to sensor 2 GND to (black wire)
- LTC4316 SCO to sensor 2 SCL (yellow wire)
- LTC4316 SDO to sensor 2 SDA (blue wire)
The following are the sensors wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V to sensor 1 VIN (red wire)
-
Board GND to sensor 1 GND (black wire)
-
Board SCL to sensor 1 SCL (yellow wire)
- Board SDA to sensor 1 SDA (blue wire)
- Sensor 1 VIN to LTC4316 VIN (red wire)
- Sensor 1 GND to LTC4316 GND (black wire)
- Sensor 1 SCL to LTC4316 SCI (yellow wire)
- Sensor 1 SDA to LTC4316 SDI (blue wire)
- LTC4316 VIN to sensor 2 VIN (red wire)
- LTC4316 GND to sensor 2 GND to (black wire)
- LTC4316 SCO to sensor 2 SCL (yellow wire)
- LTC4316 SDO to sensor 2 SDA (blue wire)
CircuitPython I2C Scan
Before running the AHT20 temperature and humidity example, you'll run an I2C scan to check the translated I2C address for the second AHT20 sensor. Update code.py with this script. Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: MIT # pylint: disable=broad-except, eval-used, unused-import """CircuitPython I2C Device Address Scan""" import time import board import busio # List of potential I2C busses ALL_I2C = ("board.I2C()", "board.STEMMA_I2C()", "busio.I2C(board.GP1, board.GP0)") # Determine which busses are valid found_i2c = [] for name in ALL_I2C: try: print("Checking {}...".format(name), end="") bus = eval(name) bus.unlock() found_i2c.append((name, bus)) print("ADDED.") except Exception as e: print("SKIPPED:", e) # Scan valid busses if len(found_i2c): print("-" * 40) print("I2C SCAN") print("-" * 40) while True: for bus_info in found_i2c: name = bus_info[0] bus = bus_info[1] while not bus.try_lock(): pass print( name, "addresses found:", [hex(device_address) for device_address in bus.scan()], ) bus.unlock() time.sleep(2) else: print("No valid I2C bus found.")
The I2C scanner code runs an I2C scan on each valid bus found and returns the device addresses found.
Both AHT20 sensors are on address 0x38. The sensor on the input side of the LTC4316 will remain on 0x38, but the sensor on the output side of the LTC4316 will be translated depending on the position of the DIP switches. To start, run the scanner code with the LTC4316 with both the A4 and A5 switches off, you'll see this result in the serial monitor:
Set switch A5 to on and power cycle the board. Now you'll see these addresses in the serial monitor:
Set switch A5 to off and A4 to on. Power cycle the board and you'll see these addresses in the serial monitor:
Finally, set both A5 and A4 to on and power cycle the board. The translated address for sensor 2 is 0x78, which is a reserved I2C address so it won't show up in CircuitPython. You'll only see 0x38 for sensor 1:
Raspberry Pi Wiring
Since there are dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired with I2C using the STEMMA connector. When you're working with I2C devices on a Raspberry Pi, it's important to plug everything in before powering up the Pi and do not unplug/replug devices while the Pi is running. This can cause errors on the filesystem.
Do not remove/insert I2C devices while the Raspberry Pi is running. It can cause errors on the filesystem.
-
Pi 3V to sensor 1 VIN (red wire)
-
Pi GND to sensor 1 GND (black wire)
-
Pi SCL to sensor 1 SCL (yellow wire)
- Pi SDA to sensor 1 SDA (blue wire)
- Sensor 1 VIN to LTC4316 VIN (red wire)
- Sensor 1 GND to LTC4316 GND (black wire)
- Sensor 1 SCL to LTC4316 SCI (yellow wire)
- Sensor 1 SDA to LTC4316 SDI (blue wire)
- LTC4316 VIN to sensor 2 VIN (red wire)
- LTC4316 GND to sensor 2 GND to (black wire)
- LTC4316 SCO to sensor 2 SCL (yellow wire)
- LTC4316 SDO to sensor 2 SDA (blue wire)
Here's the Raspberry Pi wired with I2C using a solderless breadboard:
-
Pi 3V to sensor 1 VIN (red wire)
-
Pi GND to sensor 1 GND (black wire)
-
Pi SCL to sensor 1 SCL (yellow wire)
- Pi SDA to sensor 1 SDA (blue wire)
- Sensor 1 VIN to LTC4316 VIN (red wire)
- Sensor 1 GND to LTC4316 GND (black wire)
- Sensor 1 SCL to LTC4316 SCI (yellow wire)
- Sensor 1 SDA to LTC4316 SDI (blue wire)
- LTC4316 VIN to sensor 2 VIN (red wire)
- LTC4316 GND to sensor 2 GND to (black wire)
- LTC4316 SCO to sensor 2 SCL (yellow wire)
- LTC4316 SDO to sensor 2 SDA (blue wire)
Raspberry Pi I2C Scan
You can run an I2C scan easily on a Raspberry Pi using i2cdetect
in a terminal window. If not already done, be sure to enable I2C on the Raspberry Pi via raspi-config
. If the i2cdetect
command is not found, install it with:
sudo apt-get install i2c-tools
And then to run a scan, use i2cdetect
with the following command line parameters:
i2cdetect -y 1
Here is the output in the terminal with switch A5 on and switch A4 off:
Now that you've completed the I2C scan on either a CircuitPython microcontroller or a Raspberry Pi, you can run an example for both of the AHT20 sensors.
Python Installation of AHTx0 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-ahtx0
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_AHTx0 library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folders and file:
- /adafruit_bus_device
- /adafruit_register
- adafruit_ahtx0.mpy

Python Usage
Once you have the library pip3
installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
For this example, you'll have the LTC4315 switch A5 on and switch A4 off. This will give the translated AHT20 sensor an I2C address of 0x68.
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries # SPDX-License-Identifier: MIT """ LTC4315 with two AHT20 sensors example Set the LTC4315 switch A5 on and switch A4 off The translated sensor will be on address 0x68 """ import time import board import adafruit_ahtx0 # Create sensor object, communicating over the board's default I2C bus i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller default_sensor = adafruit_ahtx0.AHTx0(i2c, 0x38) translated_sensor = adafruit_ahtx0.AHTx0(i2c, 0x68) while True: print("\nAHT20 at 0x38:") print(f"Temperature: {default_sensor.temperature:0.1f} C") print(f"Humidity: {default_sensor.relative_humidity:0.1f} %") print("\nAHT20 at 0x68:") print(f"Temperature: {translated_sensor.temperature:0.1f} C") print(f"Humidity: {translated_sensor.relative_humidity:0.1f} %") time.sleep(2)
First, both sensors are instantiated over I2C. The first AHT20 is instantiated with its default address 0x38. The second AHT20 is instantiated with its translated address at 0x68. In the loop, readings from both sensors are printed to the serial monitor.
Page last edited January 22, 2025
Text editor powered by tinymce.