bookmark - working ethernet.
This commit is contained in:
165
README.md
Normal file
165
README.md
Normal file
@@ -0,0 +1,165 @@
|
||||
# Barnum - RP2040-ETH WS2812 Network Control
|
||||
|
||||
A network-controllable WS2812 LED system built on the Waveshare RP2040-ETH board. Control LED colors over ethernet using simple TCP commands.
|
||||
|
||||
## Features
|
||||
|
||||
- **Network Control**: TCP server accepting color commands over ethernet
|
||||
- **Visual Feedback**:
|
||||
- Green flash every 1s (firmware alive indicator)
|
||||
- Amber flash on network traffic (RX/TX activity)
|
||||
- Smooth color transitions between commands
|
||||
- **Real-time Response**: Immediate color changes with network acknowledgments
|
||||
- **Debug Output**: Comprehensive serial logging for troubleshooting
|
||||
|
||||
## Hardware
|
||||
|
||||
- **Board**: Waveshare RP2040-ETH
|
||||
- **LED**: WS2812/NeoPixel connected to GPIO 25
|
||||
- **Ethernet**: CH9120 chip with built-in TCP/IP stack
|
||||
- **Power**: USB-C for programming, external power for LED strips
|
||||
|
||||
## Pin Configuration
|
||||
|
||||
| Function | GPIO | Description |
|
||||
|----------|------|-------------|
|
||||
| WS2812 Data | 25 | LED strip data line |
|
||||
| UART TX (CH9120) | 20 | Serial to ethernet chip |
|
||||
| UART RX (CH9120) | 21 | Serial from ethernet chip |
|
||||
| CFG (CH9120) | 18 | Configuration mode pin |
|
||||
| RES (CH9120) | 19 | Reset pin for ethernet chip |
|
||||
|
||||
## Network Configuration
|
||||
|
||||
- **IP Address**: 192.168.1.201
|
||||
- **Subnet Mask**: 255.255.0.0
|
||||
- **Gateway**: 192.168.1.1
|
||||
- **Mode**: TCP Server
|
||||
- **Port**: 1000
|
||||
|
||||
## Supported Commands
|
||||
|
||||
Send these as TCP messages to port 1000:
|
||||
|
||||
| Command | Effect |
|
||||
|---------|--------|
|
||||
| `RED` | Set LED to red |
|
||||
| `GREEN` | Set LED to green |
|
||||
| `BLUE` | Set LED to blue |
|
||||
| `WHITE` | Set LED to white |
|
||||
| `OFF` | Turn LED off |
|
||||
| `RGB:r,g,b` | Custom color (e.g., `RGB:255,128,0` for orange) |
|
||||
|
||||
## Building
|
||||
|
||||
```bash
|
||||
# Setup (first time)
|
||||
git clone <this-repo>
|
||||
cd barnum
|
||||
|
||||
# Build
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make barnum
|
||||
|
||||
# Flash
|
||||
# 1. Hold BOOTSEL button on RP2040-ETH
|
||||
# 2. Connect USB-C cable
|
||||
# 3. Copy barnum.uf2 to RPI-RP2 drive
|
||||
# 4. Board reboots automatically
|
||||
```
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Python Client
|
||||
```python
|
||||
import socket
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect(('192.168.1.201', 1000))
|
||||
sock.send(b'RED')
|
||||
response = sock.recv(1024)
|
||||
print(response.decode()) # "Setting color to R:255 G:0 B:0"
|
||||
sock.close()
|
||||
```
|
||||
|
||||
### Command Line
|
||||
```bash
|
||||
# Test with netcat
|
||||
echo "BLUE" | nc 192.168.1.201 1000
|
||||
|
||||
# Test with included Python client
|
||||
python3 test_client.py GREEN
|
||||
python3 test_client.py "RGB:255,0,255"
|
||||
```
|
||||
|
||||
### Network Testing
|
||||
```bash
|
||||
# Basic connectivity
|
||||
ping 192.168.1.201
|
||||
|
||||
# Port scan
|
||||
python3 test_ethernet.py
|
||||
|
||||
# Network discovery
|
||||
python3 network_scan.py
|
||||
```
|
||||
|
||||
## Visual Indicators
|
||||
|
||||
1. **Startup**: 3 blue flashes (ethernet initialization)
|
||||
2. **Alive**: Green flash every 1 second (firmware running)
|
||||
3. **Traffic**: Amber flash on network activity
|
||||
4. **Commands**: Smooth color transitions to target colors
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
barnum/
|
||||
├── barnum.c # Main application (network + LED control)
|
||||
├── barnum-initial.c # Original LED cycling demo
|
||||
├── ch9120.c/.h # CH9120 ethernet chip driver
|
||||
├── ws2812.pio # PIO program for WS2812 timing
|
||||
├── CMakeLists.txt # Build configuration
|
||||
├── test_client.py # Python test client
|
||||
├── test_ethernet.py # Network diagnostics
|
||||
├── network_scan.py # Network discovery tool
|
||||
├── README_ETH.md # Ethernet implementation details
|
||||
└── rp-2040.md # Hardware documentation
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### No Network Connectivity
|
||||
1. Check ethernet cable connection
|
||||
2. Verify green/amber LEDs on RJ45 connector
|
||||
3. Monitor serial output for configuration errors
|
||||
4. Ensure IP settings match your network
|
||||
|
||||
### LED Not Responding
|
||||
1. Verify WS2812 connection to GPIO 25
|
||||
2. Check power supply to LED strip
|
||||
3. Look for "Received command" in serial output
|
||||
|
||||
### Build Issues
|
||||
1. Ensure Pico SDK is properly installed
|
||||
2. Check board type in CMakeLists.txt
|
||||
3. Verify pico_sdk_import.cmake is present
|
||||
|
||||
## Development Notes
|
||||
|
||||
- Built with Pico SDK 2.1.1
|
||||
- Uses PIO for precise WS2812 timing
|
||||
- CH9120 handles TCP/IP stack entirely
|
||||
- Dual-core RP2040 allows concurrent LED/network operations
|
||||
- Serial debug output at 115200 baud
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- Multiple LED support
|
||||
- Animation patterns
|
||||
- Web interface
|
||||
- MQTT integration
|
||||
- Color persistence
|
||||
- Network configuration via commands
|
||||
149
ai.recreate.md
Normal file
149
ai.recreate.md
Normal file
@@ -0,0 +1,149 @@
|
||||
# AI Recreation Instructions
|
||||
|
||||
This document contains instructions for an AI assistant to recreate the Barnum project from scratch.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Create a network-controllable WS2812 LED system using the Waveshare RP2040-ETH board. The system should accept TCP commands over ethernet to control LED colors with visual feedback indicators.
|
||||
|
||||
## Hardware Requirements
|
||||
|
||||
- Waveshare RP2040-ETH board (contains RP2040 + CH9120 ethernet chip)
|
||||
- WS2812/NeoPixel LED strip or individual LED
|
||||
- Ethernet cable and network connection
|
||||
- USB-C cable for programming
|
||||
|
||||
## Core Requirements
|
||||
|
||||
### 1. LED Control System
|
||||
- Use PIO (Programmable I/O) for WS2812 timing control
|
||||
- Connect WS2812 data line to GPIO 25
|
||||
- Implement smooth color transitions between commands
|
||||
- Support RGB color mixing
|
||||
|
||||
### 2. Network Communication
|
||||
- Use CH9120 ethernet chip via UART communication
|
||||
- Configure as TCP server on port 1000
|
||||
- IP address: 192.168.1.201 (or adapt to local network)
|
||||
- Subnet mask: 255.255.0.0 (adapt to local network)
|
||||
- Gateway: 192.168.1.1 (adapt to local network)
|
||||
|
||||
### 3. Visual Feedback System
|
||||
- Green flash every 1 second: firmware alive indicator
|
||||
- Amber flash on network activity: traffic indicator
|
||||
- Blue flashes on startup: initialization complete
|
||||
- Maintain commanded color between status flashes
|
||||
|
||||
### 4. Command Protocol
|
||||
Support these TCP commands:
|
||||
- `RED`, `GREEN`, `BLUE`, `WHITE`, `OFF`
|
||||
- `RGB:r,g,b` format for custom colors (e.g., `RGB:255,128,0`)
|
||||
- Send acknowledgment responses back to client
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### CH9120 Configuration
|
||||
```c
|
||||
// Pin assignments
|
||||
#define UART_TX_PIN1 20 // To CH9120
|
||||
#define UART_RX_PIN1 21 // From CH9120
|
||||
#define CFG_PIN 18 // Configuration mode
|
||||
#define RES_PIN 19 // Reset pin
|
||||
|
||||
// Network settings
|
||||
TCP_SERVER mode
|
||||
IP: 192.168.1.201
|
||||
Subnet: 255.255.0.0
|
||||
Gateway: 192.168.1.1
|
||||
Port: 1000
|
||||
```
|
||||
|
||||
### Key Technical Points
|
||||
|
||||
1. **CH9120 Initialization Sequence**:
|
||||
- Hard reset (RES pin low->high)
|
||||
- Enter config mode (CFG pin low)
|
||||
- Send configuration commands via UART at 9600 baud
|
||||
- Exit config mode and switch to 115200 baud for data
|
||||
|
||||
2. **WS2812 Control**:
|
||||
- Use ws2812.pio program for timing
|
||||
- GRB color format (not RGB)
|
||||
- 800kHz timing requirement
|
||||
|
||||
3. **Timing Management**:
|
||||
- Use `to_ms_since_boot(get_absolute_time())` for timing
|
||||
- Non-blocking network checks
|
||||
- Smooth color transitions (increment/decrement by 1 per step)
|
||||
|
||||
4. **Visual Indicators**:
|
||||
- Override any color during status flashes
|
||||
- Green flash: `put_rgb(0, 128, 0)` for 100ms every 1000ms
|
||||
- Amber flash: `put_rgb(255, 191, 0)` for 50ms on network activity
|
||||
|
||||
## File Structure to Create
|
||||
|
||||
1. **barnum.c** - Main application combining LED and network control
|
||||
2. **ch9120.c/.h** - Ethernet chip driver with initialization and data functions
|
||||
3. **CMakeLists.txt** - Build configuration for Pico SDK
|
||||
4. **test_client.py** - Python client for testing commands
|
||||
5. **test_ethernet.py** - Network diagnostics tool
|
||||
6. **ws2812.pio** - PIO program for LED timing (copy from Pico examples)
|
||||
|
||||
## Critical Implementation Notes
|
||||
|
||||
### CH9120 Driver Functions Needed:
|
||||
```c
|
||||
void CH9120_init(void); // Initialize and configure
|
||||
void CH9120_send_data(const char *data, size_t len); // Send TCP data
|
||||
int CH9120_receive_data(char *buffer, size_t max_len); // Receive TCP data
|
||||
```
|
||||
|
||||
### Color Command Parser:
|
||||
```c
|
||||
void parse_color_command(const char *cmd, uint8_t *r, uint8_t *g, uint8_t *b);
|
||||
```
|
||||
|
||||
### LED Control Functions:
|
||||
```c
|
||||
void put_rgb(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void put_pixel(uint32_t pixel_grb);
|
||||
```
|
||||
|
||||
## Build System Setup
|
||||
|
||||
Use Pico SDK with these key settings:
|
||||
- Board type: `waveshare_rp2040_eth`
|
||||
- Enable USB stdio: Yes
|
||||
- Enable UART stdio: Yes
|
||||
- Link libraries: `pico_stdlib`, `hardware_pio`, `hardware_uart`
|
||||
|
||||
## Testing Approach
|
||||
|
||||
1. **Hardware Test**: Look for green heartbeat flash
|
||||
2. **Network Test**: `ping 192.168.1.201`
|
||||
3. **TCP Test**: `nc 192.168.1.201 1000` then send color commands
|
||||
4. **Integration Test**: Use Python client to send various color commands
|
||||
|
||||
## Common Issues and Solutions
|
||||
|
||||
1. **No ping response**: Check subnet mask matches local network
|
||||
2. **LED not working**: Verify GPIO 25 connection and power supply
|
||||
3. **No network data**: Ensure TCP_SERVER mode, not TCP_CLIENT
|
||||
4. **Color wrong**: Remember WS2812 uses GRB format, not RGB
|
||||
|
||||
## Reference Code Location
|
||||
|
||||
The project includes reference code in `Refernce Code/RP2040_ETH_CODE/C/` that demonstrates basic CH9120 usage patterns. Study this for command structure and timing requirements.
|
||||
|
||||
## Success Criteria
|
||||
|
||||
- LED flashes green every second (alive indicator)
|
||||
- Responds to ping at 192.168.1.201
|
||||
- Accepts TCP connections on port 1000
|
||||
- Changes LED color based on received commands
|
||||
- Shows amber flash during network activity
|
||||
- Sends acknowledgment messages back to client
|
||||
- Smooth color transitions between commands
|
||||
|
||||
This should provide a complete foundation for recreating the network-controlled LED system.
|
||||
Reference in New Issue
Block a user