Here's a simple example showing how to scan for any I2C devices that are connected to the ItsyBitsy ESP32 using Web Workflow. You'll connect an MCP9808 I2C sensor to the ItsyBitsy ESP32 for testing.
Plug a STEMMA QT to STEMMA QT cable into the port on the ItsyBitsy ESP32 and a port on the MCP9808 breakout.
Download the Project Bundle
In the example below, click the Download Project Bundle button to download the necessary Python file in a zip file. Then, extract the contents of the zip file. For this example, no additional libraries are needed.
# 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.")
Upload the Project Bundle with Web Workflow
Follow these steps to add the code.py file from the Project Bundle to the ItsyBitsy ESP32 with Web Workflow.
Navigate to where you downloaded the Project Bundle and select the code.py file. Click Open to upload the file to the device.
When the file has successfully uploaded, you'll see "Uploaded 1 out of 1 files" appear below the directory listing.
Your code will immediately start running. To see the serial output, you can head back to the main Welcome! screen by clicking on Blinka (the purple snake).
On the Welcome! screen, click on the serial terminal link. This will take you to the serial terminal window.
Text editor powered by tinymce.