# WiFiX-Enhanced Complete Pin Chart

## 📋 Quick Reference Table

### ESP32 DevKit Pin Assignments

| Function | GPIO | Physical Pin | Description | Connected To |
|----------|------|--------------|-------------|---------------|
| **I2C OLED Display** |
| OLED SDA | 21 | D21 | I2C Data | OLED SDA |
| OLED SCL | 22 | D22 | I2C Clock | OLED SCL |
| OLED VCC | 3.3V | 3V3 | 3.3V Power | OLED VCC |
| OLED GND | GND | GND | Ground | OLED GND |
| **SPI SD Card Module** |
| SD MOSI | 23 | D23 | SPI Master Out | SD MOSI |
| SD MISO | 19 | D19 | SPI Master In | SD MISO |
| SD CLK | 18 | D18 | SPI Clock | SD CLK |
| SD CS | 5 | D5 | Chip Select | SD CS |
| SD VCC | 3.3V | 3V3 | 3.3V Power | SD VCC |
| SD GND | GND | GND | Ground | SD GND |
| **BW16 Module UART** |
| BW16 TX | 17 | TX2 | UART Transmit | BW16 RX |
| BW16 RX | 16 | RX2 | UART Receive | BW16 TX |
| BW16 GND | GND | GND | Common Ground | BW16 GND |
| **Status LED (Optional)** |
| STATUS LED | 2 | D2 | Built-in LED | Onboard LED |
| **Power & Ground** |
| 3.3V Power | 3.3V | 3V3 | 3.3V Output | Modules |
| Ground | GND | GND | Ground | Common Ground |

## 🔧 Detailed Wiring Diagrams

### ESP32 DevKit V1 (30-pin) Layout
```
┌─────────────────────────────────────┐
│         ESP32 DevKit V1            │
├─────────────────────────────────────┤
│ 3.3V  [●] [ ]  VIN                 │
│ GND   [●] [ ]  GND                 │
│ D35   [ ] [ ]  D23  → SD MOSI      │
│ D32   [ ] [ ]  D22  → OLED SCL     │
│ D33   [ ] [ ]  D21  → OLED SDA     │
│ D25   [ ] [ ]  D19  → SD MISO      │
│ D26   [ ] [ ]  D18  → SD CLK       │
│ D27   [ ] [ ]  D5   → SD CS        │
│ D14   [ ] [ ]  D17  → BW16 TX      │
│ D12   ] [ ] [ ]  D16  → BW16 RX    │
│ GND   [●] [ ]  D4                  │
│ D13   [ ] [●]  D2   → STATUS LED   │
│ D9    [ ] [ ]  D15                 │
│ D10   [ ] [ ]  D8                  │
│ D11   [ ] [ ]  D7                  │
│ 3.3V  [●] [ ]  GND                 │
│ EN    [●] [ ]  5V                  │
└─────────────────────────────────────┘
```

### OLED Display (128x64 I2C SSD1306)
```
┌─────────────────────────────────────┐
│         OLED Display               │
├─────────────────────────────────────┤
│ VCC   [●] ──→ 3.3V (ESP32)        │
│ GND   [●] ──→ GND (ESP32)         │
│ SCL   [●] ──→ GPIO22 (ESP32)       │
│ SDA   [●] ──→ GPIO21 (ESP32)       │
└─────────────────────────────────────┘
```

### SD Card Module (SPI)
```
┌─────────────────────────────────────┐
│         SD Card Module             │
├─────────────────────────────────────┤
│ VCC   [●] ──→ 3.3V (ESP32)        │
│ GND   [●] ──→ GND (ESP32)         │
│ MISO  [●] ←── GPIO19 (ESP32)       │
│ MOSI  [●] ──→ GPIO23 (ESP32)       │
│ SCK   [●] ──→ GPIO18 (ESP32)       │
│ CS    [●] ──→ GPIO5 (ESP32)        │
└─────────────────────────────────────┘
```

### BW16 Module Pinout
```
┌─────────────────────────────────────┐
│         BW16 Module                │
├─────────────────────────────────────┤
│ 3.3V  [●] ──→ 3.3V (ESP32)        │
│ GND   [●] ──→ GND (ESP32)         │
│ TX    [●] ──→ GPIO16 (ESP32 RX)   │
│ RX    [●] ←── GPIO17 (ESP32 TX)   │
│ EN    [●] ──→ 3.3V (Pull-high)   │
│ RST   [●] ──→ NC (Optional)      │
└─────────────────────────────────────┘
```

## 🎯 Step-by-Step Wiring Instructions

### Phase 1: Power Connections
1. **ESP32 Power**
   - Connect ESP32 3.3V to breadboard positive rail
   - Connect ESP32 GND to breadboard negative rail

2. **Common Ground**
   - Ensure all modules share common ground with ESP32

### Phase 2: I2C OLED Display
1. **OLED VCC** → ESP32 3.3V
2. **OLED GND** → ESP32 GND
3. **OLED SDA** → ESP32 GPIO21 (Pin 21)
4. **OLED SCL** → ESP32 GPIO22 (Pin 22)

### Phase 3: SPI SD Card Module
1. **SD VCC** → ESP32 3.3V
2. **SD GND** → ESP32 GND
3. **SD MOSI** → ESP32 GPIO23 (Pin 23)
4. **SD MISO** → ESP32 GPIO19 (Pin 19)
5. **SD CLK** → ESP32 GPIO18 (Pin 18)
6. **SD CS** → ESP32 GPIO5 (Pin 5)

### Phase 4: BW16 UART Connection
1. **BW16 VCC** → ESP32 3.3V
2. **BW16 GND** → ESP32 GND
3. **BW16 TX** → ESP32 GPIO16 (Pin 16)
4. **BW16 RX** → ESP32 GPIO17 (Pin 17)

### Phase 5: Optional Components
1. **Status LED**: Already on ESP32 GPIO2 (built-in)
2. **External Antenna**: Connect to BW16 antenna connector
3. **Reset Button**: Optional connection to ESP32 EN pin

## 🔍 Verification Steps

### 1. Continuity Test
```
Test with multimeter:
✓ ESP32 GND to all module GNDs
✓ ESP32 3.3V to all module VCCs
✓ Individual signal connections
```

### 2. Power-On Test
```
1. Connect USB to ESP32
2. Check 3.3V rail with multimeter
3. Verify no short circuits
4. Check current draw (<200mA normal)
```

### 3. Communication Test
```
# Serial Monitor Commands
help          # Should show system info
status        # Should show all modules detected
oled test     # Should display test pattern
sd test       # Should detect SD card
```

## ⚠️ Important Notes

### Power Supply Requirements
- **ESP32**: 3.3V @ 500mA minimum
- **BW16**: 3.3V @ 300mA peak
- **OLED**: 3.3V @ 20mA
- **SD Card**: 3.3V @ 100mA peak
- **Total**: 3.3V @ 1A recommended

### Signal Level Compatibility
- All modules are 3.3V logic level
- **DO NOT** connect 5V directly to ESP32 pins
- Use level shifters if interfacing with 5V devices

### Cable Length Considerations
- **I2C (OLED)**: Max 30cm at 100kHz
- **SPI (SD Card)**: Max 10cm at 8MHz
- **UART (BW16)**: Max 50cm at 115200 baud

### Troubleshooting Connections

#### OLED Not Displaying
```
1. Check I2C address (usually 0x3C)
2. Verify SDA/SCL not swapped
3. Test with I2C scanner sketch
4. Check pull-up resistors (4.7kΩ if needed)
```

#### SD Card Not Detected
```
1. Verify SPI connections
2. Check CS pin configuration
3. Test with different SD card
4. Format SD card as FAT32
5. Check power supply stability
```

#### BW16 Not Responding
```
1. Verify UART connections (TX→RX, RX→TX)
2. Check baud rate (115200)
3. Test with serial loopback
4. Verify BW16 firmware is loaded
5. Check antenna connection
```

## 📊 Pin Usage Summary

### Used GPIOs (ESP32)
- **GPIO5**: SD Card CS
- **GPIO16**: BW16 UART RX
- **GPIO17**: BW16 UART TX
- **GPIO18**: SD Card CLK
- **GPIO19**: SD Card MISO
- **GPIO21**: OLED SDA
- **GPIO22**: OLED SCL
- **GPIO23**: SD Card MOSI

### Available GPIOs (Free)
- **GPIO0-4, 12-15, 25-27, 32-33**: Available for expansion

### Special Pins
- **GPIO2**: Built-in LED (status indicator)
- **GPIO6-11**: Connected to flash (avoid using)
- **GPIO34-39**: Input only (no output capability)

## 🔧 Expansion Options

### Additional Modules (Free Pins)
```
GPIO0  → Button (boot mode)
GPIO4  → Sensor input
GPIO13 → Additional LED
GPIO15 → Buzzer
GPIO25 → Relay control
GPIO26 → PWM output
GPIO27 → Additional UART
GPIO32 → Capacitive touch
GPIO33 → Analog input
```

### I2C Expansion
```
Current: OLED on GPIO21/22
Available addresses: 0x20-0x27 (GPIO expander)
Available addresses: 0x40-0x4F (PWM driver)
Available addresses: 0x48-0x57 (ADC/DAC)
```

---

**Remember**: Double-check all connections before powering on. Use a multimeter to verify continuity and proper voltage levels.