Features Overview

Comprehensive GPIO control, PWM, analog I/O, I2C communication, and more with professional-grade performance.

Digital GPIO Control

Complete control over all 40 GPIO pins with input/output modes, pull-up resistors, and efficient batch operations.

40 GPIO Pins: Full control over pins 0-39
Multiple Modes: INPUT, OUTPUT, INPUT_PULLUP
Batch Operations: Control multiple pins simultaneously
Pin Validation: Automatic capability checking
GPIO Control Example
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}")

GPIO Pin Capabilities

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
PWM Control Example
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

Hardware PWM with up to 16 channels, configurable frequency and resolution for precise control of motors, LEDs, and servos.

16 PWM Channels: Hardware-based PWM
Frequency Range: 1Hz to 40kHz
Resolution: 1-16 bits (1-65535 steps)
O(1) Lookup: Instant PWM operations

Use Cases

  • • Servo motor control
  • • LED brightness control
  • • Motor speed control
  • • Audio signal generation

Analog I/O

12-bit ADC input and 8-bit DAC output for precise analog signal processing and generation.

ADC Input

  • • 12-bit resolution (0-4095)
  • • 0-3.3V voltage range
  • • GPIO 32-39 (ADC1)
  • • eFuse calibration

DAC Output

  • • 8-bit resolution (0-255)
  • • 0-3.3V voltage range
  • • GPIO 25, 26 (DAC1, DAC2)
  • • Direct voltage output
Analog I/O Example
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)
I2C Communication Example
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}")

I2C Communication

Full I2C bus control with device scanning, read/write operations, and support for common sensors and peripherals.

Device Scanning: Automatic device detection
Configurable Pins: Default SDA=21, SCL=22
Speed Control: 1kHz to 1MHz
Error Handling: Robust communication

Supported Devices

  • • Temperature sensors (TMP36, DS18B20)
  • • OLED displays (SSD1306)
  • • Accelerometers (MPU6050)
  • • Real-time clocks (DS1307)
  • • EEPROM chips (24LC256)

EEPROM Storage

512 bytes of persistent storage for configuration data, settings, and small data persistence.

512 Bytes: Persistent storage space
Block Operations: Read/write multiple bytes
String Support: Direct string storage
Commit System: Safe write operations

Use Cases

  • • WiFi credentials storage
  • • Device configuration
  • • Calibration data
  • • User preferences
  • • Small data logging
EEPROM Operations Example
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()

Safety Features

Intelligent failsafe system and safety mechanisms to prevent hardware damage and ensure reliable operation.

Smart Failsafe

Multi-stage failsafe system with intelligent activation and instant recovery.

  • • 30-second total timeout
  • • Query-safe operations
  • • Instant recovery
  • • Manual control

Pin Validation

Automatic pin capability checking and mode validation.

  • • Capability detection
  • • Mode validation
  • • Error prevention
  • • Safe defaults

Error Handling

Comprehensive error handling with detailed feedback and recovery.

  • • Detailed error messages
  • • Automatic retry logic
  • • Connection monitoring
  • • Graceful degradation

Failsafe System Details

Activation Conditions

  • Only activates after output commands (MODE OUT, WRITE, PWM, etc.)
  • Query commands (IDENTIFY, VERSION, READ) don't trigger failsafe
  • 30-second total timeout (10s warning + 20s grace period)

Recovery Process

  • Any command immediately disengages failsafe
  • All configured pins reset to INPUT mode for safety
  • Detailed logging of reset operations