Software Troubleshooting¶
Solutions for software and code-related issues.
Compilation Errors¶
Library Not Found¶
Error: fatal error: xxx.h: No such file or directory
Solutions: 1. Install the library:
- Check library name spelling
- Case-sensitive on Linux
-
Example:
LiquidCrystal_I2Cnotliquidcrystal_i2c -
Verify library installed:
Multiple Libraries Found¶
Error: Multiple libraries were found for "xxx.h"
Solutions: 1. Remove duplicate libraries - Check Documents/Arduino/libraries/ - Delete old versions - Keep only latest version
- Specify which library to use:
Redefinition Errors¶
Error: redefinition of 'xxx'
Causes: - Variable defined in multiple files - Function declared twice - Header guard missing
Solutions:
// In header files, use include guards
#ifndef MY_HEADER_H
#define MY_HEADER_H
// ... declarations ...
#endif
// Or use pragma once
#pragma once
// ... declarations ...
Out of Memory¶
Error: region dram0_1_seg' overflowed or Not enough memory
Solutions: 1. Reduce buffer sizes
-
Use PSRAM (if available)
-
Minimize string usage
-
Enable memory optimization
Upload Errors¶
Upload Failed¶
Error: Failed to connect to ESP32
Solutions: 1. Hold BOOT button, press RESET, release BOOT 2. Check USB cable (must be data cable) 3. Verify correct COM port selected 4. Install USB drivers 5. Try different USB port
Wrong Boot Mode¶
Error: Wrong boot mode detected or boot mode:(3,0)
Cause: GPIO0 not LOW during upload
Solutions: - Press and hold BOOT button during entire upload - Or use auto-reset circuit
Serial Port Not Found¶
Error: Port not in Tools → Port menu
Solutions: 1. Install drivers: - CP210x: Download - CH340: Usually auto-installs
- Check device manager (Windows)
- Look for unknown devices
-
Update driver
-
Linux: Add user to dialout group
Runtime Errors¶
Watchdog Timeout¶
Error: Task watchdog got triggered or Guru Meditation Error
Solutions: 1. Add yields in long loops
-
Use delay() instead of busy-wait
-
Run heavy tasks on Core 0
Null Pointer Exception¶
Error: LoadProhibited or crash at address 0x00000000
Solutions: 1. Check pointer initialization
- Verify object creation
Stack Overflow¶
Error: Stack smashing protect failure!
Solutions: 1. Reduce local variable sizes 2. Avoid recursion 3. Increase stack size (if needed)
WiFi Issues¶
Won't Connect¶
Symptoms: WiFi.status() never returns WL_CONNECTED
Solutions: 1. Check credentials
// Verify exact SSID and password
Serial.println(ssid); // Should match router exactly
Serial.println(password); // Check special characters
-
Check 2.4GHz network
-
Add connection retry
Frequent Disconnections¶
Symptoms: WiFi connects but drops frequently
Solutions: 1. Set WiFi power saving mode
-
Check RSSI
-
Add auto-reconnect
MQTT Issues¶
Connection Failed¶
Error: failed, rc=-2 or rc=-4
Solutions: 1. Check WiFi first
-
Verify broker address
-
Check port
Authentication Failed¶
Error: failed, rc=5
Solutions: 1. Check credentials
-
Verify client ID is unique
-
Check broker allows anonymous
Messages Not Published¶
Symptoms: client.publish() returns false
Solutions: 1. Check connection first
-
Verify topic format
-
Check payload size
I2C Issues¶
Bus Lockup¶
Symptoms: I2C stops responding, devices not detected
Solutions: 1. Reset I2C bus
- Check for stuck devices
- Add timeout
Debugging Techniques¶
Enable Verbose Output¶
Add Debug Prints¶
#define DEBUG 1
#if DEBUG
#define DPRINT(x) Serial.println(x)
#else
#define DPRINT(x)
#endif
// Usage:
DPRINT("Entering function X");
DPRINT(String("Value: ") + value);
Stack Trace Decoding¶
For Guru Meditation errors: 1. Note the exception and address 2. Use ESP Exception Decoder tool 3. Or use xtensa-esp32-elf-addr2line command
Common Mistakes¶
| Mistake | Correct |
|---|---|
String + int | String + String(int) |
Missing yield() | Add in long loops |
| GPIO 6-11 usage | Use GPIO 0-5, 12-15, 18-21, 25-27, 32-33 |
| String in loops | Use char[] or const char* |
| No null checks | Verify pointers before use |
| Deep sleep without wake source | Configure timer or GPIO |