ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β iMac Dimmer Ubuntu v1.7.0 β
β β
β π Advanced ESP32-C3 Brightness Control with Dynamic IP Discovery β
β β
β β¨ Features: β
β β’ Zero-maintenance network discovery β’ Professional web interface β
β β’ mDNS hostname support (*.local) β’ Complete system integration β
β β’ HTTP API with fallback mechanisms β’ Keyboard shortcuts & automation β
β β
β π§ Hardware: ESP32-C3 SuperMini | π Protocol: HTTP + mDNS + WiFi β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
A comprehensive solution for controlling iMac display brightness using ESP32-C3 with automatic network adaptation, multiple communication methods, and robust failover mechanisms.
βββββββββββββββββββ WiFi ββββββββββββββββββββ PWM βββββββββββββββββββ
β Ubuntu PC ββββββββββββββΊβ ESP32-C3 Mini ββββββββββββΊβ iMac Display β
β β β β β Brightness β
β β’ Python Script β β β’ Web Interface β β Control β
β β’ Keyboard β β β’ HTTP API β β β
β β’ Systemd β β β’ mDNS Service β β β
β β’ Web Browser β β β’ Version Track β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
β HTTP API β imacdimmer.local
β imacdisplay.py -s 70 β http://imacdimmer.local
β β
βββββββββββββββββββββββββββββββββ
- mDNS hostname: Access via
imacdimmer.local- no IP needed - Automatic IP discovery: Finds ESP32 even when network changes
- Multi-layer fallback: MAC detection, network scanning, cached addresses
- Zero maintenance: Works across router reboots and DHCP changes
- HTTP-based control: Robust web API with
/serialendpoint - Modern web interface: Real-time brightness control with presets
- ESP32-C3 compatible: Bypasses bootloader serial communication issues
- Version tracking: Firmware verification and update management
- Keyboard shortcuts: System-wide hotkey support
- Systemd service: Background brightness restoration
- Auto-dimmer: Automatic brightness reduction after idle time
- Timer automation: Scheduled brightness adjustments
- Configuration caching: Performance optimization with smart defaults
- ESP32-C3 SuperMini Board (shown above)
- PCI-E 6-pin extension cable or splitter (to intercept PWM signal)
- USB cable for ESP32
- Basic soldering equipment
- Wire connectors (optional, for easier connections)
-
Access the LCD Driver Board
- Open the iMac and locate the LCD driver board
- Identify the PCI-E 6-pin cable connected to the LCD
-
Intercept the PWM Signal
- Cut the PWM wire on your extension cable (typically bottom right pin)
- Connect the PWM wire to GPIO3 on the ESP32
- Ensure proper grounding between ESP32 and iMac
-
Connect the ESP32
- Connect ESP32 to a USB port for power and programming
- Use GPIO3 for PWM output (brightness control)
- GPIO8 is used for status LED
-
Additional Setup
- Install
mbpfanfor fan control:sudo apt install mbpfan - This prevents fan issues when intercepting the PWM signal
- Install
- Microcontroller: ESP32-C3 (160MHz, 320KB RAM)
- Flash Memory: 4MB
- WiFi: 802.11 b/g/n (2.4GHz)
- USB: USB-C for programming and power
- Size: Ultra-compact form factor
- GPIO: 13 digital I/O pins
- PWM Output: GPIO3 (10kHz, 8-bit resolution)
iMacDimmerUbuntu/
βββ src/
β βββ main.cpp # ESP32 firmware v1.7.0
βββ scripts/
β βββ imacdisplay_http.py # Smart discovery Python script
β βββ auto_dimmer.py # Automatic idle-time brightness dimmer
β βββ test_auto_dimmer.py # Auto-dimmer testing suite
β βββ ping_test.py # Network connectivity tests
β βββ hybrid_test.py # Communication diagnostics
βββ systemd/
β βββ brightness.service # System service configuration
β βββ auto-dimmer.service # Auto-dimmer service configuration
βββ DYNAMIC_IP_SOLUTION.md # Detailed technical documentation
βββ final_install.sh # Automated installation script
βββ install_auto_dimmer.sh # Auto-dimmer installation script
βββ platformio.ini # PlatformIO build configuration
βββ README.md # This file
# Clone and install everything automatically
git clone https://github.com/doobidoo/iMacDimmerUbuntu.git
cd iMacDimmerUbuntu
# Set up WiFi credentials
cp .env.example .env
# Edit .env with your WiFi credentials
./final_install.shThe installation script will:
- β Test ESP32 connectivity
- β Configure optimal communication method
- β Install system scripts with dynamic discovery
- β Set up systemd service
- β Verify complete functionality
# Set up WiFi credentials first
cp .env.example .env
# Edit .env with your WiFi SSID and password
# Build and upload v1.7.0 firmware
~/.platformio/penv/bin/platformio run --target upload# Option A: Use mDNS hostname (recommended)
python3 scripts/imacdisplay_http.py --ip imacdimmer.local
# Option B: Auto-discover ESP32
python3 scripts/imacdisplay_http.py --discover
# Option C: Manual IP configuration
python3 scripts/imacdisplay_http.py --ip 192.168.1.100# Install system script
sudo cp scripts/imacdisplay_http.py /usr/local/bin/imacdisplay.py
sudo chmod +x /usr/local/bin/imacdisplay.py
# Install and start service
sudo cp systemd/brightness.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable brightness.service
sudo systemctl start brightness.service# Brightness control
imacdisplay.py -s 70 # Set to 70%
imacdisplay.py -g # Get current brightness
imacdisplay.py -i 10 # Increase by 10%
imacdisplay.py -d 10 # Decrease by 10%
# System diagnostics
imacdisplay.py -v # Get firmware version
imacdisplay.py --ping # Test ESP32 connectivity
imacdisplay.py --discover # Find and save ESP32 location
# Network configuration
imacdisplay.py --ip imacdimmer.local # Use hostname
imacdisplay.py --ip 192.168.1.27 # Use specific IP| π Access Methods | ποΈ Interface Features |
β’ http://imacdimmer.local (recommended)β’ http://[ESP32-IP-ADDRESS]β’ Auto-discovery enabled |
β’ ποΈ Real-time brightness slider β’ π― Quick preset buttons (5%, 20%, 50%, 70%, 100%) β’ π System information display β’ π‘ WiFi status and signal strength β’ π Firmware version verification |
Configure in your desktop environment:
| Action | Command |
|---|---|
| Brightness Up | imacdisplay.py -i 10 |
| Brightness Down | imacdisplay.py -d 10 |
| Preset Dim | imacdisplay.py -s 20 |
| Preset Bright | imacdisplay.py -s 80 |
Automatically dims the display after a period of inactivity:
# Install and test auto-dimmer
./install_auto_dimmer.sh
# Test functionality safely
python3 scripts/test_auto_dimmer.py
# Manual control options
auto_dimmer.py --minutes 10 --level 5 # Dim to 5% after 10 minutes
auto_dimmer.py --status # Show current status
auto_dimmer.py --test # Test idle detection
# Enable as system service
sudo systemctl enable auto-dimmer.service
sudo systemctl start auto-dimmer.serviceAuto-Dimmer Features:
- π Configurable idle timeout (default: 10 minutes)
- π Safe minimum brightness (default: 5%, never completely dark)
- π Activity detection (restores brightness when user returns)
- πΎ Configuration persistence (remembers settings)
- π Graceful recovery (restores brightness on shutdown)
WiFi credentials are now managed through environment variables for security:
-
Create a
.envfile in the project root:cp .env.example .env
-
Edit
.envwith your WiFi credentials:WIFI_SSID=YourWiFiNetwork WIFI_PASSWORD=YourWiFiPassword -
Build and flash - credentials are injected at build time:
~/.platformio/penv/bin/platformio run --target upload
Note: The .env file is gitignored to prevent accidental credential exposure.
The system automatically tries (in order):
- mDNS Hostname:
imacdimmer.local - Cached Address: Last known working connection
- ARP Table Scan: ESP32 MAC address detection
- Network Discovery: Intelligent local network scanning
- Manual Configuration: User-specified addresses
- β
Credentials stored in
.envfile (not in source code) - β Environment variables injected at build time
- β
.envfile excluded from git repository - β
Example template provided (
.env.example)
Important: If you've previously committed credentials to git, change your WiFi password immediately as git history retains old commits.
- β Minimum brightness enforcement (5%)
- β Safe startup brightness (70%)
- β PWM output protection
- β Status LED feedback
- β Automatic WiFi reconnection
- β mDNS service registration
- β HTTP communication redundancy
- β Configuration caching and recovery
- β Systemd service with auto-restart
- β Background brightness restoration
- β Non-blocking communication timeouts
- β Graceful degradation on failures
# Test ESP32 discovery
python3 scripts/hybrid_test.py
# Test hostname resolution
ping imacdimmer.local
# Manual connectivity test
curl http://imacdimmer.local/version# Check service status
systemctl status brightness.service
# View service logs
journalctl -u brightness.service -f
# Restart service
sudo systemctl restart brightness.service# Check web interface
curl http://imacdimmer.local/version
# Verify firmware version
python3 scripts/imacdisplay_http.py -v
# Re-flash firmware if needed
~/.platformio/penv/bin/platformio run --target upload- Home networks with standard routers
- Networks with mDNS/Bonjour support
- Standard DHCP configurations
- Multi-VLAN setups with local access
- Corporate networks with mDNS blocked
- Networks with restricted ARP access
- Very strict firewall configurations
Workaround: Use manual IP configuration:
imacdisplay.py --ip [actual-esp32-ip]The ESP32 provides a RESTful API:
# Version information
GET /version
# WiFi and system status
GET /wifistatus
# Serial command emulation
GET /serial?cmd=version
GET /serial?cmd=get
GET /serial?cmd=50
# LED control
GET /led?pin=8&state=1
# Direct brightness control
GET /brightness?level=128Settings are automatically cached in ~/.config/imacdisplay.conf:
{
"esp32_ip": "imacdimmer.local",
"last_brightness": 70
}| Component | Specification |
|---|---|
| Microcontroller | ESP32-C3 (160MHz, 320KB RAM) |
| WiFi | 802.11 b/g/n, 2.4GHz |
| PWM Output | GPIO3, 10kHz frequency, 8-bit resolution |
| Communication | HTTP/1.1, mDNS, WebSocket ready |
| Power | USB-C, 3.3V operation |
| Flash Memory | 4MB with OTA support |
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly with
python3 scripts/hybrid_test.py - Submit a pull request
This project is open source. See the repository for license details.
- PCI-E 6-pin Pinout: Standard pinout for LCD driver connections
- PWM Signal Location: Bottom right pin on the 6-pin connector
- Detailed Wiring Guide: iMac GPU Upgrade & ESP32 PWM Brightness Fix
- Always disconnect power before working on hardware
- Use proper grounding to prevent static damage
- The PWM signal is typically 3.3V compatible
- Test connections before final assembly
- ESP32 Community: For comprehensive hardware support
- PlatformIO: For excellent development environment
- mDNS/Avahi: For network service discovery
- mbpfan Project: For iMac fan control solution
π Links
- Repository: github.com/doobidoo/iMacDimmerUbuntu
- Technical Details: DYNAMIC_IP_SOLUTION.md
- Latest Release: v1.7.0
- Hardware Wiring Guide: Medium Article by @fixingthings
Built with β€οΈ for the ESP32 and open source communities
