Introduction
1-Wire is one of those protocols that just won't die — and for good reason. A single data line, a ground, and sometimes a power pin can chain dozens of temperature sensors, EEPROMs, and battery monitors over hundreds of meters. The DS18B20, for instance, has been the backbone of greenhouse automation, server-room monitoring, and DIY weather stations for nearly two decades. But making sense of its raw binary scratchpad data, handling ROM commands, and dealing with parasitic power can eat hours of your time.
When you combine 1-Wire with ASI Biont, the AI agent does the heavy lifting. Instead of writing and debugging low-level bit-banging code from scratch, you describe the sensor and your goal in plain English. ASI Biont chooses the right connection method, generates the Python code, and executes it. This article is a practical, code-first guide to integrating 1-Wire sensors with ASI Biont through a COM port — the most common interface for USB 1-Wire adapters. We'll cover wiring, Python examples, real-world automation scenarios, and explain how ASI Biont's AI constructors turn a chat message into a working integration.
What Is 1-Wire and Why Connect It to an AI Agent?
1-Wire is a half-duplex, low-speed protocol developed by Dallas Semiconductor (now Maxim Integrated). It uses a single open-drain data line with a 4.7 kΩ pull-up resistor to 3.3–5 V. Each device has a unique 64-bit ROM code, so you can put many sensors on the same bus and address them individually. The DS18B20 temperature sensor, for example, returns 12-bit readings with ±0.5°C accuracy from −55°C to +125°C. Its datasheet (available at Analog Devices) describes the entire protocol in detail — but who wants to parse a hundred pages of timing diagrams?
This is exactly where an AI agent shines. ASI Biont can read the datasheet, understand the byte-level commands (SKIP ROM, CONVERT T, READ SCRATCHPAD), and write clean Python code using the pyserial library. You don't need to remember whether the reset signal is 480 µs or 960 µs. Just say, "I have three DS18B20s on COM4, log temperatures every minute," and the AI handles it.
Hardware You Need for 1-Wire Integration
To connect 1-Wire sensors to ASI Biont, you have two main paths:
- USB 1-Wire adapter (e.g., MAXIM DS9490R, or a cheap USB-to-serial adapter with an FTDI chip and a 1-Wire level shifter). The adapter appears as a COM port on your PC.
- GPIO on a microcontroller (e.g., Raspberry Pi, ESP32) that runs a temporary bridge — but the cleanest route is still a serial connection.
In this guide, we'll focus on the COM port path. It's universal: any OS sees a COM port, and ASI Biont's Hardware Bridge can talk to it over the internet.
Wiring the DS18B20 to a USB 1-Wire Adapter
Here is the classic wiring diagram for a DS18B20 in external power mode:
USB 1-Wire adapter DS18B20
----------------- -------
VCC (3.3V) --------------- VDD (pin 3)
Data --------------- DQ (pin 2)
GND --------------- GND (pin 1)
Pull-up resistor: 4.7 kΩ between Data and VCC
For parasitic power mode, connect VDD and GND together and use the DQ line for both data and power:
USB 1-Wire adapter DS18B20
----------------- -------
VCC (3.3V) --------------- VDD & GND tied together
Data --------------- DQ
GND --------------- GND
In parasitic mode, the pull-up resistor must be stronger (2.2 kΩ is safer). Most modern adapters supply 5V on VCC; double-check your sensor's maximum rating.
For multiple sensors connected in parallel, each sensor's DQ, VDD, and GND all go to the same bus. Up to 10 sensors can live on a 10-meter cable with a 4.7 kΩ pull-up; for longer runs, use 2.2 kΩ.
Connecting to ASI Biont: COM Port via Hardware Bridge
The Hardware Bridge (bridge.py) is the out-of-band component that ASI Biont uses to reach serial devices on your computer. You download it from the ASI Biont dashboard — never from GitHub or a third-party site. Once launched, it opens the specified COM port and establishes a secure connection to the ASI Biont cloud. The AI agent can then send commands through the bridge.
Bridge is a command-line tool. A typical launch looks like this:
python bridge.py --token=YOUR_TOKEN --ports=COM4 --baud=115200 --rate=10
--tokenis your personal API token from the ASI Biont dashboard.--portsis the COM port name (on Windows it'sCOM4, on Linux/dev/ttyUSB0).--baudsets the serial baud rate. For 1-Wire, 115200 is common, but some adapters use 9600 or 57600. Check your adapter's datasheet.--ratedefines how often the bridge polls the port (in Hz).
After the bridge connects, you can start a chat in ASI Biont and write: "Read the temperature from the 1-Wire sensor on COM4 every 30 seconds and send me an alert if it goes above 60°C."
Launching the Bridge
Let's say you have a DS18B20 on COM4, and you downloaded bridge.py to your Downloads folder.
On Windows:
python Downloads\bridge.py --token=abc123 --ports=COM4 --baud=115200 --rate=10
On Linux/macOS:
python3 ~/Downloads/bridge.py --token=abc123 --ports=/dev/ttyUSB0 --baud=115200 --rate=10
The bridge will log something like:
[INFO] Bridge started
[INFO] Connected to ASI Biont cloud
[INFO] Monitoring port COM4
Now the bridge is waiting for commands. ASI Biont's AI agent will use industrial_command() to talk to the port.
Talking to the Sensor: Python Code Example (Standalone)
Before we let ASI Biont generate the code, let's understand how to read a DS18B20 from Python. This example works on any machine with pyserial installed and a USB 1-Wire adapter that exposes a raw serial interface.
import serial
import time
import glob
# Find the right port (auto-detect on Linux)
ports = glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*')
port = ports[0] if ports else 'COM4'
ser = serial.Serial(port, 115200, timeout=2)
def onewire_reset():
ser.write(b'\x00') # send reset pulse (actual bytes depend on adapter)
time.sleep(0.05)
return ser.read(1) # presence pulse
def read_temperature():
# 1-Wire commands for DS18B20, using the adapter's serial protocol.
# This is a simplified example; the exact bytes vary by adapter.
onewire_reset()
ser.write(b'\xCC') # SKIP ROM
ser.write(b'\x44') # CONVERT T
time.sleep(0.75) # wait for conversion
onewire_reset()
ser.write(b'\xCC') # SKIP ROM
ser.write(b'\xBE') # READ SCRATCHPAD
data = ser.read(9) # read 9 bytes
temp_raw = (data[1] << 8) | data[0]
if temp_raw & 0x8000:
temp_raw = temp_raw - 65536
celsius = temp_raw / 16.0
return celsius
while True:
try:
temp = read_temperature()
print(f"{time.time()}, {temp:.2f}")
except Exception as e:
print("Error:", e)
time.sleep(30)
This loop is fine for a local script, but inside ASI Biont's sandbox, you'd never run an infinite while True — its execute_python has a 30-second timeout. Instead, you'd write a single-shot function and let ASI Biont's scheduler call it periodically.
Same Code Inside ASI Biont: Using industrial_command
When you're inside ASI Biont, you don't have direct access to pyserial on your local machine. The bridge abstracts the serial port. The correct way to send commands is through industrial_command(). Here's a minimal example of what the AI agent might generate for a one-off temperature read:
def get_temperature():
response = industrial_command(
protocol="serial",
command="write_read",
port="COM4",
data=[0x00, 0xCC, 0x44], # reset, skip ROM, convert T
read_size=9,
timeout=1000
)
# Parse the 9-byte scratchpad
if len(response["data"]) < 9:
return None
raw = (response["data"][1] << 8) | response["data"][0]
if raw & 0x8000:
raw -= 65536
return raw / 16.0
This example is intentionally simplified. The exact command and data fields depend on the bridge version and your adapter. The key point is: you write one function, and ASI Biont runs it on demand or on a schedule. No infinite loops — just a clean, testable unit.
Device-Side MicroPython with ESP32
Sometimes you don't want to run a USB cable to your PC. An ESP32 with a 1-Wire sensor can publish measurements via MQTT, and ASI Biont can subscribe to that MQTT topic. Here's a MicroPython example for the ESP32 side:
from machine import Pin
from onewire import OneWire
from ds18x20 import DS18X20
import time, ubinascii, network
from umqtt.simple import MQTTClient
ow = OneWire(Pin(4))
ds = DS18X20(ow)
roms = ds.scan()
print("Found:", len(roms))
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("SSID", "password")
while not wlan.isconnected():
time.sleep(0.5)
client = MQTTClient("esp32", "broker.hivemq.com", 1883)
client.connect()
while True:
ds.convert_temp()
time.sleep_ms(750)
temp = ds.read_temp(roms[0])
client.publish("sensors/temperature", str(temp))
time.sleep(10)
Then, in ASI Biont, you'd instruct the AI: "Subscribe to MQTT topic sensors/temperature and log it." The AI will generate code using paho-mqtt. This is a great way to bridge 1-Wire into an existing wireless environment.
Scenario 1: Greenhouse Climate Control
You have a greenhouse with four DS18B20 sensors measuring air, soil, and two control points. You want to maintain 22–28°C during the day. With ASI Biont you can set up a rule:
"Every 5 minutes, read the average temperature from all sensors on COM3. If it's below 22°C, turn on the heater via the relay on COM5; if it's above 28°C, open the vent."
The AI agent will:
- Generate a script that reads all four sensors using the 1-Wire bus.
- Compute the average.
- Send a Modbus or MQTT command to the relay controller.
- Log the values and send a Telegram notification when something's off.
Here's a pseudo-code snippet for the decision logic:
temps = [read_sensor(s) for s in sensor_ids]
avg = sum(temps) / len(temps)
if avg < 22:
industrial_command(protocol="modbus", command="write_coil", address=5, value=True)
elif avg > 28:
industrial_command(protocol="modbus", command="write_coil", address=6, value=True)
else:
industrial_command(protocol="modbus", command="write_coil", address=5, value=False)
industrial_command(protocol="modbus", command="write_coil", address=6, value=False)
Scenario 2: Server Room Monitoring
A server room must not exceed 35°C. Place a DS18B20 near the rack intake and another near the exhaust. In ASI Biont, set up a monitoring task:
"Read both sensors every minute. If any temperature exceeds 40°C, send an alert to my phone and turn on the backup fan via GPIO on the Raspberry Pi bridge."
The AI will generate a script that uses requests.post to send a Telegram message via the official Bot API:
import requests
def send_alert(msg):
requests.post(
"https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/sendMessage",
json={"chat_id": "987654321", "text": msg}
)
This is a practical, low-latency way to protect expensive hardware without installing a dedicated monitoring system.
Scenario 3: Smart Home Temperature Logging
Install DS18B20 sensors in every room. Connect them to a single USB adapter on your home server. Ask ASI Biont: "Log temperatures from all rooms to a CSV file every 15 minutes and show me a daily average." The AI will write a script that appends to a file, and then you can ask for a graph or trend analysis — all from the chat.
The interesting part is that you can mix protocols. You can read the 1-Wire sensors, combine the data with energy consumption from an MQTT smart meter, and let the AI correlate the two: "When the living room temperature drops below 20°C, the heater runs for 3 hours — how much energy does that use?"
How ASI Biont's AI Agent Generates the Integration
No code wizardry is required from your side. The workflow is:
- Describe your device — "I have a DS18B20 on /dev/ttyUSB0 at 9600 baud."
- Describe the goal — "Read the temperature and send it to my dashboard."
- Optional constraints — "Use Celsius, check every 30 seconds, alert if out of range."
The AI searches its built-in protocol knowledge (1-Wire, Modbus, MQTT, etc.) and writes a Python script. It uses industrial_command() for serial/mobile protocols or execute_python for anything custom. You can review the code, ask for changes, and run it in seconds.
What makes this powerful is the universal execute_python fallback. If your device uses a proprietary binary protocol over CAN bus, or an undocumented HTTP endpoint, just tell ASI Biont. The AI will use python-can, aiohttp, or pyserial to talk to it. There is no need to wait for an official plugin — the AI adapts on the fly.
Security and Reliability Notes
- Always download
bridge.pyonly from the ASI Biont dashboard. A compromised bridge would expose your COM ports to the internet. - Use strong tokens and rotate them regularly.
- For industrial setups, consider a dedicated USB adapter with electrical isolation to protect your PC from voltage spikes.
- The 1-Wire bus works best with a 4.7 kΩ pull-up. If you see random readings, check your wiring and pull-up resistance.
- ASI Biont's sandbox enforces a 30-second timeout on
execute_python. For long-running tasks, rely on the scheduler or set up recurring commands.
Conclusion
1-Wire is a simple, reliable protocol, but its raw protocol details are tedious. ASI Biont removes the complexity by generating and running the integration code for you. Whether you're automating a greenhouse, monitoring a server room, or just logging temperatures, you can be up and running in ten minutes — without reading a single timing diagram.
Try it yourself: describe your 1-Wire sensor setup to ASI Biont at asibiont.com, and let the AI do the wiring — the virtual wiring, at least.
Comments