Introduction
The I2C (Inter-Integrated Circuit) bus is one of the most ubiquitous serial communication protocols in embedded systems. Developed by Philips Semiconductor (now NXP) in 1982, it allows multiple peripherals—temperature sensors, humidity sensors, accelerometers, LCD displays, EEPROMs, and more—to communicate with a microcontroller over just two wires: SDA (data) and SCL (clock). According to the official NXP I2C specification, the bus supports up to 127 devices on a single bus, making it ideal for sensor-rich projects.
But raw sensor data is useless without analysis, alerting, and automation. That’s where ASI Biont comes in. ASI Biont is an AI agent that can connect to virtually any device via Python—no custom firmware, no cloud dashboards, no waiting for developers to add support. You simply describe your setup in the chat, and the AI writes the integration code on the fly. This article walks through a concrete example: integrating an I2C temperature/humidity sensor (SHT30 or DHT12 on an I2C adapter) with an ESP32 microcontroller, sending data to ASI Biont via MQTT, and automating actions like Telegram alerts and relay control.
Unlike traditional device reviews, this is a pure integration guide. We assume you already have a sensor and a microcontroller; we focus on how ASI Biont bridges the gap between raw hardware and intelligent automation.
Why I2C and ASI Biont?
I2C is the backbone of many IoT projects because of its simplicity and low pin count. However, the real value comes when you can:
- Collect data from multiple sensors without cluttering your code with protocol handlers.
- Send that data to a cloud AI agent that can analyze trends, detect anomalies, and trigger actions.
- Automate responses: turn on a fan when temperature exceeds 30°C, log humidity every hour, send a Telegram alert when a sensor goes offline.
ASI Biont supports multiple connection methods (see the full list below), but for I2C sensors we typically use one of two paths:
1. MQTT – The sensor microcontroller publishes data to a broker (e.g., Mosquitto), and ASI Biont subscribes via a Python script using paho-mqtt.
2. Hardware Bridge + COM port – The microcontroller sends I2C readings over a serial connection (UART), and the user runs bridge.py on their PC, which connects to ASI Biont via HTTP long polling. The AI then sends industrial_command with protocol='serial://' to read data.
For this guide, we’ll use MQTT because it’s cloud-friendly, works over Wi-Fi, and doesn’t require a tethered PC. However, if your sensor is on a wired Arduino connected to a PC, the Hardware Bridge method works equally well.
Supported Connection Methods in ASI Biont
| Method | Protocol/Interface | Use Case |
|---|---|---|
| COM port (RS-232/485) | Hardware Bridge + bridge.py | Wired microcontrollers (Arduino, ESP32 via UART) |
| SSH | paramiko | Single-board computers (Raspberry Pi, Orange Pi) |
| MQTT | paho-mqtt | IoT devices with Wi-Fi (ESP32, smart home sensors) |
| Modbus/TCP | pymodbus | Industrial PLCs and Modbus devices |
| HTTP API / WebSocket | aiohttp | Smart plugs, cameras, REST APIs |
| OPC UA | opcua-asyncio | Industrial servers (factory automation) |
ASI Biont does NOT have a “device dashboard” or “add device” button. Everything happens through the chat conversation. You tell the AI: “Connect to my ESP32 via MQTT; it publishes temperature and humidity on topic sensor/data.” The AI then writes a Python script using paho-mqtt, runs it in a secure sandbox (cloud environment), and starts receiving data. If you need to send a command back—like turning on a relay—the AI publishes to a different topic.
Use Case: ESP32 + SHT30 I2C Sensor → ASI Biont via MQTT
Hardware Setup
- Microcontroller: ESP32 DevKit V1 (ESP-WROOM-32)
- Sensor: SHT30 (I2C address 0x44) – temperature (±0.3°C) and humidity (±2% RH)
- Wi-Fi: ESP32 connects to your local network
- MQTT Broker: Mosquitto running on a Raspberry Pi or cloud (e.g., HiveMQ Cloud free tier)
Wiring
| SHT30 Pin | ESP32 Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
No external pull-up resistors are needed if the ESP32 internal pull-ups are enabled (they are by default on GPIO21/22).
Microcontroller Code (Arduino Framework)
Below is a minimal MicroPython sketch for the ESP32. It reads the SHT30 every 10 seconds and publishes the data as JSON over MQTT.
# ESP32 MicroPython: sht30_mqtt.py
import network
import time
import json
from machine import Pin, I2C
from umqtt.simple import MQTTClient
# Wi-Fi credentials
WIFI_SSID = "your_wifi_ssid"
WIFI_PASS = "your_wifi_password"
# MQTT broker settings
MQTT_BROKER = "test.mosquitto.org" # public broker for testing
MQTT_PORT = 1883
MQTT_TOPIC = b"sensor/sht30"
CLIENT_ID = b"esp32_sht30_001"
# I2C setup
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
SHT30_ADDR = 0x44
def read_sht30():
# Send measurement command
i2c.writeto(SHT30_ADDR, b'\x2C\x06')
time.sleep_ms(20)
# Read 6 bytes
data = i2c.readfrom(SHT30_ADDR, 6)
# Convert raw data (see SHT30 datasheet)
raw_temp = (data[0] << 8) | data[1]
raw_hum = (data[3] << 8) | data[4]
temp = -45.0 + (175.0 * raw_temp / 65535.0)
hum = 100.0 * raw_hum / 65535.0
return temp, hum
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASS)
while not wlan.isconnected():
time.sleep(1)
print("Wi-Fi connected")
def main():
connect_wifi()
client = MQTTClient(CLIENT_ID, MQTT_BROKER, port=MQTT_PORT)
client.connect()
print("Connected to MQTT broker")
while True:
try:
temp, hum = read_sht30()
payload = json.dumps({"temperature": round(temp, 2), "humidity": round(hum, 2)})
client.publish(MQTT_TOPIC, payload)
print("Published:", payload)
time.sleep(10)
except OSError as e:
print("Sensor read error:", e)
time.sleep(5)
main()
Upload this script to your ESP32 using Thonny or ampy. Once running, it will publish data every 10 seconds to sensor/sht30.
Connecting ASI Biont via MQTT
Now open ASI Biont chat and describe your setup:
“I have an ESP32 publishing to MQTT topic
sensor/sht30on brokertest.mosquitto.org. Subscribe to that topic, parse the JSON, and if temperature exceeds 30°C, send me a Telegram alert. Also log all readings to a CSV file and email me a summary every 24 hours.”
The AI will generate and execute a Python script using paho-mqtt. Here’s a simplified version of what the AI might produce:
# ASI Biont sandbox script: mqtt_subscriber.py
import paho.mqtt.client as mqtt
import json
import time
import csv
from datetime import datetime
def on_message(client, userdata, msg):
try:
data = json.loads(msg.payload.decode())
temp = data["temperature"]
hum = data["humidity"]
print(f"Received: temp={temp}, hum={hum}")
# Log to CSV (stored in sandbox, downloadable)
with open("sensor_log.csv", "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([datetime.now().isoformat(), temp, hum])
# Alert if temperature > 30°C
if temp > 30.0:
# Send Telegram message (using requests library)
import requests
TELEGRAM_TOKEN = "your_token"
CHAT_ID = "your_chat_id"
text = f"⚠️ High temperature alert: {temp}°C"
requests.post(f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage",
json={"chat_id": CHAT_ID, "text": text})
except Exception as e:
print("Error processing message:", e)
client = mqtt.Client()
client.on_message = on_message
client.connect("test.mosquitto.org", 1883, 60)
client.subscribe("sensor/sht30")
print("Subscribed to sensor/sht30")
client.loop_forever()
Important: The sandbox has a 30-second timeout for scripts, so loop_forever() would normally be killed. However, ASI Biont’s MQTT integration uses the industrial_command tool for quick checks, and for continuous subscription, the AI uses an async approach with asyncio or a separate long-running task (outside sandbox) via the Hardware Bridge. In practice, the AI will use asyncio with paho-mqtt’s async client or a non-blocking loop to stay within limits. The above is for illustration.
Automating Actions
Once ASI Biont receives the data, you can trigger any action:
- Telegram/Email alerts when thresholds are exceeded.
- Relay control: publish a command to a second MQTT topic (e.g., actuator/relay1) that the ESP32 subscribes to, turning on a fan or heater.
- Database logging: store readings in PostgreSQL or MongoDB for historical analysis.
- Chart generation: use matplotlib to create temperature trends and email the chart daily.
Here’s an example of how the AI might control a relay via MQTT:
# In the on_message callback, after alert:
if temp > 30.0:
# Publish "ON" to relay topic
client.publish("actuator/relay1", b"ON")
elif temp < 25.0:
client.publish("actuator/relay1", b"OFF")
Real-World Scenario: Greenhouse Automation
Consider a greenhouse with 10 I2C sensors (SHT30 for temperature/humidity, BH1750 for light, and MPU6050 for vibration to detect wind). Each sensor is on an ESP32 node that publishes via MQTT. ASI Biont:
- Aggregates all sensor data into a unified time-series database.
- Detects outliers: if one sensor reads 10°C higher than neighbors, it flags a hardware fault.
- Controls irrigation: if soil moisture (another I2C sensor) is low, it opens a valve via a relay.
- Sends a daily report with max/min values and growth predictions.
All of this is configured through chat conversations. No UI, no manual coding of integration logic—the AI writes the glue code.
Why This Approach Beats Traditional IoT Platforms
Traditional platforms (AWS IoT, Azure IoT Hub, ThingsBoard) require:
- Setting up device shadows.
- Writing integration code in their SDK.
- Managing dashboards.
With ASI Biont, you:
1. Connect your hardware (ESP32 + I2C sensor).
2. Describe what you want in plain English.
3. The AI generates the Python integration, runs it, and starts automating.
Because ASI Biont uses execute_python (a sandboxed Python environment with libraries like paho-mqtt, pymodbus, paramiko, aiohttp, opcua-asyncio, plus data analysis libraries like numpy, pandas, scikit-learn), you can connect to any device that communicates over a supported protocol. The user only provides connection parameters (IP, port, baud rate, API key) in the chat.
Conclusion
Integrating I2C sensors with ASI Biont transforms a simple temperature logger into an intelligent automation system. By using MQTT as the bridge between the microcontroller and the AI agent, you get real-time data collection, anomaly detection, alerting, and actuator control—all without writing a single line of integration boilerplate. The AI does the heavy lifting.
Whether you’re building a smart greenhouse, a home automation system, or an industrial monitoring setup, ASI Biont’s flexible connection methods (COM port, MQTT, SSH, Modbus, HTTP, OPC UA) mean you can plug in almost any I2C device. The only limit is your imagination.
Ready to automate your I2C sensors? Head over to asibiont.com and start a chat with the AI agent. Describe your hardware, and let the AI write the integration in seconds.
Comments