A Python script for communicating with Victron VE.Direct devices (such as BlueSolar and SmartSolar MPPT charge controllers) using the HEX protocol via a UART (serial) connection. This implementation is based on the official documentation: BlueSolar-HEX-protocol.pdf (Rev 18). Tested with MPPT 100/50.
- Construct Library: Utilizes the
constructtool for declarative building and parsing of binary data frames. - HEX Validation: Handles frame formatting, automatic checksum calculation, and response verification.
- Register Abstraction:
get_register(): Automatically handles decoding, scaling, and value mapping (e.g., 3 -> "Bulk").set_register(): Safely writes values to the device with full error code handling.
Install the required dependencies using the pip package manager:
pip install pyserial constructThe library offers an extended class called vedirectDEV, which includes pre-built methods for the most common MPPT device parameters.
from vedirect import vedirectDEV
# Initialize the device (specify the correct serial port)
mppt = vedirectDEV("/dev/ttyAMA0", baudrate=19200, debug=False)
try:
print(f"Model: {mppt.get_model_name()}")
print(f"Charger Voltage: {mppt.get_charger_voltage()} V")
print(f"Panel Power: {mppt.get_panel_power()} W")
print(f"Current State: {mppt.get_device_state()}")
finally:
mppt.disconnect()# Turn on the Load Output
mppt.set_load_output_control("ON")
# Set External Control mode (for remote voltage/current control)
mppt.set_device_in_external_control_mode()Below is a table of selected registers supported by the module:
| Register Key | ID (HEX) | Scale | Description |
|---|---|---|---|
| PANEL_VOLTAGE | 0xEDBB | 0.01 | Photovoltaic panel voltage (V) |
| CHARGER_VOLTAGE | 0xEDD5 | 0.01 | Battery charging voltage (V) |
| PANEL_POWER | 0xEDBC | 0.01 | Current panel power (W) |
| DEVICE_STATE | 0x0201 | 1 | Current operating state (e.g., Bulk, Float) |
| YIELD_TODAY | 0xEDD3 | 0.01 | Today's energy yield (kWh) |
The device verifies every frame for consistency. The sum of all binary bytes (command + data + checksum) modulo 256 must equal
Note
VE.Direct MPPT devices broadcast text data (Text Mode) continuously. This library automatically ignores the text stream and correctly captures HEX responses, which start with the : character.
Warning
Writing incorrect values to registers (e.g., BATTERY_VOLTAGE_SETTING) can permanently damage your batteries. Always verify the manufacturer's allowed ranges before sending a command.
Image below shows electrical serial connection.
Tested with 3.3V UART on Raspberry Pi 5. MPPT 100/50 uses 5V UART therefore there is a need of Logic Level Converter 3,3V/5V. Tested with the cheapest one and works fine.
UART
┌────────────┐ ┌──────────┐ ┌────────────┐
│ 3 │<-----TX ---->│ │<----- RX ----->│ 10 │
│ Victron 2 │<-----RX ---->│ LOGIC │<----- TX ----->│ 8 RPI 5 │
│ DEV 4 │<---- 5V ---->│ Level │<----- 3.3V---->│ 1 GPIO │
│ 1 │<--- GND ---->│converter │<----- GND --->│ 6 │
│ │ │ │ │ │
└────────────┘ └──────────┘ └────────────┘