Files
lighting-controller/esp32/README.md
Pi User 5a05ee99a1 Add ESP32-C3 SPI slave with ESP-NOW, Raspberry Pi test tools, and updated project structure
- ESP32-C3 SPI slave project with ESP-NOW broadcast functionality
- Raspberry Pi SPI master test tools and CLI for JSON communication
- Merged src/ directory from full branch with lighting controller code
- Updated Pipfile with system install scripts and ESP32 monitoring
- Added comprehensive test suite for SPI communication
2025-10-01 21:08:28 +13:00

74 lines
1.8 KiB
Markdown

# ESP32-C3 SPI Slave with ESP-NOW Project
This ESP-IDF project implements an SPI slave device that broadcasts received data via ESP-NOW with the following GPIO configuration:
- **MOSI**: GPIO10
- **MISO**: GPIO9
- **SCLK**: GPIO20
- **CS**: GPIO7
## Features
- SPI Mode 0 (CPOL=0, CPHA=0)
- 256-byte buffer for data exchange
- DMA support for efficient transfers
- Real-time data logging via UART
- **ESP-NOW broadcasting** of received SPI data
- Timestamped data packets
- Broadcast to all nearby ESP32 devices
## Building and Flashing
1. Set up ESP-IDF environment:
```bash
. $HOME/esp/esp-idf/export.sh
```
2. Build the project:
```bash
cd esp32
idf.py build
```
3. Flash to ESP32-C3:
```bash
idf.py -p /dev/ttyUSB0 flash monitor
```
## Usage
The ESP32-C3 will act as an SPI slave device, waiting for transactions from an SPI master. When data is received, it will:
1. Print the received data to the serial console
2. **Broadcast the received data via ESP-NOW** to all nearby ESP32-C3 devices
3. Send back a test pattern (0x00, 0x01, 0x02, ...)
4. Wait for the next transaction
## ESP-NOW Data Format
The broadcasted data includes:
- **Data**: The actual SPI received data (up to 256 bytes)
- **Length**: Number of bytes received
- **Timestamp**: Millisecond timestamp when data was received
## Receiving ESP-NOW Data
To receive the broadcasted data on another ESP32-C3 device, you can use the ESP-NOW receive callback function. The data structure is:
```c
typedef struct {
uint8_t data[256]; // Received SPI data
uint8_t length; // Number of bytes
uint32_t timestamp; // Timestamp in milliseconds
} espnow_data_t;
```
## Serial Monitor
Connect to the serial monitor to see debug output:
```bash
idf.py -p /dev/ttyUSB0 monitor
```
The device will log received SPI data and transaction status.