EIP Ground Truth
ESP32-P4 EtherNet/IP adapter with IMU ground-truth for counterbalance
Status: This project is a proof-of-concept implementation and requires further development, testing, and validation before production use.
Overview
A comprehensive EtherNet/IP communication adapter for the ESP32-P4 microcontroller, integrating sensor support, Modbus TCP, and web-based configuration. The device serves as a bridge between EtherNet/IP networks and local I/O, sensors, and other industrial automation components.
This project implements a full-featured EtherNet/IP adapter device on the ESP32-P4 platform using the OpENer open-source EtherNet/IP stack. The device provides IMU-based ground-truth measurements for counterbalance applications, calculating roll, pitch, ground angle, and opposed-cylinder pressures.
Hardware Platform
This project targets ESP32-P4 with Ethernet connectivity:
- Microcontroller: ESP32-P4 (Espressif)
- Ethernet PHY: IP101 (or compatible)
- I2C Devices: Optional IMU sensor (MPU6050 or LSM6DS3)
- GPIO Configuration: Ethernet: MDC, MDIO, PHY Reset (configurable); I2C: SDA, SCL (configurable, defaults GPIO7/GPIO8)
IMU Integration
The device supports 6-axis motion sensor support with automatic fallback:
- MPU6050: Primary sensor - Accelerometer-based orientation calculation
- LSM6DS3: Fallback sensor - Sensor fusion (complementary filter) combining accelerometer and gyroscope for accurate orientation
IMU Capabilities
Both sensors provide the following measurements:
- Roll and Pitch: Orientation angles from horizontal (degrees)
- Ground Angle: Angle from vertical (degrees)
- Cylinder Pressures: Calculated pressures for two opposed cylinders based on orientation, tool weight, tip force, and cylinder bore
Calculation Precision
All sensor calculations use 32-bit float precision (IEEE 754 single precision):
- Ground angle calculation:
acos(cos(roll) × cos(pitch))for both MPU6050 and LSM6DS3 (correct 3D angle formula) - Typical accuracy: ±0.04° for ground angle calculations (sufficient for industrial sensor applications)
- Values are scaled by 10000 for angles and 1000 for pressures when stored in assembly data
EtherNet/IP Assembly Structure
The device exposes three EtherNet/IP assembly instances:
Input Assembly (Instance 100) - 32 Bytes
Contains IMU sensor data and other input data:
| Offset | Size | Field Name | Description |
|---|---|---|---|
| 0-3 | 4 | DINT 0 | Roll angle (degrees × 10000) |
| 4-7 | 4 | DINT 1 | Pitch angle (degrees × 10000) |
| 8-11 | 4 | DINT 2 | Ground angle from vertical (degrees × 10000) |
| 12-15 | 4 | DINT 3 | Bottom cylinder pressure (PSI × 1000) |
| 16-19 | 4 | DINT 4 | Top cylinder pressure (PSI × 1000) |
| 20-31 | 12 | Reserved | Available space for other sensor data |
Note: Byte offset is configurable (0-12) to avoid conflicts with other sensors.
Output Assembly (Instance 150) - 32 Bytes
Contains control commands and configuration parameters:
- Byte 29: Cylinder bore diameter (scaled by 100: 0.01-2.55 inches)
- Byte 30: Tool weight (0-255 lbs)
- Byte 31: Tip force (0-255 lbs)
- Bytes 0-28: Control commands and other output data
Configuration Assembly (Instance 151) - 10 Bytes
A 10-byte configuration assembly is available for device-specific configuration parameters.
Modbus TCP Server
Standard Modbus TCP/IP server (port 502) provides additional protocol access:
- Input Registers 0-15: Map to Input Assembly 100 (32 bytes = 16 registers)
- Holding Registers 100-115: Map to Output Assembly 150 (32 bytes = 16 registers)
- Holding Registers 150-154: Map to Configuration Assembly 151 (10 bytes = 5 registers)
All assembly data is stored in little-endian format (Modbus converts to big-endian for transmission).
Network Configuration
The device includes RFC 5227 compliant Address Conflict Detection (ACD):
- RFC 5227 compliant static IP assignment (implemented in application layer)
- ACD probe sequence runs before IP assignment (deferred assignment)
- Natural ACD state machine flow
- EtherNet/IP conflict reporting in TCP/IP Interface Object Attribute #11
- User LED indication (GPIO27): blinks during normal operation, solid on ACD conflict
Web-Based Configuration Interface
Essential device management via web interface:
- Network Configuration: Set IP address, netmask, gateway, DNS (DHCP/Static IP modes)
- Firmware Updates: Upload firmware updates via web browser (OTA)
- REST API: All other device configuration, monitoring, and status information available via REST API
Access the web interface at http://<device-ip>/ after the device has obtained an IP address.
Sensor Configuration
Configuration via web API:
- Enable/disable sensor
- Configure byte offset (0-12) to avoid conflicts with other sensors
- View real-time readings (roll, pitch, ground angle, pressures)
- Calibrate sensor (LSM6DS3 only)
The device automatically detects and uses MPU6050 if available, otherwise falls back to LSM6DS3.
Software Requirements
- ESP-IDF: Version 5.5.1 or compatible
- Python: 3.x (for build scripts)
- CMake: 3.16 or higher
Connection Types
The device supports standard EtherNet/IP connection types:
- Exclusive Owner: Bidirectional I/O connection
- Input Only: Unidirectional input connection
- Listen Only: Unidirectional input connection (multicast)