Let's talk to an I2C sensor.

We'll use the BME280 sensor which can read temperature, humidity, and pressure. Here's the wiring diagram:

For the older version of the board, you'll need to jumper D1 and D2 together:

If you have the original board version, don't forget to jumper the D1 and D2 pins together.
If you have the new board version, don't forget to set the I2C MODE switch to ON.

Install BME280 Library

To install the BME280 library, run the following:

Download: file
sudo pip3 install adafruit-circuitpython-bme280

Note that this step is the same as shown in the main BME280 guide. You would do the same thing for any other sensor.

Run Example

Now we can run the simple test example from the library. Here's the code:

import time

import board
import busio
import adafruit_bme280

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# OR create library object using our Bus SPI port
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bme_cs = digitalio.DigitalInOut(board.D10)
# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

while True:
    print("\nTemperature: %0.1f C" % bme280.temperature)
    print("Humidity: %0.1f %%" % bme280.relative_humidity)
    print("Pressure: %0.1f hPa" % bme280.pressure)
    print("Altitude = %0.2f meters" % bme280.altitude)
    time.sleep(2)

Copy and save the above code and then run it with:

Download: file
python3 bme280_simpletest.py

and you should see it print out sensor readings over and over:

Using STEMMA QT

The new version of the FT232H features a STEMMA QT connector. This makes connecting to newer breakouts that also have a STEMMA QT connector super easy. Just use a STEMMA QT cable:

This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of...
Out of Stock
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of...
Out of Stock
This 4-wire cable is 50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but...
$0.95
In Stock

And then you can just wire the FT232H and the STEMMA QT breakout directly together. You don't even need a breadboard or soldering.

For breakout boards without a STEMMA QT connector, you can either use the header pins on both boards, that is, don't even use the STEMMA QT connector:

Or use the STEMMA QT connector on the FT232H breakout along with a STEMMA QT cable with one end of the cable cut off. You can then terminate the cut off end to the breakout in whatever way works best for your application.

There are also some STEMMA QT cables with header connectors which might be useful:

This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium female headers on the other. Compared with the chunkier...
$0.95
In Stock
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the...
Out of Stock

This guide was first published on Sep 29, 2019. It was last updated on Sep 29, 2019.

This page (I2C) was last updated on Nov 24, 2020.