7-Segment Display (TM1637) Meets AI Agent: Real-Time Data Display Without Coding with ASI Biont

Introduction

A 7-segment display — the iconic four-digit LED module found in clocks, thermostats, and industrial panels — is one of the most straightforward ways to show numeric data. The TM1637 variant, driven by a simple I2C-like two-wire protocol, is a favorite among makers and engineers for its low cost ($1–$3) and ease of use. But in a typical IoT setup, updating that display means writing firmware, reflashing microcontrollers, and hardcoding every value. What if you could tell an AI agent to "show the CPU temperature of my server" and have the display update automatically — without touching a single line of C++?

ASI Biont makes this possible. This article is a step-by-step guide to connecting a TM1637 7-segment display to ASI Biont, using an ESP32 or Arduino as the physical bridge. You'll learn which connection method works best, see real code examples, and discover how to build automation scenarios — like showing temperature, time, or system status — entirely through natural language conversation with an AI agent.

Why Connect a 7-Segment Display to an AI Agent?

A standalone TM1637 is a passive output device — it only shows what a microcontroller tells it to show. Integrated with an AI agent, it becomes a live dashboard that can:

  • Display real-time sensor data (temperature, humidity, pressure) from any source
  • Show system metrics (CPU load, disk usage, uptime) from servers or Raspberry Pi
  • Act as an alert panel — flashing a code when a threshold is exceeded
  • Sync with cloud services (weather, stock prices, crypto rates) without manual polling

The benefit is zero-hardcoding integration. Instead of writing and uploading new firmware every time you want to change what's displayed, you simply chat with ASI Biont: "Show the temperature from my DHT22 sensor on the TM1637 display, update every 5 seconds." The AI writes the code, connects to the device, and starts the data flow.

Connection Method: Hardware Bridge + COM Port

ASI Biont supports multiple integration methods (MQTT, SSH, Modbus, HTTP API, etc.), but for a TM1637 the most practical approach is Hardware Bridge via COM port.

Why this method?
- The TM1637 is typically controlled by an Arduino or ESP32 over GPIO pins (CLK and DIO). These microcontrollers connect to a PC via USB (virtual COM port).
- Hardware Bridge (bridge.py) is a small Python application that runs on your PC and connects to ASI Biont's cloud via WebSocket. It opens the COM port locally and forwards commands from the AI to the microcontroller.
- The AI uses the industrial_command tool with protocol serial:// to send serial_write_and_read(data=hex_string) — an atomic write+read operation. The microcontroller receives the data, updates the display, and optionally sends back an acknowledgment.

Alternative: SSH to Raspberry Pi
If your TM1637 is connected to a Raspberry Pi (directly or via an Arduino over USB), you can use SSH instead. The AI writes a Python script using paramiko that runs on the Pi and controls the display via GPIO libraries like RPi.GPIO or Adafruit_CircuitPython_TM1637. This is ideal if you already have a single-board computer acting as a hub.

Step-by-Step Integration: TM1637 + ASI Biont

Step 1: Hardware Setup

Connect the TM1637 module to your microcontroller (ESP32 or Arduino Uno):

TM1637 Pin ESP32 Pin Arduino Pin
VCC 3.3V 5V
GND GND GND
CLK GPIO 18 Digital 2
DIO GPIO 19 Digital 3

Table 1: Wiring diagram for TM1637 with ESP32 and Arduino

Step 2: Upload Firmware to Microcontroller

You need a simple firmware that listens on the serial port for commands and updates the display. Below is a complete MicroPython example for ESP32:

# ESP32 MicroPython firmware for TM1637
# Upload via Thonny or ampy

from machine import Pin
import tm1637
import time
import sys

# Initialize TM1637 on GPIO 18 (CLK) and 19 (DIO)
display = tm1637.TM1637(clk=Pin(18), dio=Pin(19))
display.brightness(7)  # maximum brightness

# Show startup message
display.show("LOAD")
time.sleep(1)
display.show("    ")

# Main loop: listen for serial commands
while True:
    if sys.stdin.available():
        try:
            cmd = sys.stdin.readline().strip()
            if cmd.startswith("SHOW:"):
                value = cmd[5:9].ljust(4)  # pad to 4 chars
                display.show(value)
                # Send acknowledgment
                print("OK:SHOW:" + value)
            elif cmd == "CLEAR":
                display.show("    ")
                print("OK:CLEAR")
            elif cmd == "BRIGHT:":
                level = int(cmd[7:8])
                display.brightness(min(level, 7))
                print("OK:BRIGHT:" + str(level))
            else:
                print("ERR:UNKNOWN")
        except Exception as e:
            print("ERR:" + str(e))

For Arduino (C++), use the TM1637Display library:

#include <TM1637Display.h>
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);

void setup() {
  Serial.begin(115200);
  display.setBrightness(0x0f);
}

void loop() {
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();
    if (cmd.startsWith("SHOW:")) {
      String value = cmd.substring(5, 9);
      display.showNumberDec(value.toInt());
      Serial.println("OK:SHOW:" + value);
    } else if (cmd == "CLEAR") {
      display.clear();
      Serial.println("OK:CLEAR");
    } else {
      Serial.println("ERR:UNKNOWN");
    }
  }
}

Upload the firmware to your board. Note the COM port (e.g., COM3 on Windows or /dev/ttyUSB0 on Linux).

Step 3: Set Up Hardware Bridge

  1. Go to the ASI Biont dashboardDevicesCreate API KeyDownload bridge.
  2. Install dependencies:
pip install pyserial requests websockets
  1. Run bridge.py with your token and COM port:
python bridge.py --token=YOUR_API_KEY --ports=COM3 --baud 115200

The bridge connects to ASI Biont via WebSocket and opens COM3 at 115200 baud. You should see a log message: [INFO] Connected to ASI Biont cloud.

Step 4: Configure the AI Agent via Chat

Now open the ASI Biont chat interface. Describe your setup and what you want to achieve. For example:

"I have a TM1637 display on COM3 at 115200 baud. The firmware accepts SHOW: followed by 4 characters. Show the temperature from the OpenWeatherMap API for London every 10 seconds."

ASI Biont will:
1. Verify the connection by sending a HELP command (the device should respond).
2. Write a Python script using execute_python that fetches weather data via requests and sends SHOW:temp to the bridge.
3. Schedule the script to run periodically (using the schedule library or a loop with time.sleep).

The AI might respond with something like:

# Generated by ASI Biont
import requests
import time

# Fetch temperature from OpenWeatherMap
api_key = "YOUR_KEY"
city = "London"
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"

while True:
    try:
        resp = requests.get(url).json()
        temp = round(resp['main']['temp'], 1)
        # Format as 4-character string (e.g., "23.5")
        temp_str = f"{temp:4}"
        # Send via bridge by calling industrial_command
        # (the AI knows the bridge protocol)
        # industrial_command(protocol='serial://', command='serial_write_and_read', data='SHOW:' + temp_str)
        time.sleep(10)
    except Exception as e:
        print("Error:", e)

Note: The AI runs this script inside the secure sandbox (execute_python). The sandbox has access to the bridge via the industrial_command tool — no direct HTTP calls to the bridge are needed.

Real-World Use Cases

1. Temperature and Humidity Monitor

Scenario: You have a DHT22 sensor connected to the same ESP32 as the TM1637. The ESP32 reads temperature and humidity, and ASI Biont decides what to show based on thresholds.

How it works:
- The ESP32 sends sensor data to ASI Biont via MQTT (or via the bridge serial link).
- The AI analyzes the data: if temperature > 30°C, display "HOT!"; otherwise show the numeric value.
- The AI sends the update command to the display.

Benefits: No need to re-flash the ESP32 when you change logic. Just tell the AI: "If humidity is above 70%, show 'WET' instead of the number."

2. Server Uptime Display

Scenario: You run a small home server (Raspberry Pi). You want the TM1637 to show uptime in hours.

How it works:
- The AI connects to the Raspberry Pi via SSH (using paramiko in execute_python).
- It runs uptime -p (or reads /proc/uptime) to get the uptime in seconds.
- It converts to hours, formats as 4 characters (e.g., "1234" for 1234 hours), and sends via bridge to the display.

Code snippet (generated by AI):

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.100', username='pi', password='raspberry')

stdin, stdout, stderr = ssh.exec_command('cat /proc/uptime')
uptime_seconds = float(stdout.read().decode().split()[0])
hours = int(uptime_seconds // 3600)
ssh.close()

# Format and send to TM1637 via bridge
# The AI uses industrial_command internally
display_value = str(hours).zfill(4)
# industrial_command(protocol='serial://', command='serial_write_and_read', data='SHOW:' + display_value)

3. Countdown Timer for Industrial Processes

Scenario: In a factory, a chemical process must run for exactly 180 seconds. The TM1637 shows the remaining time.

How it works:
- The AI starts a timer when a button (connected to another GPIO) is pressed.
- It decrements the display each second, sending SHOW:0179, SHOW:0178, etc.
- When time runs out, the AI can trigger an alarm (e.g., via MQTT to a buzzer).

Advantage: The countdown logic lives in the AI, not in the microcontroller firmware. You can change the duration or behavior by simply chatting: "Change the countdown to 300 seconds and show 'DONE' at the end."

Comparison of Connection Methods for TM1637

Method Hardware Required Latency Best For
Hardware Bridge + COM PC + Arduino/ESP32 ~50 ms Simple, local setups
SSH to Raspberry Pi Raspberry Pi with GPIO ~100 ms Server room, always-on SBC
MQTT + ESP32 ESP32 with WiFi ~200 ms Remote displays, IoT cloud
HTTP API ESP32 with web server ~300 ms RESTful control from anywhere

Table 2: Comparison of integration methods for TM1637 with ASI Biont

The best choice depends on your environment. For a desktop weather display, COM bridge is simplest. For a display in a factory that must survive without a PC, an ESP32 connected via MQTT is more robust.

How ASI Biont Handles the Integration Automatically

You don't need to write any of the code above manually. Here's the typical flow:

  1. Describe your device in the chat: "I have an ESP32 with a TM1637 display. It's connected to my PC on COM3 at 115200 baud. The firmware accepts commands like SHOW:1234."
  2. State your goal: "I want to display the current Bitcoin price from CoinGecko API, updating every 30 seconds."
  3. AI takes over:
  4. It tests the connection by sending a HELP command via bridge.
  5. It writes a Python script that fetches Bitcoin price (requests.get('https://api.coingecko.com/...')), formats it (e.g., "$56.7k" → "567K"), and sends it to the display.
  6. It runs the script in the sandbox with a loop and time.sleep(30).
  7. If the price changes significantly, the AI can flash the display or send you a notification.

No dashboards, no buttons, no manual coding. The entire integration is a conversation.

Limitations and Considerations

  • Sandbox timeout: Scripts run via execute_python have a 30-second timeout. For long-running loops, use the schedule library or break the loop with time.sleep() intervals.
  • Reliability: The COM bridge depends on the PC staying on. For 24/7 operation, consider an ESP32 with MQTT instead.
  • Data format: The TM1637 has only 4 digits. You need to format data creatively (e.g., "23.5" fits, "12345" does not). The AI can handle this — just tell it "show temperature as 2 decimal places."

Conclusion

Integrating a 7-segment display with an AI agent transforms it from a static number box into a dynamic, intelligent output panel. With ASI Biont, you connect the TM1637 via Hardware Bridge (COM port) or SSH, and the AI writes all the glue code — fetching data, formatting it, and pushing it to the display. You can change what's shown, how often it updates, and what triggers alerts, all through natural language.

Whether you're a maker building a weather station, an engineer monitoring server rooms, or an industrial operator creating process timers, the combination of TM1637 + ASI Biont saves hours of firmware work and gives you unprecedented flexibility.

Try it yourself: Go to asibiont.com, get your API key, download bridge.py, and tell the AI: "Connect my TM1637 display and show the current time." Your hardware will come alive in seconds.

← All posts

Comments