KrakenKodersLights/README.md

209 lines
No EOL
7.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# D1 Mini Blinkin LED Driver Emulator
This project allows a D1 Mini (ESP8266) to emulate a REV Blinkin LED Driver, enabling control of WS2812B LED strips via PWM signals from an FTC robot's REV Control Hub or Expansion Hub.
## Features
- **Full Blinkin Pattern Support**: Emulates 100+ Blinkin patterns including solid colors, animations, and effects
- **PWM Signal Input**: Reads standard servo PWM signals (900-2100 microseconds)
- **60 LED Support**: Configured for 60 WS2812B LEDs (adjustable in code)
- **FastLED Library**: High-performance LED control with color correction
- **Debug Mode**: Serial output for troubleshooting PWM values and patterns
- **No WiFi**: WiFi disabled to save power and improve performance
## Hardware Requirements
- D1 Mini (ESP8266) or compatible board
- WS2812B LED strip (60 LEDs default, adjustable)
- Voltage divider circuit (5V to 3.3V for PWM input)
- 5V power supply capable of 3-4A for 60 LEDs
- REV Control Hub or Expansion Hub
## Wiring Connections
### PWM Signal Input (from REV Hub Servo Port)
**IMPORTANT**: The REV Hub outputs 5V PWM signals. The D1 Mini requires 3.3V input. You MUST use a voltage divider!
```
REV Hub Servo Port | Voltage Divider | D1 Mini
-------------------|-----------------|----------
Signal (White) | Input → Output | D2 (GPIO4)
Power (Red) | - | 5V
Ground (Black) | - | GND
```
### Voltage Divider Circuit
```
REV PWM Signal (5V) ──┬── R1 (2.2kΩ) ──┬── To D1 Mini D2
│ │
│ R2 (3.3kΩ)
│ │
GND ───────────────┴── GND
```
### LED Strip Connection
```
D1 Mini Pin | LED Strip | Description
-------------|--------------|-------------
D4 (GPIO2) | Data In | LED data signal
5V | 5V | Power (use external supply)
GND | GND | Ground
```
**Power Note**: For 60 LEDs at full brightness, current draw can reach 3.6A. Use an external 5V power supply, not the REV Hub's servo power.
## Software Setup
### Method 1: PlatformIO (Recommended)
1. Install [Visual Studio Code](https://code.visualstudio.com/)
2. Install PlatformIO IDE extension
3. Clone this repository
4. Open project folder in VS Code
5. Connect D1 Mini via USB
6. Click PlatformIO: Upload (→) in the bottom toolbar
### Method 2: Arduino IDE
1. Install [Arduino IDE](https://www.arduino.cc/en/software)
2. Add ESP8266 Board Support:
- File → Preferences → Additional Board Manager URLs:
- Add: `http://arduino.esp8266.com/stable/package_esp8266com_index.json`
- Tools → Board → Board Manager → Search "ESP8266" → Install
3. Install FastLED Library:
- Tools → Manage Libraries → Search "FastLED" → Install
4. Select Board: Tools → Board → "LOLIN(WEMOS) D1 R2 & mini"
5. Open `src/main.cpp` and upload
## FTC Robot Configuration
### Hardware Configuration
1. Connect the voltage divider output to a servo port on the REV Hub
2. In the Robot Controller app, configure the servo in your hardware map
3. Name it something meaningful like "blinkin" or "ledDriver"
### Example FTC Java Code
```java
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
public class BlinkinExample extends LinearOpMode {
private Servo blinkin;
@Override
public void runOpMode() {
// Initialize
blinkin = hardwareMap.get(Servo.class, "blinkin");
// Set to solid red (pattern value from Blinkin manual)
blinkin.setPosition(0.61); // Solid Red
waitForStart();
while (opModeIsActive()) {
// Alliance color selection
if (gamepad1.x) {
blinkin.setPosition(0.87); // Solid Blue
} else if (gamepad1.b) {
blinkin.setPosition(0.61); // Solid Red
} else if (gamepad1.a) {
blinkin.setPosition(0.77); // Solid Green
} else if (gamepad1.y) {
blinkin.setPosition(0.93); // Solid White
}
// Special effects
if (gamepad1.left_bumper) {
blinkin.setPosition(0.41); // Rainbow
}
if (gamepad1.right_bumper) {
blinkin.setPosition(0.43); // Confetti
}
}
}
}
```
### Common Blinkin Pattern Values
| Pattern | Servo Position | PWM (μs) | Description |
|---------|---------------|----------|-------------|
| Rainbow | 0.41 | 1005 | Rainbow palette |
| Confetti | 0.43 | 1015 | Random colored pixels |
| Red Shot | 0.53 | 1065 | Red chase pattern |
| Blue Shot | 0.54 | 1075 | Blue chase pattern |
| Red | 0.61 | 1505 | Solid red |
| Orange | 0.65 | 1535 | Solid orange |
| Yellow | 0.69 | 1555 | Solid yellow |
| Green | 0.77 | 1595 | Solid green |
| Blue | 0.87 | 1645 | Solid blue |
| Violet | 0.91 | 1665 | Solid violet |
| White | 0.93 | 1675 | Solid white |
| Black/Off | 0.99 | 1695 | All LEDs off |
## Configuration
Edit these values in `src/main.cpp`:
```cpp
#define NUM_LEDS 60 // Number of LEDs in your strip
#define BRIGHTNESS 100 // Brightness (0-255)
#define DEBUG_MODE true // Serial debug output
```
## Testing & Debugging
1. **Serial Monitor**: Connect via USB and open serial monitor at 115200 baud
- Shows current PWM value and selected pattern
- Displays startup messages and status
2. **LED Test**: On startup, a green sweep animation indicates the system is ready
3. **Manual PWM Test**: Use a servo tester to send PWM signals and verify pattern changes
## Troubleshooting
### LEDs not lighting up
- Check 5V power supply (must provide sufficient current)
- Verify D4 (GPIO2) is connected to LED data line
- Confirm ground connections between all components
### Wrong patterns displaying
- Verify voltage divider is working (PWM signal must be ~3.3V)
- Check serial monitor for PWM values (should be 900-2100μs)
- Ensure servo position in FTC code is between 0.0 and 1.0
### Erratic behavior
- Add a 1000μF capacitor across LED power lines
- Add a 470Ω resistor between D4 and LED data
- Ensure all grounds are connected together
### Pattern doesn't match Blinkin
- Some complex patterns may differ slightly from original Blinkin
- Adjust PWM thresholds in `pwmToPattern()` function if needed
## Power Calculations
- Each WS2812B LED: ~60mA at full white brightness
- 60 LEDs × 60mA = 3.6A maximum
- With brightness set to 100/255: ~1.4A typical
- D1 Mini consumption: ~80mA
- **Recommended PSU: 5V 4A minimum**
## Build Guide Documentation
Additional documentation is available:
- [INSTALLATION_GUIDE.md](INSTALLATION_GUIDE.md) - Detailed setup instructions
- [VOLTAGE_DIVIDER_BUILD_GUIDE.md](VOLTAGE_DIVIDER_BUILD_GUIDE.md) - How to build the voltage divider
- [VOLTAGE_DIVIDER_ALTERNATIVES.md](VOLTAGE_DIVIDER_ALTERNATIVES.md) - Alternative protection methods
- [QUICK_FLASH_GUIDE.md](QUICK_FLASH_GUIDE.md) - Quick programming reference
## License
This project is open source and available for FTC teams to use and modify.
## Credits
Created for Kraken Koders FTC Team
Based on REV Blinkin LED Driver patterns and functionality