Comprehensive GPIO control, PWM, analog I/O, I2C communication, and more with professional-grade performance.
Complete control over all 40 GPIO pins with input/output modes, pull-up resistors, and efficient batch operations.
from esp32_gpio_bridge import ESP32GPIO
with ESP32GPIO(port) as esp:
# Set pin modes
esp.set_pin_mode(2, "OUT") # LED pin
esp.set_pin_mode(0, "IN_PULLUP") # Button pin
# Digital operations
esp.digital_write(2, 1) # Turn LED on
button_state = esp.digital_read(0) # Read button
# Batch operations (much faster)
esp.batch_digital_write({
2: 1, # LED on
4: 0, # Pin 4 low
5: 1 # Pin 5 high
})
# Get configured pins
pins = esp.get_configured_pins()
print(f"Configured pins: {pins}")
| Pin Range | Digital I/O | Analog Input | PWM | Notes |
|---|---|---|---|---|
| GPIO 0-31 | Output only (some pins) | |||
| GPIO 32-39 | ADC capable | |||
| GPIO 25, 26 | DAC output |
from esp32_gpio_bridge import ESP32GPIO
with ESP32GPIO(port) as esp:
# Initialize PWM
channel = esp.pwm_init(
pin=2, # GPIO pin
frequency=1000, # 1kHz frequency
resolution=8 # 8-bit resolution (0-255)
)
# Set duty cycle (raw value)
esp.pwm_write(2, 128) # 50% duty cycle
# Set duty cycle (percentage)
esp.pwm_set_duty_percent(2, 75.0) # 75% duty cycle
# Fade LED effect
for i in range(0, 256, 5):
esp.pwm_write(2, i)
time.sleep(0.01)
# Stop PWM
esp.pwm_stop(2)
Hardware PWM with up to 16 channels, configurable frequency and resolution for precise control of motors, LEDs, and servos.
12-bit ADC input and 8-bit DAC output for precise analog signal processing and generation.
from esp32_gpio_bridge import ESP32GPIO
with ESP32GPIO(port) as esp:
# Analog input - read sensor
raw_value = esp.analog_read(34) # GPIO 34
voltage = (raw_value / 4095.0) * 3.3
print(f"Sensor voltage: {voltage:.2f}V")
# Analog output - generate voltage
esp.analog_write(25, 128) # 1.65V on GPIO 25
esp.analog_write(26, 255) # 3.3V on GPIO 26
# Continuous monitoring
while True:
sensor_val = esp.analog_read(34)
# Convert to percentage
percentage = (sensor_val / 4095.0) * 100
print(f"Sensor reading: {percentage:.1f}%")
time.sleep(0.1)
from esp32_gpio_bridge import ESP32GPIO
with ESP32GPIO(port) as esp:
# Initialize I2C bus
esp.i2c_init(sda=21, scl=22, frequency=100000)
# Scan for devices
devices = esp.i2c_scan()
print(f"Found devices: {[hex(addr) for addr in devices]}")
# Write to device (e.g., OLED display)
esp.i2c_write(0x3C, [0x00, 0xFF, 0x80]) # Address, data
# Read from device (e.g., sensor)
data = esp.i2c_read(0x48, 4) # Address, bytes to read
print(f"Read data: {data}")
# Common sensor operations
# Write register address
esp.i2c_write(0x48, [0x00]) # Register 0x00
# Read sensor data
sensor_data = esp.i2c_read(0x48, 2)
temperature = (sensor_data[0] << 8) | sensor_data[1]
print(f"Temperature: {temperature}")
Full I2C bus control with device scanning, read/write operations, and support for common sensors and peripherals.
512 bytes of persistent storage for configuration data, settings, and small data persistence.
from esp32_gpio_bridge import ESP32GPIO
with ESP32GPIO(port) as esp:
# Single byte operations
esp.eeprom_write(0, 42) # Write byte
value = esp.eeprom_read(0) # Read byte
# Block operations
data = [10, 20, 30, 40, 50]
esp.eeprom_write_block(10, data)
read_data = esp.eeprom_read_block(10, 5)
# String operations
esp.eeprom_write_string(100, "Hello ESP32!")
esp.eeprom_commit() # Save to flash
text = esp.eeprom_read_string(100, 12)
print(f"Stored text: {text}")
# Configuration storage
config = {
'wifi_ssid': 'MyNetwork',
'wifi_password': 'secret123',
'device_id': 12345
}
# Store configuration as JSON
import json
config_json = json.dumps(config)
esp.eeprom_write_string(200, config_json)
esp.eeprom_commit()
Intelligent failsafe system and safety mechanisms to prevent hardware damage and ensure reliable operation.
Multi-stage failsafe system with intelligent activation and instant recovery.
Automatic pin capability checking and mode validation.
Comprehensive error handling with detailed feedback and recovery.
All critical issues resolved! The ESP32 GPIO Bridge is now production-ready with zero known issues and comprehensive stability features.
Fixed hardware watchdog timer issues that were causing unwanted ESP32 restarts during normal operations.
Enhanced serial communication with comprehensive error filtering and mixed message parsing.
Fixed ESP32 hang issues after idle periods by optimizing failsafe mechanism and health monitoring.
Less aggressive failsafe mechanism with better timeout management for improved responsiveness.
Comprehensive testing confirms stable long-term operation with all examples working perfectly.
The ESP32 GPIO Bridge is now ready for production use with all core features working perfectly.