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
This commit is contained in:
Pi User
2025-10-01 21:08:28 +13:00
parent aa9b5bb324
commit 5a05ee99a1
1356 changed files with 190644 additions and 87 deletions

64
test/quick_test.py Executable file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""
Quick SPI test for basic functionality verification
"""
import spidev
import time
import sys
import json
def quick_spi_test():
"""Quick test to verify SPI communication"""
print("Quick SPI Test")
print("=" * 30)
try:
# Initialize SPI
spi = spidev.SpiDev()
spi.open(0, 0) # Bus 0, Device 0
spi.max_speed_hz = 1000000 # 1MHz
spi.mode = 0 # SPI Mode 0
spi.bits_per_word = 8
print("SPI initialized successfully")
print(f"Mode: {spi.mode}, Speed: {spi.max_speed_hz}Hz")
# Test 1: Simple byte
print("\nTest 1: Single byte (0xAA)")
response = spi.xfer2([0xAA])
print(f"Sent: [0xAA], Received: {[hex(b) for b in response]}")
# Test 2: Multiple bytes
print("\nTest 2: Multiple bytes")
test_data = [0x01, 0x02, 0x03, 0x04]
response = spi.xfer2(test_data)
print(f"Sent: {[hex(b) for b in test_data]}")
print(f"Received: {[hex(b) for b in response]}")
# Test 3: Hello message
print("\nTest 3: Hello message")
hello = [0x48, 0x65, 0x6C, 0x6C, 0x6F] # "Hello"
response = spi.xfer2(hello)
print(f"Sent: {[hex(b) for b in hello]} ({''.join([chr(b) for b in hello])})")
print(f"Received: {[hex(b) for b in response]}")
# Test 4: JSON message
print("\nTest 4: JSON message")
payload = {"d":{"t":"b","br":128},"bar":{"pt":"off"}}
json_bytes = list(json.dumps(payload, separators=(",",":"))).encode("utf-8")
response = spi.xfer2(list(json.dumps(payload, separators=(",",":"), ensure_ascii=False).encode("utf-8")))
print(f"Sent JSON: {json.dumps(payload)}")
print(f"Received: {[hex(b) for b in response]}")
spi.close()
print("\nTest completed successfully!")
return True
except Exception as e:
print(f"Test failed: {e}")
return False
if __name__ == "__main__":
success = quick_spi_test()
sys.exit(0 if success else 1)