-
Notifications
You must be signed in to change notification settings - Fork 161
99 Python
Geo edited this page Jul 10, 2025
·
11 revisions
This page shows how to communicate with the ESP32 Bus Pirate using Python over a serial connection.
- Python 3.x
-
pyseriallibrary (pip install pyserial) - ESP32 Bus Pirate connected via USB
Make sure you know the correct serial port:
- On Linux/Mac: typically
/dev/ttyUSB0,/dev/tty.SLAB_USBtoUART, etc. - On Windows: something like
COM3,COM4, etc.
You can list available ports using:
python -m serial.tools.list_portsimport serial
import time
# Replace with your actual port
PORT = "/dev/ttyUSB0"
BAUDRATE = 115200
with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
# Give device time to reset if needed
time.sleep(2)
# Wake up the Bus Pirate: send any random character
# This will trigger the welcome banner
ser.write(b"\n") # or any character
time.sleep(0.5)
# Read and print welcome message
while ser.in_waiting:
print(ser.readline().decode(errors="ignore").strip())
# Example command (e.g., enter WiFi mode)
ser.write(b"m wifi\n")
time.sleep(0.2)
# Read response
while ser.in_waiting:
print(ser.readline().decode(errors="ignore").strip())- Always send
\nto simulate Enter key. - Some commands require waiting before reading the full response.
- Use
ser.flushInput()andser.flushOutput()to clear buffers if needed. - For scripting instructions, you can send raw blocks like:
ser.write(b"[0x33 r:8]\n") # Send 1WIRE read ROM commandYou can also create wrappers around modes or commands. Here's a simple helper:
class BusPirate:
def __init__(self, port="/dev/ttyUSB0", baudrate=115200):
self.ser = serial.Serial(port, baudrate, timeout=1)
time.sleep(2)
def send(self, command):
self.ser.write((command + "\n").encode())
def read_all(self):
output = []
while self.ser.in_waiting:
output.append(self.ser.readline().decode(errors="ignore").strip())
return output
def close(self):
self.ser.close()Using pyserial, you can fully automate your interactions with the ESP32 Bus Pirate, from scripting protocols to issuing mode commands.
⚠️ Voltage Warning: Devices should only operate at 3.3V or 5V.
Do not connect peripherals using other voltage levels — doing so may damage your ESP32.