ESP32 Projects
Start a build
Markdown

Round Compass

You use this code entirely at your own risk. The author accepts no liability for any damage, injury or loss arising from its use.

Elecrow CrowPanel 2.1ArduinoUnrated
Parts and source

Before you start

Check the exact Touchscreen, BME280 configuration against the upstream wiring or parts list.

Upstream README

Logo

ESP32 CrowPanel Compass & Multi-Function Display

Platform: ESP32-S3 Display: CrowPanel 2.1" Rotary Knob Protocol: ESP-NOW License: MIT UI: LVGL9

Disclaimer

This is a personal hobby project. It is provided "as is", without warranty of any kind. See LICENSE.

This firmware is NOT intended for navigation or for any safety-critical use at sea. Do not rely on the data it produces (such as heading, depth or position) to navigate a vessel. Always use certified navigation equipment and proper seamanship.

You use this code entirely at your own risk. The author accepts no liability for any damage, injury or loss arising from its use.

Introduction

Marine instrument display for Elecrow CrowPanel 2.1" HMI (ESP32-S3, 480x480 IPS round touchscreen, rotary knob). Receives via ESP-NOW:

Displays values on a round LVGL UI. User interaction via rotary knob (rotate or press). No touch screen implementation yet.

Different screens selectable by rotating the knob:

  • Compass screen — rotating compass rose with HEADING (HDG T), COG and SOG views
  • Attitude screen — toggle between artificial horizon, pitch/roll min/max and depth views
  • Weather screen — toggle between temperature, pressure and humidity views
  • Battery screen — toggle between house voltage, house current, house SoC and starter voltage views
  • Engine screen — toggle between exhaust temperature, fuel tank and fresh water tank views
  • Celestial screen — sextant practice aid: computed altitude Hc and azimuth Zn of the Sun, Moon and a twilight set of one planet + two stars (or three stars), on a star chart relative to the bow
  • Brightness screen — backlight brightness adjustment with NVS persistence

Developed and tested on:

Integrated via ESP-NOW with:

Purpose of the project

This is one of my individual digital boat projects. Use at your own risk. Not for safety-critical navigation.

  1. I needed a compact multi-function display near the helm, receiving data wirelessly from the compass and other devices, independently from WiFi and SignalK
  2. I wanted to learn LVGL and SquareLine Studio for UI development
  3. I continued learning ESP32 C++ patterns and FreeRTOS from the companion projects

Release history

Release Comment
v4.3.0 Latest release. CelestialScreen added — sextant practice aid showing the geocentric computed altitude Hc and azimuth Zn of the Sun, Moon and a twilight set of one planet + two stars (or three stars) on a star chart, in three views (FROM ZENITH / FROM VESSEL / NORTH UP). Astronomy Engine 2.1.19, 57 navigational stars from Hipparcos, GNSS UTC via ESP-NOW DATETIME_DELTA, host unit tests against JPL Horizons. See CHANGELOG for details.
v4.2.4 Documentation update: disclaimer added to README. New version.h with SW_VERSION. See CHANGELOG for details.
v4.2.3 Bug fix: AttitudeScreen now restores the last selected view (ATTITUDE / MINMAX / DEPTH) when returning to the screen and after reboot — active view is persisted to NVS like on the other screens. See CHANGELOG for details.
v4.2.2 Bug fix: trend arrows (↑/↓) on WeatherScreen, BatteryScreen and EngineScreen now show the direction the value is developing in, instead of whether it is above or below the level where it last stood still. New TrendIndicator (fast/slow EMA rate estimate with hysteresis), tuned per value. See CHANGELOG for details.
v4.2.1 Documentation update only.
v4.2.0 AttitudeScreen DEPTH view — graphical depth situation (surface line, keel line, moving sea bottom, grounding caution). EngineScreen FRESHWATER view — fresh water tank arc gauge from HALMET-ESP32-SignalK-gateway. Bug fixes: EngineScreen showView() now hides all three view roots, the water gauge container no longer covers the exhaust and fuel views; the BrightnessScreen arc overlay no longer shows on screen entry. See CHANGELOG for details.
v4.1.0 EngineScreen added — exhaust temperature with session min/max and trend, fuel tank arc gauge with dynamic color. ESP-NOW integration with HALMET-ESP32-SignalK-gateway. Bug fix: AttitudeScreen MINMAX view now reflects pitch and roll extremes recorded across the full runtime, not only while the Attitude screen was active. See CHANGELOG for details.
v4.0.0 Leveling functionality removed — CrowPanel is now receive-only. CompassScreen with 3-view cycle (HEADING → COG → SOG), GNSS data integration from UBLOX-ESP32-SignalK-gateway. See CHANGELOG for details.
v3.1.1 Patching documentation only.
v3.1.0 AttitudeScreen redesigned with separate views for real-time attitude, min/max tracking and for performing attitude leveling (triggered by count-down, canceled by button press/rotate). See CHANGELOG for details.
v3.0.0 Library upgrade: ESP32 board package 2.0.14 → 3.3.7, LVGL 8.3.6 → 9.5.0, Arduino GFX Library 1.3.1 → 1.6.5. This is a compatibility change - v2.1.0 does not compile on the new libraries. See CHANGELOG for details.
v2.1.0 Introduces BatteryScreen and BatteryUI UI adapter class. Minor modifications to WeatherScreen and WeatherUI. See CHANGELOG for details.
v2.0.0 Refactored for scalability in screen management. Introduces IScreenUI interface as an abstract base class for the actual UI adapter classes. Breaking change in ESP-NOW protocol: updated with framed packets, introducing ESPNowPacket and ESPNowHeader structs. Adds WeatherUI UI adapter class and WeatherScreen UI to show temperature, humidity and pressure. See CHANGELOG for details.
v1.0.0 First stable release. See CHANGELOG for details - including pre-releases.

Classes

Class diagram including the companion projects:

CrowPanelApplication:

  • Owns: Arduino_ESP32RGBPanel, Arduino_RGB_Display, Arduino_SWSPI, PCF8574, ESPNowReceiver, CompassUI, AttitudeUI, WeatherUI, BatteryUI, EngineUI, CelestialUI, BrightnessUI, RotaryEncoder, ScreenManager
  • Responsible for: orchestrating everything within the main program

ESPNowReceiver:

  • Responsible for: receiving HeadingData, GnssData, WeatherDelta, BatteryDelta, HALMETEngineDelta, HALMETTankDelta, HALMETWaterDelta, DepthDelta and DateTimeDelta broadcasts via ESP-NOW (receive-only)
  • Keeps a dedicated RX timestamp for depth (lastDepthRxMillis()), because depth is relayed and its freshness cannot be judged from the payload alone
  • Keeps RX timestamps for GNSS, weather and date/time (lastGnssRxMillis(), lastWeatherRxMillis(), lastDateTimeRxMillis()) for screens that judge freshness themselves (CelestialUI)
  • Owned by: CrowPanelApplication

RotaryEncoder:

  • Uses: PCF8574
  • Responsible for: reading rotary knob rotation and knob button press
  • Owned by: CrowPanelApplication

IScreenUI:

  • Abstract base class for UI adapter class implementations

CompassUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver
  • Responsible for: updating LVGL UI objects on the compass screen based on heading and GNSS data; 3-view cycle (HEADING / COG / SOG)
  • Owned by: CrowPanelApplication

AttitudeUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver
  • Responsible for: updating LVGL UI objects on the attitude screen based on pitch, roll and depth data; 3-view cycle (ATTITUDE / MINMAX / DEPTH)
  • Owned by: CrowPanelApplication

WeatherUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver
  • Responsible for: updating LVGL UI objects on the weather screen based on temperature, pressure and humidity data.
  • Owned by: CrowPanelApplication

BatteryUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver
  • Responsible for: updating LVGL UI objects on the battery screen based on battery data.
  • Owned by: CrowPanelApplication

EngineUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver
  • Responsible for: updating LVGL UI objects on the engine screen based on engine exhaust, fuel tank and fresh water tank data; 3-view cycle (EXHAUST / FUEL0 / FRESHWATER)
  • Owned by: CrowPanelApplication

CelestialUI:

  • Realizes: IScreenUI
  • Uses: ESPNowReceiver, Preferences
  • Owns: CelestialEngine
  • Responsible for: updating LVGL UI objects on the celestial screen — data label, body labels and star chart placement; 3-view cycle (FROM_ZENITH / FROM_VESSEL / NORTH_UP)
  • Owned by: CrowPanelApplication

CelestialEngine:

  • Uses: CelestialCalculator, CelestialSelector, NavStars
  • Responsible for: running the astronomy on its own FreeRTOS task (core 0) once per second while the celestial screen is active
  • Owned by: CelestialUI

CelestialCalculator:

  • Uses: Astronomy Engine, NavStars
  • Responsible for: geocentric computed altitude Hc and azimuth Zn of the Sun, Moon, Venus, Mars, Jupiter, Saturn and the 57 navigational stars (double precision)
  • Owned by: CelestialEngine

CelestialSelector:

  • Responsible for: picking the twilight set (one planet + two stars, or three stars, azimuths ~120° apart) with hysteresis
  • Owned by: CelestialEngine

BrightnessUI:

  • Realizes: IScreenUI
  • Uses: Preferences
  • Responsible for: backlight brightness adjustment with NVS persistence, updating LVGL UI objects on the brightness screen
  • Owned by: CrowPanelApplication

ScreenManager:

  • Depends on: IScreenUI*
  • Responsible for: Screen carousel management
  • Owned by: CrowPanelApplication

Features

Compass screen

Pressing the knob button cycles between HEADING → COG → SOG → HEADING. Last view stored in NVS onLeave() (default: HEADING).

  • HEADING view — compass rose rotates to HDG(T) from CMPS14. Mode label: HDG(T). Last known heading preserved on disconnect.
  • COG view — compass rose rotates to COG(T) from GNSS. Mode label: COG(T). Shows ---° when no valid GNSS fix or sender disconnected.
  • SOG view — speedometer arc and speed label from GNSS. Arc range 0-100 = 0.0-10.0 kn (arc value = knots x 10). Label format: one decimal place e.g. 7.1. Shows --.- when no valid GNSS fix or sender disconnected.

Common features:

  • Heading/COG label format: 3-digit with leading zero e.g. 090°
  • Rotating compass rose image (240x240 px source, rendered at 480x480 with LVGL zoom=512, no alpha, antialias off)
  • Rotation threshold 0.5°: skips LVGL re-render when heading/COG change is below threshold
  • Connected indicator panel (black = connected, red = disconnected) — tracks active view's data source (CMPS14 for HEADING, GNSS sender for COG/SOG)
Attitude screen

  • Pitch and roll min/max values tracked across the full runtime (all screens), no persistent storage in NVS
  • Pressing the knob button cycles between ATTITUDE → MINMAX → DEPTH → ATTITUDE view
  • Last view stored in NVS onLeave() (default: ATTITUDE)
  • ATTITUDE view:
    • Artificial horizon: white 680 x 4 px image that rotates and translates based on pitch and roll
    • Pitch and roll value labels
  • MINMAX view:
    • Four horizon lines, all 680 x 4 px images, to show recorded pitch and roll min/max values
      • Yellow, placed horizontally to the max pitch, showing highest bow up position
      • Blue, placed horizontally to the min pitch, showing lowest bow down position
      • Green, pivot at the center, rotated to show max roll, furthest roll position to starboard
      • Red, pivot at the center, rotated to show min roll, furthest roll position to port side
    • Pitch and roll min/max value labels
  • DEPTH view:
    • Depth relayed from NMEA2000 source (temporary, clean ESP32-based depth sender under construction)
    • Ship silhouette floats between two static white lines: water surface (top) and keel (bottom), 55 px apart representing the 1.2 m draft (45.83 px/m ≈ 2.18 cm/px)
    • Grey sea bottom panel slides vertically with the depth below keel. At 0 m it sits on the keel line (aground) and fills the screen; it is hidden once it has slid entirely off-screen (≈ 4.0 m under the keel)
    • Labels, one decimal place, in meters:
      • Left of the ship, on the surface line: depth below surface
      • Right of the ship, on the keel line: depth below keel
      • Under the hull: draft (1.2, static vessel dimension)
      • On top of the mast: air height (5.0, static vessel dimension)
      • Bottom of the screen: static Meters unit label
    • Yellow caution triangle shown when there is less than one draft (1.2 m) of water under the keel
    • Either half of the depth pair is reconstructed from the other through the constant draft if only one arrives; below_transducer_m is not used
    • Two-fold freshness check — a relayed value carries no freshness of its own, so both are required: the ESP-NOW relay must be alive (RX timestamp, 6 s) and the sounder feed behind it must be fresh (DepthDelta.age_ms, 5 s). Either stale, or depth below keel NAN → labels show --.- and the bottom panel and caution triangle are hidden. A frozen depth under the keel is worse than none, because the caution triangle is driven by the same number
    • --.- at anchor is normal: the plotter feeding depth into NMEA2000 reports very infrequently while the vessel is stationary
    • Sea bottom rendering throttled to 250 ms and skipped when the computed position has not moved — the panel is 484x185 px and the sounder only updates at ~1 Hz
  • Ship silhouette overlay on all three views
    • The red and green "navigation lights" of the ship silhouette hidden when disconnected, shown again when data received from the compass — they follow the compass link in all three views, missing depth does not hide them
Weather screen

  • Pressing the knob button toggles between TEMPERATURE → PRESSURE → HUMIDITY → TEMPERATURE view
  • Last view stored in NVS onLeave()
  • Stored view retrieved from NVS when returning to the screen (default: temperature)
  • Temperature view: Temperature °C, maximum and minimum
  • Pressure view: Pressure hPA, maximum and minimum
  • Humidity view: Humidity %, maximum and minimum
  • Min and max values are runtime only, not persistent in NVS
  • Trend indicators (↑/↓) show the direction the value is developing in: rate estimate from a fast and a slow time-based EMA, with hysteresis (TrendIndicator). Time constants and rate thresholds are tuned per value and can be adjusted via the *_TREND_* constants in the header
Battery screen

  • Pressing the knob button toggles between HOUSE VOLTAGE → HOUSE CURRENT → HOUSE SOC → STARTER VOLTAGE → HOUSE VOLTAGE view
  • Last view stored in NVS onLeave()
  • Stored view retrieved from NVS when returning to the screen (default: house voltage)
  • House voltage view: voltage V, maximum and minimum
  • House current view: current A, maximum and minimum
  • House SoC view: state-of-charge %, maximum and minimum
  • Min and max values are runtime only, not persistent in NVS
  • Trend indicators (↑/↓) show the direction the value is developing in: rate estimate from a fast and a slow time-based EMA, with hysteresis (TrendIndicator). Time constants and rate thresholds are tuned per value and can be adjusted via the *_TREND_* constants in the header
Engine screen

  • Pressing the knob button cycles between EXHAUST → FUEL0 → FRESHWATER → EXHAUST view
  • Last view stored in NVS onLeave() (default: EXHAUST)
  • Engine, fuel tank and fresh water tank connections tracked independently; timeout: 6 seconds
  • Oil pressure and coolant temperature panels exist in the SquareLine project as placeholders for upcoming HALMET data; always hidden for now

EXHAUST view:

  • Exhaust temperature in °C (converted from Kelvin)
  • Session min and max temperatures (runtime only, not persistent in NVS)
  • Trend indicator (↑/↓) based on a fast/slow EMA rate estimate (TrendIndicator) — appears when the temperature changes faster than 1 °C/min

FUEL0 view:

  • Fuel arc gauge: arc range 0–100 % of tank, label shows calculated litres (tank capacity: 400 L)
  • Dynamic arc color based on fuel level:
    • Green: ≥ 25 %
    • Yellow: 10–25 %
    • Red: < 10 %
  • On disconnect: labels show "---"

FRESHWATER view:

  • Fresh water arc gauge: arc range 0–100 % of tank, label shows calculated litres (tank capacity: 80 L)
  • Same dynamic arc colors and thresholds as the fuel gauge (green ≥ 25 %, yellow 10–25 %, red < 10 %)
  • Own arc render cache and connection tracking, independent of the fuel and exhaust feeds
  • On disconnect: labels show "---"
Celestial screen

A sextant practice aid: shows where suitable bodies stand relative to the bow and how high they are. The navigator does the actual sight reduction separately; the display targets 1' in Hc, 4 s in time and 1° in Zn.

  • Hc is geocentric, as in the Nautical Almanac and sight reduction (apparent place of date, no refraction, no parallax) — for the Moon this differs from what the sextant shows by up to ~1°, corrected via HP as usual
  • Computed with Astronomy Engine in double precision; star positions from Hipparcos (57 navigational stars) with proper motion applied. Host tests agree with JPL Horizons to 0.12' in Hc
  • Centre label: blank line, HDG true 000°, latitude dd°mm,m'N, longitude ddd°mm,m'E, GNSS UTC hh:mm:ss, air pressure 1010 hPa, temperature 18°C
  • Body labels: name (star names longer than 6 characters shortened, e.g. Betelg.), Hc dd°mm,m', Zn ddd°
  • Star chart: zenith (Hc 90°) at the centre, horizon (Hc 0°) on the 380 px circle, altitude linear; direction relative to true heading
  • Bodies shown:
    • Sun and Moon between their actual rise and set: upper limb on the sea horizon with standard refraction (34'), the same definition as Astronomy Engine's rise/set search. For the Sun this is geocentric Hc ≈ -50'; for the Moon, because of its ~57' parallax, about Hc +7'. A body near the horizon can therefore show a slightly negative Hc
    • In twilight (Sun Hc -3°00,0' … -12°00,0', inclusive — mid civil twilight through the whole of nautical twilight) three bodies chosen for azimuths ~120° apart, Hc preferably 15°–65° (hard limits 10°–75°), brightness, and distance from the Moon: one planet and two stars when a planet scores well, otherwise three stars. A planet set gets a bonus worth ~30° of spread
    • Hysteresis: the set is re-evaluated every 60 s and replaced only if the new one is clearly better, or at once if a body leaves the hard limits
  • Pressing the knob button cycles the chart view FROM ZENITH → FROM VESSEL → NORTH UP → FROM ZENITH; the view name replaces the centre data for 3 s on every change and when the screen is entered:
    • FROM ZENITH (default): looking down on the boat, bow up, bearings clockwise
    • FROM VESSEL: looking up at the sky from the boat, bow down, bearings counter-clockwise (the starboard quarter is top right)
    • NORTH UP: looking down from the zenith with true north up; needs no heading, bow arrow replaced by the cardinal points N, E, S, W at the screen edges
  • Last view stored in NVS onLeave() (namespace "celestial", key "view")
  • Updates once per UTC second; the astronomy runs on its own FreeRTOS task on core 0 and only while the screen is active
  • Data freshness, each source separately: stale values show dashes, never as fresh
    • Heading, in two steps (FROM ZENITH and FROM VESSEL): after 2 s ---° and the body texts turn red, but the bodies are still placed with the last heading; after 4 s the bodies are hidden. Texts turn white and bodies reappear as soon as the heading returns. NORTH UP does not use the heading: only the HDG line shows ---°
    • Position (5 s) or GNSS time (10 s): all bodies hidden
    • Pressure and temperature (6 s): ---- hPa / --°C
  • Known limitation: the centre data label covers bodies higher than ~65°
Brightness screen

  • Sun icon image and current brightness percentage label
  • Screen always entered in IDLE with the arc overlay hidden (onEnter()), regardless of how the screen was left
  • Knob button press enters ADJUSTING mode: arc overlay appears
  • Knob rotation in ADJUSTING mode: ±2% brightness, updates arc, label and backlight in real-time
  • 3-second timeout after last rotation → saves to NVS and returns to idle
  • Brightness range: 2%-100% (2% minimum prevents screen going completely dark)
  • Default: 48% (~122/255)
  • Persistence: ESP32 Preferences (NVS), namespace "display", key "brightness"
  • PWM: GPIO6, 5 kHz, 8-bit
Knob behavior
Screen Button press Rotation (normal) Rotation (special)
Compass Cycle HEADING/COG/SOG view Switch screen —
Attitude Cycle ATTITUDE/MINMAX/DEPTH view Switch screen —
Weather Toggle TEMPERATURE/PRESSURE/HUMIDITY view Switch screen —
Battery Toggle HOUSE VOLTAGE/HOUSE CURRENT/HOUSE SOC/STARTER VOLTAGE view Switch screen —
Engine Cycle EXHAUST/FUEL0/FRESHWATER view Switch screen —
Celestial Cycle FROM ZENITH/FROM VESSEL/NORTH UP chart view Switch screen —
Brightness Enter ADJUSTING mode Switch screen ±2% brightness (ADJUSTING mode only)

Screen carousel order:

  • Clockwise: COMPASS → ATTITUDE → WEATHER → BATTERY → ENGINE → CELESTIAL → BRIGHTNESS → COMPASS
  • Counter-clockwise: COMPASS → BRIGHTNESS → CELESTIAL → ENGINE → BATTERY → WEATHER → ATTITUDE → COMPASS

Screen carousel is scalable, new screens may be added.

ESP-NOW communication

All ESP-NOW messages are wrapped in the payload of ESPNowPacket.

template <typename TPayload>
  struct ESPNowPacket {
    ESPNowHeader hdr;
    TPayload payload;
} __attribute__((packed));

ESPNowHeader contains `ESPNOW_MAGIC = 0x45534E57' ("ESNW") which identifies the packets from others on the same channel.

struct ESPNowHeader {
   uint32_t magic;           // ESPNOW_MAGIC ('E''S''N''W')
   uint8_t  msg_type;        // ESPNowMsgType
   uint8_t  payload_len;     // payload length in bytes (max 250)
   uint8_t  reserved[2];     // padding, set to zero
} __attribute__((packed));

ESPNowMsgType identifies the content delivered, topped with the payload length information in the header.

espnow_protocol.h is a shared file, copied by hand into every ESP32 project on the boat, and ESPNowMsgType is a single fleet-wide number space. A change is not done until every copy is identical — never reconcile two versions field by field.

Sample types:

enum class ESPNowMsgType : uint8_t {
   HEADING_DELTA        = 1,  // CMPS14-ESP32-SignalK-gateway
   BATTERY_DELTA        = 2,  // VEDirect-ESP32-SignalK-gateway
   WEATHER_DELTA        = 3,  // BME280-ESP32-SignalK-gateway
   GNSS_DELTA           = 4,  // UBLOX-ESP32-SignalK-gateway
   HALMET_ENGINE_DELTA  = 5,  // HALMET-ESP32-SignalK-gateway
   HALMET_TANK_DELTA    = 6,  // HALMET-ESP32-SignalK-gateway
   HALMET_WATER_DELTA   = 7,  // HALMET-ESP32-SignalK-gateway
   DEPTH_DELTA          = 8,  // Relayed NMEA2000 source
   DATETIME_DELTA       = 9,  // UBLOX-ESP32-SignalK-gateway
};

Types 1-8 are consumed by this project. DATETIME_DELTA (9) exists in the shared protocol for other receivers on the boat and is ignored here.

Sample payloads:

struct HeadingDelta {
   float heading_rad;       // Magnetic heading (radians)
   float heading_true_rad;  // True heading (radians)
   float pitch_rad;         // Pitch (radians)
   float roll_rad;          // Roll (radians)
};

struct WeatherDelta {
   float temperature_c;   // °C
   float humidity_p;      // percent
   float pressure_hpa;    // hPa
};

struct BatteryDelta {
   float house_voltage;   // house bank volts
   float house_current;   // house bank amps
   float house_power;     // house bank watts
   float house_soc;       // house bank soc percent
   float start_voltage;   // starter battery volts
};

struct GnssDelta {
   float lat_deg;        // Latitude, decimal degrees
   float lon_deg;        // Longitude, decimal degrees
   float sog_ms;         // Speed over ground, m/s
   float cog_true_rad;   // Course over ground (true), radians
   float mag_var_rad;    // Magnetic variation (WMM), radians — NAN until first fix
   uint8_t satellites;   // SIV
   uint8_t fix_type;     // 0=no fix, 3=3D, 4=GNSS+DR
   uint8_t fix_ok;       // getGnssFixOk() ? 1 : 0
   uint8_t reserved;
};

struct HALMETEngineDelta {
   float exhaust_temp_k;    // propulsion.0.exhaustTemperature [K]
};

struct HALMETTankDelta {
   float fuel_level_ratio;  // tanks.fuel.0.currentLevel [0.0..1.0]
};

struct HALMETWaterDelta {
   float water_level_ratio;  // tanks.freshWater.0.currentLevel [0.0..1.0]
};

// Depth relayed from NMEA2000 source, will be replaced by a clean ESP32 based sender later.
// A relayed value carries no freshness of its own, so both signals are required:
//   - a field is NAN when that individual path is stale or has never arrived
//   - age_ms describes the depth feed as a whole (bottom lost, or N2K chain down)
struct DepthDelta {
   float    below_surface_m;     // environment.depth.belowSurface [m]
   float    below_transducer_m;  // environment.depth.belowTransducer [m]
   float    below_keel_m;        // environment.depth.belowKeel [m]
   uint32_t age_ms;              // ms since the freshest of the three; UINT32_MAX = never received
};

Receives at ~20 Hz, in radians (sent by CMPS14-ESP32-SignalK-gateway), as broadcast:

  • ESPNowPacket<HeadingDelta>:
    • 24 B packet, 8 B header + 16 B payload
    • Payload: HeadingDelta struct (heading_rad, heading_true_rad, pitch_rad, roll_rad - equal to what SignalK server gets from the gateway)
    • HeadingDelta converted into HeadingData, an internal data struct for CrowPanel implementation

Receives at ~0.5 Hz, in °C, % and hPA (sent by BME280-ESP32-SignalK-gateway), as broadcast:

  • ESPNowPacket<WeatherDelta>:
    • 20 B packet, 8 B header + 12 B payload
    • Payload: WeatherDelta struct (temperature_c, humidity_p, pressure_hpa)

Receives at ~1 Hz (sent by UBLOX-ESP32-SignalK-gateway), as broadcast:

  • ESPNowPacket<GnssDelta>:
    • 32 B packet, 8 B header + 24 B payload
    • Payload: GnssDelta struct (lat_deg, lon_deg, sog_ms, cog_true_rad, mag_var_rad, satellites, fix_type, fix_ok)
    • GnssDelta converted into GnssData, an internal data struct: cog_true_x10 (0-3599), sog_knots_x10 (knots x 10), fix_ok
  • ESPNowPacket<DateTimeDelta> (~2 s cadence):
    • 16 B packet, 8 B header + 8 B payload
    • Payload: DateTimeDelta struct (unix_utc whole seconds, time_valid)
    • Used by CelestialUI: UTC is extrapolated between packets with millis(); stale after 10 s

Receives at ~1 Hz, in V, A and % (sent by VEDirect based sender), as broadcast:

  • ESPNowPacket<BatteryDelta>:
    • 28 B packet, 8 B header + 20 B payload
    • Payload: BatteryDelta struct (house_voltage, house_current, house_power, house_soc, start_voltage)

Receives at ~1 Hz (sent by HALMET-ESP32-SignalK-gateway), as broadcast:

  • ESPNowPacket<HALMETEngineDelta>:
    • 12 B packet, 8 B header + 4 B payload
    • Payload: HALMETEngineDelta struct (exhaust_temp_k — converted to °C in EngineUI)
  • ESPNowPacket<HALMETTankDelta>:
    • 12 B packet, 8 B header + 4 B payload
    • Payload: HALMETTankDelta struct (fuel_level_ratio — 0.0 to 1.0, scaled to litres in EngineUI)
  • ESPNowPacket<HALMETWaterDelta>:
    • 12 B packet, 8 B header + 4 B payload
    • Payload: HALMETWaterDelta struct (water_level_ratio — 0.0 to 1.0, scaled to litres in EngineUI)

Receives at ~1 Hz, in meters (sent by a temporary NMEA2000 relay), as broadcast:

  • ESPNowPacket<DepthDelta>:
    • 24 B packet, 8 B header + 16 B payload
    • Payload: DepthDelta struct (below_surface_m, below_transducer_m, below_keel_m, age_ms)
    • Relayed from NMEA2000, not measured by a dedicated ESP32 sender — AttitudeUI gates it on both the ESP-NOW RX timestamp (6 s) and the in-payload age_ms (5 s)

Channel: ESP-NOW devices must be on the same WiFi channel. Configured to channel 6 (static constexpr uint8_t ESP_NOW_CHANNEL = 6 in CrowPanelApplication.h). Set your router to a fixed channel 6. This allows senders to operate both on WiFi and ESP-NOW, using WiFi's channel for ESP-NOW. Avoid channel jumping by setting a fixed channel in the router.

Deadband: Compass sender has 0.05° deadband — no packet sent if heading and attitude change less than 0.05°. CrowPanel has an additional 0.5° threshold for compass rose rotation rendering only.

NOTE: Requires CMPS14-ESP32-SignalK-gateway v1.4.0, UBLOX-ESP32-SignalK-gateway v1.0.0 (v1.3.0 for the celestial screen's GNSS time), BME280-ESP32-SignalK-gateway v1.0.1, VEDirect-ESP32-SignalK-gateway v1.0.0 and HALMET-ESP32-SignalK-gateway v1.3.0 (fresh water tank), or newer. Depth requires an NMEA2000 relay broadcasting DepthDelta (msg type 8).

Project structure

File(s) Description
ESP32-Crowpanel-compass.ino Owns CrowPanelApplication app, contains setup() and loop()
CrowPanelApplication.h/.cpp Class CrowPanelApplication, the "app" — owns all instances
espnow_protocol.h Wire protocol (namespace ESPNow), shared by hand across every ESP32 project on the boat: ESPNowHeader, ESPNowPacket<T>, ESPNowMsgType, HeadingData/Delta, GnssData/Delta, WeatherDelta, BatteryDelta, HALMETEngineDelta, HALMETTankDelta, HALMETWaterDelta, HALMETOilDelta (not used here), DepthDelta, DateTimeDelta
IScreenUI.h Abstract base class for all UI adapter class implementations
ESPNowReceiver.h/.cpp Class ESPNowReceiver — ESP-NOW receive (receive-only)
CompassUI.h/.cpp Class CompassUI — compass screen adapter, realizes IScreenUI
AttitudeUI.h/.cpp Class AttitudeUI — attitude screen adapter, realizes IScreenUI
WeatherUI.h/cpp Class WeatherUI - weather screen adapter, realizes IScreenUI
BatteryUI.h/cpp Class BatteryUI — battery screen adapter, realizes IScreenUI
EngineUI.h/.cpp Class EngineUI — engine screen adapter, realizes IScreenUI
CelestialUI.h/.cpp Class CelestialUI — celestial screen adapter, realizes IScreenUI
CelestialEngine.h/.cpp Class CelestialEngine — FreeRTOS task (core 0) running the astronomy at 1 Hz while the celestial screen is active
CelestialCalculator.h/.cpp Class CelestialCalculator — geocentric Hc/Zn of Sun, Moon, planets and stars via Astronomy Engine
CelestialSelector.h/.cpp Class CelestialSelector — twilight body selection (planet + two stars, or three stars) with hysteresis
CelestialFormat.h Header-only label formatting, star chart placement and freshness helpers
NavStars.h/.cpp The 57 navigational stars (Hipparcos J2000 positions, proper motions, magnitudes)
astronomy.h/.c Astronomy Engine 2.1.19 (MIT) — unmodified except ASTRONOMY_ENGINE_NO_CURRENT_TIME defined at the top of astronomy.h
TrendIndicator.h Class TrendIndicator — header-only ↑/↓ trend estimate (fast/slow EMA + hysteresis), shared by WeatherUI, BatteryUI and EngineUI
TrendLabel.h applyTrend() — shows a TrendIndicator trend on an LVGL label
BrightnessUI.h/.cpp Class BrightnessUI — brightness screen adapter + adjustment state machine, realizes IScreenUI
RotaryEncoder.h/.cpp Class RotaryEncoder — rotary knob rotation and button, FreeRTOS tasks
ScreenManager.h/.cpp Class ScreenManager — Scalable screen carousel management
version.h Software version string SW_VERSION
lv_conf.h LVGL configuration file based on the template provided by LVGL library
Crowpanel_ST7701_Init.h/.cpp Arduino_RGB_Display init table for CrowPanel display - crowpanel_st7701_type5_init_operations
ui.h/.c SquareLine Studio generated — UI init
ui_CompassScreen.h/.c SquareLine Studio generated
ui_AttitudeScreen.h/.c SquareLine Studio generated
ui_WeatherScreen.h/.c SquareLine Studio generated
ui_BatteryScreen.h/.c SquareLine Studio generated
ui_EngineScreen.h/.c SquareLine Studio generated
ui_CelestialScreen.h/.c SquareLine Studio generated
ui_BrightnessScreen.h/.c SquareLine Studio generated
ui_helpers.h/.c SquareLine Studio generated
ui_font_*.c Custom fonts
ui_img_*.c Images (compass rose, icons)
UI/ SquareLine Studio project
tests/celestial/ Host unit tests for the celestial logic (run_tests.sh), with JPL Horizons and SIMBAD reference fixtures and the scripts that fetch them
docs/ Other documents

Hardware

Bill of materials
  1. Elecrow CrowPanel 2.1" HMI ESP32 Rotary Display, having:

    • ESP32-S3 module
    • 480x480 IPS round display (ST7701, RGB interface)
    • Rotary encoder with push button (PCF8574 I2C GPIO expander at 0x21)
  2. WiFi router with fixed channel 6

  3. CMPS14-ESP32-SignalK-gateway as ESP-NOW sender

  4. UBLOX-ESP32-SignalK-gateway as ESP-NOW sender

  5. BME280-ESP32-SignalK-gateway as ESP-NOW sender

  6. VEDirect-ESP32-SignalK-gateway as ESP-NOW sender

  7. HALMET-ESP32-SignalK-gateway as ESP-NOW sender

  8. 3D-printed mounting frame for CrowPanel:

No paid partnerships.

Software

  1. Arduino IDE 2.3.8
  2. Espressif Systems esp32 board package 3.3.8
  3. Additional libraries:
    • LVGL 9.5.0
    • Arduino GFX Library (by Moon On Our Nation) 1.6.5
    • PCF8574 (by Renzo Mischianti) 2.4.0
  4. SquareLine Studio 1.6.0 for UI design and code generation
  5. CMPS14-ESP32-SignalK-gateway v1.4.0
  6. UBLOX-ESP32-SignalK-gateway v1.0.0
  7. BME280-ESP32-SignalK-gateway v1.0.1
  8. VEDirect-ESP32-SignalK-gateway v1.0.0
  9. HALMET-ESP32-SignalK-gateway v1.3.0

Installation

  1. Clone the repo
    git clone https://github.com/mkvesala/ESP32-Crowpanel-compass.git
    
  2. Alternatively, download the code as zip
  3. Install required libraries in Arduino IDE (LVGL, Arduino_GFX_Library, PCF8574)
  4. Set ESP-NOW channel in CrowPanelApplication.h to match your router:
    static constexpr uint8_t ESP_NOW_CHANNEL = 6;
    
  5. Connect and power up the CrowPanel with USB
  6. Compile and upload with Arduino IDE (board: ESP32S3 Dev Module)
  7. Point the ESP-NOW senders to the same WiFi channel

Note that lv_conf.h is in project root (with default values from the library template). If you are using LVGL elsewhere, this file is probably under Arduino/libraries/ folder next to lvgl library folder. Check the settings and use either one to avoid conflicts.

SquareLine Studio note: SquareLine Studio clears the export directory completely on export. Always git commit before exporting from SquareLine Studio and set a temporary directory in project settings for the export folder.

Todo

Check open issues.

Debug

Performance characteristics on CrowPanel 2.1" (ESP32-S3):

Screen UI updates/5s LVGL avg LVGL max Notes
Compass (heading changing) ~52 ~48 ms ~160 ms 240x240 zoom=512, no alpha, antialias off, draw buffer 120 lines, adaptive LVGL tick scheduling
Compass (stable heading) 48-74 1-7 ms — 0.5° threshold prevents unnecessary re-renders
Attitude (data flowing) ~80 4-13 ms — Horizon line 680x4 px is cheap to render
Attitude (stable) ~83 <1 ms — Nothing to render

Compass rose lv_image_set_rotation() is the main performance bottleneck (only on the compass screen). PNG image stored in the image object is 240x240 pixels, no alpha, scaled with LVGL factor 512 to 480x480 pixels. Antialiasing is off. LVGL rendering is based on partial mode, using buffer of 480x120.

Security

Use at your own risk — not for safety-critical navigation!

This device receives data only via ESP-NOW broadcast on a local WiFi channel. There is no network server, no authentication and no sensitive data. Keep the device on a private boat WiFi network.

Credits

Software and libraries used are documented in the above sections.

Inspired by example source code by Elecrow.

Humidity icons created by Freepik - Flaticon

Temperature icons created by Freepik - Flaticon

Sun icons created by Freepik - Flaticon

Battery icons created by Freepik - Flaticon

Pressure icons created by Muhammad Ali - Flaticon

Exhaust pipe icons created by Iconiyo - Flaticon

Gas icons created by Pixel perfect - Flaticon

Gallon bottle icons created by AbtoCreative - Flaticon

Caution icons created by agus raharjo - Flaticon

Oil icons created by Magnific - Flaticon

Temperature icons created by Magnific - Flaticon

This is a companion project to my CMPS14-ESP32-SignalK-gateway, VEDirect-ESP32-SignalK-gateway, BME280-ESP32-SignalK-gateway, UBLOX-ESP32-SignalK-gateway and HALMET-ESP32-SignalK-gateway. Check the UML diagram below to see how these projects relate:

No paid partnerships.

Developed by Matti Vesala in collaboration with Claude.

See CONTRIBUTING.md for further details on development.