Skip to content

๐ŸŽฎ PS5 Controller + ESP32 + LoRa = Advanced wireless aircraft ground control station with OLED display ๐Ÿ“กโœˆ๏ธ

License

Notifications You must be signed in to change notification settings

Arsalan134/Ground-Lora

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

54 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ก Ground-Lora

License PlatformIO Arduino

๐ŸŽฎ ESP32-based Dual-Core LoRa Ground Control Station with PS5 Controller

A sophisticated dual-core ground control station for remote aircraft control using LoRa communication and PS5 DualSense controller input. This project provides real-time flight control with OLED display feedback, robust wireless communication, and optimized dual-core performance for enhanced responsiveness and safety.

๐ŸŒŸ Features

โšก Dual-Core Architecture

  • Core 1 (High Priority): Real-time PS5 controller processing and LoRa transmission at 20Hz
  • Core 0 (Lower Priority): OLED display updates and LoRa reception at 10Hz
  • Thread Safety: Mutex protection for shared data between cores
  • Performance Monitoring: Real-time system health and performance statistics
  • Watchdog Protection: Robust error handling to prevent system crashes

๐ŸŽฎ PS5 Controller Integration

  • Full DualSense Support: Buttons, analog sticks, triggers, and IMU sensors
  • Flight Controls:
    • โ†”๏ธ Left stick X-axis โ†’ Aileron control
    • โ†”๏ธ Right stick X-axis โ†’ Rudder control
    • โ†•๏ธ Right stick Y-axis โ†’ Elevator control
    • ๐ŸŽš๏ธ R2 trigger โ†’ Engine throttle
  • Auxiliary Controls:
    • ๐Ÿชถ L1/R1 โ†’ Flaps control (decrease/increase)
    • ๐Ÿ”„ L3/R3 โ†’ Reset aileron/elevator trim
    • ๐Ÿ›‘ PS Button โ†’ Enable airbrake
    • โŒ Cross Button โ†’ Disable emergency stop
    • โญ• Circle Button โ†’ Enable emergency stop
  • Safety Features: Emergency stop override and safety interlocks

๐Ÿ“ก LoRa Communication

  • 915MHz ISM Band: Long-range, low-power wireless communication
  • Packet Protocol: Custom message format with checksum validation
  • Real-time Transmission: 60ms update rate for responsive control
  • Data Optimization: Smart packet filtering to reduce redundant transmissions

๐Ÿ–ฅ๏ธ OLED Display Interface

  • 128x64 SSD1306 Display: Real-time status and control feedback
  • Multi-frame UI: Switchable display screens
  • Status Overlays:
    • ๐Ÿ”ต Bluetooth connection status
    • ๐Ÿ”‹ Battery percentage display
    • โšก Charging indicator
    • ๐Ÿ“ถ WiFi status (when available)
  • Flight Data Display: Live control surface positions and engine status

๐Ÿ›ก๏ธ Safety Systems

  • Emergency Stop: Immediate control override capability
  • Connection Monitoring: Automatic safety engagement on signal loss
  • Input Validation: Checksum verification for all transmitted data
  • Redundant Safety: Multiple layers of safety interlocks

๐Ÿ› ๏ธ Hardware Requirements

๐Ÿ“ฑ Main Components

  • ESP32 Development Board: TTGO LoRa32 v2.1 (recommended)
  • LoRa Module: 915MHz SX1276/SX1278
  • OLED Display: 128x64 SSD1306 (I2C)
  • PS5 DualSense Controller: Bluetooth connectivity

๐Ÿ”Œ Pin Configuration

  • LoRa Module: Uses board default pins (automatically configured)
  • OLED Display: I2C (uses board default SDA/SCL pins)
  • Analog Input: Pin 34 for manual throttle slider (optional)
  • Built-in LED: Status indication

๐Ÿ—๏ธ System Architecture

  • FreeRTOS Tasks: Dual-core task management with priority scheduling
  • Memory Management: Optimized 8000-word stack size per task
  • Error Handling: Graceful degradation and automatic recovery
  • Performance Optimization: Load balancing across both ESP32 cores

๐Ÿ“ฆ Dependencies

lib_deps = 
    thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.5.0  ; ๐Ÿ–ฅ๏ธ
    sandeepmistry/LoRa@^0.8.0   ; ๐Ÿ“ก
    ; PS5 Controller library included in lib/ folder ๐ŸŽฎ

๐Ÿš€ Quick Start

1. ๐Ÿ”ง Hardware Setup

  1. Connect LoRa module to ESP32 (refer to pin definitions in include/common.h)
  2. Connect OLED display via I2C
  3. Power up the system

2. ๐Ÿ“ฑ PS5 Controller Pairing

  1. Find your PS5 controller's Bluetooth MAC address:
    • Connect controller to your phone via Bluetooth
    • Check "About" settings for the MAC address
  2. Update the MAC address in include/common.h:
    #define PS5_MAC_ADDRESS "xx:xx:xx:xx:xx:xx"  // ๐ŸŽฎ Your controller's MAC
  3. Upload the code and the controller will automatically pair

3. ๐Ÿ“ค Build and Upload

# Using PlatformIO
pio run --target upload

# Or use VS Code PlatformIO extension
# Click "Upload" button in PlatformIO toolbar

๐ŸŽฎ Control Mapping

Control Function Description
๐Ÿ•น๏ธ Left Stick X Aileron โ†”๏ธ Roll control
๐Ÿ•น๏ธ Right Stick X Rudder โ†”๏ธ Yaw control
๐Ÿ•น๏ธ Right Stick Y Elevator โ†•๏ธ Pitch control
๐ŸŽš๏ธ R2 Trigger Engine ๐Ÿš€ Throttle control
โฌ†๏ธ D-Pad Up Elevator Trim + โ†•๏ธ Nose up trim
โฌ‡๏ธ D-Pad Down Elevator Trim - โ†•๏ธ Nose down trim
โžก๏ธ D-Pad Right Aileron Trim + โ†”๏ธ Right roll trim
โฌ…๏ธ D-Pad Left Aileron Trim - โ†”๏ธ Left roll trim
๐Ÿ”ด L1 Flaps Down ๐Ÿชถ Decrease flaps
๐Ÿ”ด R1 Flaps Up ๐Ÿชถ Increase flaps
๐Ÿ”˜ L3 Reset Aileron Trim ๐Ÿ”„ Center aileron
๐Ÿ”˜ R3 Reset Elevator Trim ๐Ÿ”„ Center elevator
โŒ Cross Disable Emergency ๐Ÿ”“ Enable flight
โญ• Circle Emergency Stop ๐Ÿšจ Immediate stop
๐Ÿ  PS Button Airbrake ๐Ÿ›‘ Enable airbrake

๐Ÿ“ก Communication Protocol

The system uses a custom LoRa packet format:

e[engine]a[aileron]r[rudder]l[elevator]t[trim]i[aileron_trim]f[flaps]z[reset_a]y[reset_e]b[airbrake]#[checksum]

๐Ÿ“Š Data Ranges

  • Engine: 0-180 (mapped from 0-4095 analog input)
  • Control Surfaces: 0-180 (mapped from controller input)
  • Trim: ยฑvalues for fine adjustment
  • Flaps: 0-4 discrete positions
  • Checksum: XOR validation byte

๐Ÿ–ฅ๏ธ Display Interface

๐Ÿ“บ Main Screen (Frame 1)

  • Control Positions: Live aileron, elevator, rudder values
  • Engine Status: Throttle percentage with ๐Ÿš€ indicator
  • Emergency Status: ๐Ÿšจ STOP indicator when active
  • Flaps Position: Current flap setting ๐Ÿชถ
  • Developer Info: ๐Ÿ‘จโ€๐Ÿ’ป Arsalan Iravani

๐Ÿ“ฑ Status Overlays

  • ๐Ÿ”ต Bluetooth: Connection status indicator
  • ๐Ÿ”‹ Battery: Controller battery percentage
  • โšก Charging: Active charging indicator
  • ๐Ÿ“ถ WiFi: Network status (when applicable)

๐Ÿ›ก๏ธ Safety Features

๐Ÿšจ Emergency Systems

  • Automatic Stop: Engine cuts to zero on emergency activation
  • Connection Loss: Safety engagement if controller disconnects
  • Input Validation: All commands verified with checksums
  • Redundant Controls: Multiple ways to activate emergency stop

โš–๏ธ Control Limits

  • Stick Deadzone: Idle deviation threshold prevents accidental inputs
  • Rate Limiting: Flap changes limited to prevent servo damage
  • Range Mapping: All inputs mapped to safe servo ranges

๐Ÿ“ Project Structure

Ground Lora/
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE                          # ๐Ÿ“ MIT License file
โ”œโ”€โ”€ ๐Ÿ“„ platformio.ini                   # ๐Ÿ”ง Build configuration with dual-core flags
โ”œโ”€โ”€ ๐Ÿ“„ README.md                        # ๐Ÿ“š This file
โ”œโ”€โ”€ ๏ฟฝ include/                         # ๐Ÿ“‚ Header files directory
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ common.h                     # ๏ฟฝ Shared definitions and pin config
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Display.h                    # ๐Ÿ–ฅ๏ธ Display interface
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ images.h                     # ๏ฟฝ๏ธ Display graphics and icons
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ main.h                       # ๐Ÿš€ Main function declarations
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ PS5Joystick.h               # ๐ŸŽฎ Controller interface
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ SD-Card.h                   # ๐Ÿ’พ SD card interface
โ”œโ”€โ”€ ๐Ÿ“‚ src/                            # ๐Ÿ“‚ Source code directory
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ main.cpp                     # ๐Ÿš€ Main program with dual-core tasks
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Display.cpp                  # ๐Ÿ–ฅ๏ธ OLED display management
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Lora.cpp                     # ๐Ÿ“ก LoRa communication
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ PS5Joystick.cpp             # ๐ŸŽฎ Controller handling (no mutex)
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ SD-Card.cpp                 # ๐Ÿ’พ SD card functionality
โ”œโ”€โ”€ ๐Ÿ“‚ lib/                            # ๐Ÿ“‚ Libraries directory
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ PS5Library/                 # ๐ŸŽฎ PS5 controller library
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ component.mk             # ๐Ÿ“‹ Component makefile
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ Kconfig                  # โš™๏ธ Configuration file
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ keywords.txt             # ๐Ÿ”ค Arduino IDE keywords
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ library.properties       # ๐Ÿ“š Library properties
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ PACKET_ANALYSIS.md       # ๐Ÿ“ก Packet analysis documentation
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ README.md                # ๏ฟฝ Library documentation
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ SENSOR_IMPLEMENTATION.md # ๐Ÿ“Š Sensor implementation details
โ”‚       โ”œโ”€โ”€ ๐Ÿ“‚ examples/                # ๐Ÿ“ Example implementations
โ”‚       โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ ps5_advanced_sensors.ino # ๐Ÿงช Advanced sensors example
โ”‚       โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ ps5_packet_debug.ino     # ๐Ÿ” Packet debugging example
โ”‚       โ”‚   โ””โ”€โ”€ ๐Ÿ“„ ps5_sensors_example.ino  # ๏ฟฝ Basic sensors example
โ”‚       โ””โ”€โ”€ ๐Ÿ“‚ src/                     # ๐Ÿ“‚ Library source code
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5_int.h            # ๐Ÿ”— Internal PS5 definitions
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5_l2cap.c          # ๐Ÿ“ก L2CAP protocol implementation
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5_parser.c         # ๏ฟฝ Data parser implementation
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5_spp.c            # ๐Ÿ“ถ SPP protocol implementation
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5.c                # ๐ŸŽฎ Core PS5 functionality
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5.h                # ๐ŸŽฎ PS5 header file
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5Controller.cpp    # ๐ŸŽฎ Controller class implementation
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ ps5Controller.h      # ๐ŸŽฎ Controller class header
โ”‚           โ”œโ”€โ”€ ๐Ÿ“‚ osi/                 # ๐Ÿ“‚ OS interface
โ”‚           โ”‚   โ””โ”€โ”€ ๐Ÿ“„ allocator.h      # ๐Ÿ’พ Memory allocator
โ”‚           โ””โ”€โ”€ ๐Ÿ“‚ stack/               # ๏ฟฝ Bluetooth stack
โ”‚               โ”œโ”€โ”€ ๐Ÿ“„ bt_types.h       # ๐Ÿ”ต Bluetooth type definitions
โ”‚               โ”œโ”€โ”€ ๐Ÿ“„ btm_api.h        # ๐Ÿ”ต BTM API definitions
โ”‚               โ”œโ”€โ”€ ๐Ÿ“„ gap_api.h        # ๐Ÿ”ต GAP API definitions
โ”‚               โ”œโ”€โ”€ ๐Ÿ“„ hcidefs.h        # ๐Ÿ”ต HCI definitions
โ”‚               โ”œโ”€โ”€ ๐Ÿ“„ l2c_api.h        # ๐Ÿ”ต L2C API definitions
โ”‚               โ””โ”€โ”€ ๏ฟฝ l2cdefs.h        # ๐Ÿ”ต L2C definitions
โ”œโ”€โ”€ ๏ฟฝ๐Ÿ“‚ Resources/                       # ๐Ÿ“‚ Resource files directory
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ blIcon.png                   # ๐Ÿ”ต Bluetooth icon
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ charging.png                 # โšก Charging indicator icon
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ ps5 icon.png                 # ๐ŸŽฎ PS5 controller icon
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ PS5-Controller-PNG-Image.png # ๐ŸŽฎ Controller image
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ wifiIcon.png                 # ๐Ÿ“ถ WiFi status icon
โ””โ”€โ”€ ๐Ÿ“‚ test/                           # ๐Ÿ“‚ Unit tests directory
    โ”œโ”€โ”€ ๐Ÿ“„ README                       # ๐Ÿ“š Test documentation
    โ”œโ”€โ”€ ๐Ÿ“„ test_config.py              # โš™๏ธ Test configuration file
    โ”œโ”€โ”€ ๐Ÿ“‚ test_display/                # ๐Ÿ–ฅ๏ธ Display tests
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ test_display.cpp         # ๐Ÿงช Display unit tests
    โ”œโ”€โ”€ ๐Ÿ“‚ test_integration/            # ๐Ÿ”— Integration tests
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ test_integration.cpp     # ๐Ÿงช Integration unit tests
    โ”œโ”€โ”€ ๐Ÿ“‚ test_lora/                   # ๐Ÿ“ก LoRa tests
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ test_lora.cpp            # ๐Ÿงช LoRa unit tests
    โ”œโ”€โ”€ ๐Ÿ“‚ test_main/                   # ๐Ÿš€ Main tests
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ test_main.cpp            # ๐Ÿงช Main functionality tests
    โ”œโ”€โ”€ ๐Ÿ“‚ test_ps5/                    # ๐ŸŽฎ PS5 controller tests
    โ”‚   โ””โ”€โ”€ ๏ฟฝ test_ps5.cpp             # ๐Ÿงช PS5 controller unit tests
    โ”œโ”€โ”€ ๐Ÿ“‚ test_safety/                 # ๏ฟฝ๏ธ Safety system tests
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ test_safety.cpp          # ๐Ÿงช Safety feature tests
    โ””โ”€โ”€ ๐Ÿ“‚ test_utilities/              # ๐Ÿ”ง Utility tests
        โ””โ”€โ”€ ๐Ÿ“„ test_utilities.cpp       # ๐Ÿงช Utility function tests

๐Ÿ“‹ Key Files Description

๐Ÿš€ Core System Files

  • main.cpp: Dual-core task implementation with FreeRTOS
  • common.h: Shared definitions, pin configurations, and extern declarations
  • main.h: Function declarations for dual-core tasks and system functions

๐ŸŽฎ Controller Integration

  • PS5Joystick.cpp/.h: PS5 controller handling with optimized callback functions
  • PS5Library/: Complete PS5 DualSense library with advanced features
    • ps5Controller.cpp/.h: Main controller class implementation
    • ps5.c/.h: Core PS5 functionality and protocol handling
    • examples/: Sample implementations for various PS5 features

๐Ÿ–ฅ๏ธ Display System

  • Display.cpp/.h: OLED display management with frame-based UI
  • images.h: Graphics definitions for icons and symbols
  • Resources/: Icon and image assets for the display interface

๐Ÿ“ก Communication

  • Lora.cpp: LoRa communication with packet protocol and checksums
  • SD-Card.cpp/.h: SD card functionality for data logging

๐Ÿงช Testing Framework

  • test/: Comprehensive unit testing suite
    • test_config.py: Python configuration for test automation
    • test_display/: Display functionality tests
    • test_integration/: System integration tests
    • test_lora/: LoRa communication tests
    • test_main/: Core functionality tests
    • test_ps5/: PS5 controller tests
    • test_safety/: Safety system validation tests
    • test_utilities/: Utility function tests

๐Ÿ“š Project Configuration

  • platformio.ini: Build configuration with dual-core optimization flags
  • LICENSE: MIT License file
  • README.md: This comprehensive documentation

๐Ÿ”ง Development Setup

Prerequisites

  • PlatformIO: VS Code extension or CLI
  • ESP32 Toolchain: Automatically installed by PlatformIO (dual-core enabled)
  • PS5 Controller: DualSense controller with Bluetooth
  • Hardware: TTGO LoRa32 or compatible ESP32 board with LoRa module

๐Ÿ› ๏ธ Building

# Clone the repository
git clone https://github.com/Arsalan134/Ground-Lora.git
cd Ground-Lora

# Build the project (with dual-core support)
pio run

# Upload to ESP32
pio run --target upload

# Monitor serial output (view dual-core performance stats)
pio device monitor

๐Ÿ“Š Build Configuration

The project is configured for dual-core operation with optimized flags:

build_flags = 
    -std=gnu++17
    -DCONFIG_FREERTOS_NUMBER_OF_CORES=2

๐Ÿ“Š Performance

โšก Dual-Core Performance

  • Core 1 (Controller): 20Hz update rate for responsive control input
  • Core 0 (Display): 10Hz update rate for smooth UI without blocking control
  • LoRa Transmission: ~16.7Hz with smart packet optimization
  • System Health: Monitored every 30 seconds with performance statistics

๐Ÿ“ˆ System Metrics

  • RAM Usage: ~12% of 320KB (highly efficient)
  • Flash Usage: ~87% with all features enabled
  • Stack Usage: 8000 words per task with monitoring
  • Heap Monitoring: Real-time memory leak detection
  • Range: Several kilometers (LoRa 915MHz)
  • Latency: <50ms typical (improved with dual-core)

๐Ÿ› Troubleshooting

๐ŸŽฎ Controller Issues

  • Pairing Failed: Check MAC address in src/Common/common.h
  • No Response: Ensure controller is charged and in pairing mode
  • Input Lag: Check for Bluetooth interference, dual-core should minimize lag

๐Ÿ“ก LoRa Issues

  • Init Failed: Check antenna connections, system will continue without LoRa after 10 retries
  • Poor Range: Verify antenna positioning and frequency settings
  • Packet Loss: Check for interference on 915MHz band

๐Ÿ–ฅ๏ธ Display Issues

  • Blank Screen: Verify I2C connections (uses board default pins)
  • Corrupted Display: Check power supply stability
  • Slow Updates: Normal with dual-core - Core 0 handles display at 10Hz

โšก System Stability

  • Watchdog Timeout: See WATCHDOG_TIMEOUT_FIX.md for detailed solutions
  • Core Crashes: Check serial output for mutex warnings and stack usage
  • Memory Issues: Monitor heap usage in performance statistics
  • Task Failures: Verify stack high-water marks in health checks

๐Ÿ”ง Performance Optimization

  • Check Serial Output: Look for dual-core performance statistics every 5 seconds
  • Monitor System Health: Health checks appear every 30 seconds
  • Stack Monitoring: Ensure >1000 words free space per task
  • Heap Memory: Should stay >100KB for stable operation

๐Ÿค Contributing

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’พ Commit your changes (git commit -m 'โœจ Add amazing feature')
  4. ๐Ÿ“ค Push to the branch (git push origin feature/amazing-feature)
  5. ๐Ÿ”€ Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary:

  • โœ… Commercial use allowed
  • โœ… Modification allowed
  • โœ… Distribution allowed
  • โœ… Private use allowed
  • โš–๏ธ Liability and warranty disclaimed

๐Ÿ‘จโ€๐Ÿ’ป Author

Arsalan Iravani

๐Ÿ”— Related Projects

  • Airplane: Companion dual-core receiver project for aircraft-side control
  • PS5-ESP32: Enhanced PS5 controller library with dual-core support (included in lib/)

๐Ÿ“š Additional Documentation

โš ๏ธ Disclaimer

This is a dual-core remote control system for model aircraft. Always follow local regulations and safety guidelines when operating remote-controlled aircraft. The dual-core architecture provides enhanced safety features, but proper operation is still the responsibility of the user. The author is not responsible for any accidents or damages resulting from the use of this system.


๐Ÿš€ Happy Flying! โœˆ๏ธ

About

๐ŸŽฎ PS5 Controller + ESP32 + LoRa = Advanced wireless aircraft ground control station with OLED display ๐Ÿ“กโœˆ๏ธ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages