Introduction
The Teensy 4.x is not your average microcontroller. With a 600 MHz ARM Cortex-M7 processor, 1024 KB RAM, and built-in audio library, it can handle real-time signal processing, sensor fusion, and even machine learning inference on the edge. Yet, many developers spend hours writing custom Python scripts to log data, trigger alerts, or command actuators from a PC — only to find themselves maintaining brittle serial code.
ASI Biont changes that. It is an AI agent that connects directly to your Teensy via a simple chat conversation. No dashboards, no manual API integrations. You describe what you need (e.g., “read three analog pins every second and send a Telegram alert if the temperature exceeds 40°C”), and the AI writes and executes the integration code in seconds. This article shows you exactly how to connect Teensy 4.x to ASI Biont, which method to use, and what becomes possible when you combine real-time microcontroller data with AI-driven analytics.
Why Connect Teensy 4.x to an AI Agent?
Teensy excels at low-latency I/O – PWM, audio I²S, CAN bus, and up to 60 digital pins. But extracting value from that data often requires Python glue code on a host PC: parsing serial lines, storing averages, sending emails. ASI Biont eliminates that middle layer. The AI agent can:
- Read raw data from Teensy over USB serial.
- Perform complex analysis (FFT, anomaly detection, NLP on transcribed audio).
- Write back commands to control motors, LEDs, or relays — all without you writing a single line of glue code.
The AI agent uses Hardware Bridge – a lightweight bridge.py script you run on your PC. Bridge connects to ASI Biont’s cloud via WebSocket (the only channel) and opens a COM port to your Teensy. Then, through a chat conversation, you ask the AI to read sensors, process audio, or trigger actions. The entire flow is controlled by natural language.
Which Connection Method and Why?
Teensy 4.x exposes a USB CDC serial port (typically COM3 on Windows, /dev/ttyACM0 on Linux). The most straightforward and reliable method is COM port via Hardware Bridge (method #1 in ASI Biont’s supported protocols).
| Method | Pros | Cons | Best for |
|---|---|---|---|
| Serial (bridge.py) | Simple, no extras, bidirectional, low latency | Requires USB cable; PC must be on | Reading sensors, sending commands, audio streaming |
| MQTT (paho-mqtt) | Wireless, scalable | Needs WiFi module on Teensy (e.g., ESP32) | Distributed IoT networks |
| SSH | Works on single-board computers | Not native on Teensy | Teensy + Raspberry Pi combo |
The article focuses on the serial bridge because it is zero-configuration for most users: plug in USB, install pyserial and websockets, and run bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200. The AI agent then uses the industrial_command tool with protocol serial:// to communicate.
Real Use Case: Audio Anomaly Detection + Sensor Logging
Imagine you’re monitoring a machine that hums at 60 Hz when healthy. You have a Teensy 4.0 with an electret microphone on A2 and a DHT22 temperature/humidity sensor on pin 5. Instead of writing a Python script to capture audio FFT bins, compute RMS, and check thresholds, you simply tell ASI Biont:
“Connect to Teensy on COM3 at 115200 baud. Every second, read temperature from pin 5 (DHT22) and send me the value. Also, listen for a serial message ‘ANOMALY’ and if detected, blink the built-in LED for 5 seconds.”
The AI agent will:
1. Establish a bridge session with serial_write_and_read commands.
2. Send a single byte command 'R' to request temperature (Teensy firmware already returns temperature:25.3).
3. Parse the response and log it.
4. Start a background polling thread (within the bridged connection) that continuously checks for the ‘ANOMALY’ string.
5. When received, it sends a command 'B' to blink the LED.
Step-by-Step Code (from the AI agent’s perspective)
1. On Teensy (upload via Arduino IDE):
// teensy_firmware.ino
#include <DHT.h>
#include <Audio.h>
#define DHTPIN 5
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
AudioInputAnalog adc1(A2);
AudioAnalyzeFFT1024 myFFT;
AudioConnection patchCord(adc1, myFFT);
float anomaly_threshold = 0.5;
void setup() {
Serial.begin(115200);
dht.begin();
AudioMemory(12);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (Serial.available()) {
char cmd = Serial.read();
if (cmd == 'R') { // Read temperature
float t = dht.readTemperature();
Serial.print("temperature:"); Serial.println(t);
} else if (cmd == 'B') {
digitalWrite(LED_BUILTIN, HIGH);
delay(5000);
digitalWrite(LED_BUILTIN, LOW);
}
}
// Audio anomaly detection
if (myFFT.available()) {
float energy = myFFT.read(60, 1); // 60 Hz bin
if (energy > anomaly_threshold) {
Serial.println("ANOMALY");
}
}
delay(100);
}
2. On your PC – start bridge:
pip install pyserial websockets
python bridge.py --token=abc123 --ports=COM3 --baud 115200 --rate=10
3. In ASI Biont chat – the AI agent executes:
# This is generated and run by the AI agent in the sandbox (execute_python)
# Not user code – it's what the AI runs when you give the command.
import asyncio
from asibiont_tools import industrial_command # hypothetical internal API
async def read_temp():
response = await industrial_command(
protocol="serial://",
command="serial_write_and_read",
data="52" # hex for 'R'
)
print("Temperature:", response)
async def monitor_anomaly():
while True:
line = await industrial_command(
protocol="serial://",
command="serial_read_line" # waits for newline
)
if "ANOMALY" in line:
await industrial_command(
protocol="serial://",
command="serial_write_and_read",
data="42" # hex for 'B'
)
break
asyncio.run(asyncio.gather(read_temp(), monitor_anomaly()))
Note: The AI agent does not run infinite loops – it uses a single-shot monitor_anomaly() call that waits for one occurrence. In practice, the AI orchestrates periodic tasks via a scheduler inside its own environment.
Wiring Diagram (Textual)
Teensy 4.x
+-- [A2] – Electret Mic (with amplifier)
+-- [5] – DHT22 data pin (with 10kΩ pull-up)
+-- [USB] – to PC (COM3)
+-- [LED_BUILTIN] – internal
Beyond Sensors: Real-Time Audio Analytics
Teensy’s audio library can compute FFT in hardware. By streaming spectral data over serial, ASI Biont can run advanced analysis that the microcontroller alone cannot: voice activity detection, sound classification, or even keyword spotting. The AI agent stitches together the audio chunks, sends them to a local or cloud model (e.g., Whisper, YAMNet), and returns a text transcription or label.
Example Chat Prompt:
“Connect to Teensy at COM3. The Teensy sends 1024 FFT bins as comma-separated floats every 100ms. If the dominant frequency is between 200-400 Hz and the amplitude exceeds 0.3, classify it as a ‘human voice’ and log the timestamps.”
The AI will parse the serial stream, compute maximum bin, compare thresholds, and save events to a local CSV or send a notification. No programming required.
How to Connect – The Chat Experience
- Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge).
- Run bridge with your token and port:
bash python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200 - Open chat at asibiont.com.
- Type your request in natural language, e.g., “Connect to Teensy on COM3, read analog pin A0 every 5 seconds and plot in real time.”
The AI agent will immediately start writing the integration code, test the connection with a HELP command (Teensy should respond with a list of supported commands), and begin collecting data. If you need to change the logic – just ask. “Instead of plotting, send me a Telegram alert when A0 > 2.5V.”
What Makes This Different from Traditional IoT Platforms?
| Traditional Platform | ASI Biont |
|---|---|
| You design data pipeline, write MQTT client, parse JSON | You describe the goal, AI generates and runs code instantly |
| Dashboard configuration with drag-and-drop widgets | No dashboards – everything is conversational |
| Limited to built-in integrations | Any protocol: serial, MQTT, Modbus, SSH, CAN – AI writes code for any device |
| Requires manual firmware updates for new features | Firmware stays simple; AI handles all logic on the host |
Because ASI Biont uses execute_python – the AI writes and runs Python scripts directly in a sandbox that has access to all popular libraries (pyserial, paho-mqtt, paramiko, numpy, openai, etc.). This means you are not limited to a predefined set of supported devices. If your device talks over a custom binary protocol over TCP, the AI can decode it. If you have a Teensy that logs CAN bus frames, the AI can parse them.
Conclusion
Teensy 4.x is a powerful edge compute node, but its true potential is unlocked when combined with an AI agent that can interpret, respond, and evolve the logic in real time. ASI Biont turns your Teensy into a plug-and-play data source that can drive complex automation without a single line of manually written integration code.
Try it yourself today: Go to asibiont.com, download the bridge, plug in your Teensy, and tell the AI what you want to monitor. Whether it’s audio anomaly detection, environmental logging, or closed-loop control, the AI will make it happen in seconds – not hours.
Comments