DC Motors (L298N, BTS7960) + ASI Biont
Robotics projects almost always start with the same problem: you have a motor driver, an Arduino or ESP32, and a pile of wires — but controlling the robot from afar or building logic on top of it takes weeks of firmware work. What if you could just tell the AI what you want, and it writes the integration, connects the driver, and lets you command the robot via chat? That's exactly what ASI Biont does for DC motor drivers like L298N and BTS7960.
In this article, you'll learn how to connect these popular H-bridge drivers to ASI Biont using MQTT or a COM port, see real code for ESP32/Arduino, and explore automation scenarios from voice-controlled carts to smart greenhouses.
Why Connect a Motor Driver to an AI Agent?
A DC motor driver is a straightforward device: it takes PWM and direction signals and drives the motor. The complexity lives in the firmware, state logic, and remote control. ASI Biont removes that layer by acting as a central brain. You can send natural-language commands like "move forward at 40% speed" — the AI converts it into the proper PWM/direction values and sends them to the driver. The result is a robot that you can control and automate without writing a full control system from scratch.
How ASI Biont Connects to L298N / BTS7960
ASI Biont is protocol-agnostic. For DC motor drivers, the most practical options are:
| Method | Protocol | Library | Use case |
|---|---|---|---|
| COM port | RS-232/RS-485 via Hardware Bridge | bridge.py | Wired connection to an Arduino controlling the driver |
| MQTT | MQTT over TCP | paho-mqtt | ESP32/NodeMCU with Wi-Fi, cloud-independent |
| HTTP/WebSocket | REST API | aiohttp | Local server on the motor controller |
| Execute Python | Any | pyserial / paho-mqtt / socket | Direct connection to any device, no waiting for built-in support |
You don't need to click through configuration panels. You describe your setup in the chat — port, baud rate, IP, topic, API key — and ASI Biont generates the adapter code.
Practical Example: ESP32 + L298N Over MQTT
Here's a minimal MicroPython firmware for an ESP32 with an L298N driver. It subscribes to a topic and parses commands like "F:200" (forward, PWM=200) or "B:150" (backward, PWM=150):
from machine import Pin, PWM
import ubinascii
from umqtt.simple import MQTTClient
IN1 = Pin(25, Pin.OUT)
IN2 = Pin(26, Pin.OUT)
ENA = PWM(Pin(27), freq=1000)
def motor_control(cmd):
parts = cmd.split(':')
direction = parts[0]
speed = int(parts[1])
if direction == 'F':
IN1.value(1); IN2.value(0)
ENA.duty(speed)
elif direction == 'B':
IN1.value(0); IN2.value(1)
ENA.duty(speed)
elif direction == 'S':
IN1.value(0); IN2.value(0)
ENA.duty(0)
client = MQTTClient('esp32_l298n', '192.168.1.100', user='biont', password='secret')
def on_message(topic, msg):
motor_control(msg.decode())
client.set_callback(on_message)
client.connect()
client.subscribe(b'robot/motor')
while True:
client.wait_msg()
On the ASI Biont side, the AI agent uses the paho-mqtt library to publish commands. All you do is tell the chat agent: "The MQTT broker is at 192.168.1.100, topic robot/motor, send a command F:200." The agent writes and executes the publisher script.
Hardware Bridge Example: COM Port with industrial_command()
If your robot uses a wired serial link, download bridge.py from the ASI Biont dashboard (no other source — always get it from the dashboard to avoid tampered versions) and launch it:
python bridge.py --token=XXX --ports=COM3 --baud 115200 --rate=10
Then in the chat, the AI sends a command using the industrial protocol:
response = industrial_command(
protocol='serial',
command='F:200',
port='COM3',
baudrate=115200
)
print(response)
The bridge handles framing, handshake, and the COM port lifecycle. The AI agent uses this to send raw serial commands to the motor driver via an Arduino sketch.
BTS7960: Higher Current, Same Pattern
The BTS7960 is a half-bridge driver capable of much higher current (up to 43A with proper heatsinking). Its control logic uses PWM and direction pins just like the L298N, so the integration pattern stays identical. The main difference is electrical — separate power supply, overcurrent protection pins, and often an additional enable signal. In ASI Biont, you simply tell the agent "I'm using a BTS7960 on pins 4/5/6" and it adapts the code accordingly.
Real-World Automation Scenarios
1. Voice-Controlled Robot Cart
A small rover with an ESP32, L298N, and a microphone running voice recognition. ASI Biont receives a text command from the user (from a chat interface or a voice-to-text assistant), decides the movement sequence, and publishes it to MQTT. The cart can navigate a warehouse line with simple commands: "go to dock 3, stop at the sensor."
2. Automated Conveyor Belt
A factory conveyor uses two BTS7960 drivers to control belt speed and direction. The AI agent monitors sensor values (via Modbus or MQTT) and adjusts motor PWM to keep the line at the required speed. If a jam sensor triggers, the agent stops the belt and sends a Telegram alert.
3. Smart Greenhouse with Motorized Vents
Greenhouse windows are often driven by DC actuators through an L298N. ASI Biont reads temperature and humidity via a HTTP API from a weather station, then opens or closes the vents by sending F:255 or B:255. Because the AI can combine data sources, it can also implement a schedule — for example, close the vents when the wind speed exceeds a threshold.
How AI Writes the Integration Code
You don't need to know the API in advance. In the ASI Biont chat, you describe the task:
"Connect to my L298N robot via MQTT at 192.168.1.50:1883, user 'robot', password '1234'. Topic 'cmd'. Make it so I can say 'forward 50' and it goes forward at PWM 50."
The agent generates a Python script containing the MQTT client, a message parser, and a loop that translates natural-language intents into PWM commands. Because execute_python runs in a sandbox with a 30-second timeout, the agent uses blocking client.loop_forever() or a simple time.sleep cycle rather than while True loops to avoid timeouts. For long-running tasks, it delegates to the Hardware Bridge or a persistent service.
The same applies to any device — not just motor drivers. ASI Biont connects to arbitrary hardware through execute_python, using pyserial, paramiko, paho-mqtt, pymodbus, aiohttp, or opcua-asyncio. This means you are never blocked waiting for official driver support. Describe the device, its port, IP, baud rate, or API key — and the AI writes the integration on the spot.
Why This Matters
- Speed: Integration that used to take days of firmware work is done in seconds.
- Language: You interact with your robot in plain English, not cryptic register maps.
- Flexibility: Switching from L298N to BTS7960 is just a chat prompt away.
- Automation: Combine motor control with sensors, timers, and external APIs to build complex scenarios like a fully automated greenhouse.
ASI Biont turns a dumb motor driver into a conversational, autonomous actuator. Whether you're building a hobby robot or an industrial automation cell, the workflow is the same: describe, connect, control.
Try It Yourself
Go to asibiont.com, open the chat, and describe your motor driver setup. The AI will help you select the connection method, generate the firmware snippet, and run the integration code. No dashboards, no button-clicking — just dialogue.
Comments