GitNik1 / VEBus

Arduino library for communicating with Victron Energy devices via VE.BUS
GNU General Public License v3.0
3 stars 1 forks source link
arduino-library communication esp32

VEBus

This library is used to work with an ESP32 Arduino (not for the AVR family as the library uses std::vector).

Built With

Dependencies

arduino-esp32 boardlibrary >= 2.0.8 for < 2.0.8 undefine UART_MODE_RS485 in the vebus.h file

//#define UART_MODE_RS485
#ifdef UART_MODE_RS485
#include "hal/uart_types.h"
#endif

Getting Started

This is a sample guide for setting up your project locally.

Hardware

The RS485 IC can be a MAX485 or max1348

[!TIP] For a simple start (PlugAndPlay) you can use an esp32 arduino board with integrated RS485 LILYGO T-CAN485

Software

There are a few examples to get you started with the library

Function descriptions

*.ino

void Receive(std::vector<uint8_t>& buffer)
{
    _vEBus.DestuffingFAtoFF(buffer);
    Serial.printf("Res: ");
    for (uint32_t j = 0; j < buffer.size(); j++) Serial.printf("%02X ", buffer[j]);
    Serial.println();
}

void setup()
{
    _vEBus.SetReceiveCallback(Receive);
}

[!TIP] If you don't want to see some messages, you can skip them using a blacklist or use the whitelist to see specific messages.


VEBus::Blacklist _blacklist[] = { {.value = 0xE4, .at = 4}, {.value = 0x55, .at = 4} };

void setup() { _vEBus.SetReceiveCallback(Receive, _blacklist, sizeofarray(_blacklist)); }


### Callback for response messages
```ruby
void SetResponseCallback(std::function<void(ResponseData&)> cb);

To parse all response messages, the callback can be used as follows. data.id is specified by the query to indicate that it is the response of the read operation.

*.ino

void Response(VEBus::ResponseData& data)
{
    if(requestId == data.id){}
    if(WinmonCommand == data.command && Settings == data.address){}
    //...to some stuff
}

void setup()
{
    _vEBus.SetResponseCallback(Response);
}

Write a value to Multiplus

uint8_t WriteViaID(RamVariables variable, int16_t rawValue, bool eeprom = false);
uint8_t WriteViaID(RamVariables variable, uint16_t rawValue, bool eeprom = false);
RequestResult WriteViaID(RamVariables variable, float value, bool eeprom = false);

uint8_t WriteViaID(Settings setting, int16_t rawValue, bool eeprom = false);
uint8_t WriteViaID(Settings setting, uint16_t rawValue, bool eeprom = false);
RequestResult WriteViaID(Settings setting, float value, bool eeprom = false);

To write a value, you have three ways to send it. You can store a value to a non-volatile memory. To do this you need to set the eeprom true

[!CAUTION] Be careful when repeatedly writing EEPROM (loop) EEPROM writes are limited

*.ino

void loop()
{
    if(dataToWrite == true)
    {
        _vEBus.WriteViaID(Settings::IMainsLimit, 7.2); //set 7.2A
    }
}

*.ino

void setup()
{
    _vEBus.ReadInfo(Settings::IMainsLimit);
}

void loop()
{
    if(dataToWrite == true)
    {
        _vEBus.WriteViaID(Settings::IMainsLimit, 7.2); //set 7.2A
    }
}

*.ino

void loop()
{
    if(dataToWrite == true)
    {
        _vEBus.WriteViaID(Settings::IMainsLimit, 72); //set 7.2A
    }
}

Read a value to Multiplus

uint8_t Read(RamVariables variable);
uint8_t Read(Settings setting);

To read a value

*.ino

void loop()
{
    if(dataToRead == true)
    {
        uint8_t requestId = _vEBus.Read(Settings::IMainsLimit);
    }
}

Supported devices with value interpretations

To do lists

Known issues

License

This project is licensed under the GNU General Public License v3.0 or later - see the LICENSE.md file for details

Acknowledgments