├── README.md └── VEcan.ino /README.md: -------------------------------------------------------------------------------- 1 | # VEcan 2 | Communicating with Victron energy products, also compatible with other inverters and solar equipement 3 | 4 | Communication over canbus at 250kbps 5 | Battery information for system to use; 6 | -Battery Voltage 7 | -Battery Current 8 | -Battery Temperature 9 | -Charge Voltage Limit 10 | -Charge Current Limit 11 | -Dischcarge Voltage Limit 12 | -Discharge Current Limit 13 | -SOH 14 | -SOC 15 | -------------------------------------------------------------------------------- /VEcan.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | //variables for VE can 6 | uint16_t chargevoltage = 49100; //max charge voltage in mv 7 | uint16_t chargecurrent = 30000; //max charge current in ma 8 | uint16_t disvoltage = 42000; // max discharge voltage in mv 9 | uint16_t discurrent = 30000; // max discharge current in ma 10 | uint16_t SOH = 100; // SOH place holder 11 | 12 | unsigned char mes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 13 | unsigned char bmsname[8] = {'S', 'I', 'M', 'P', '-', 'B', 'M', 'S'}; 14 | unsigned char bmsmanu[8] = {'T', 'O', 'M', ' ', 'D', 'E', ' ', 'B'}; 15 | 16 | MCP_CAN CAN(9); //set CS pin for can controlelr 17 | 18 | int SOC =80; 19 | 20 | float PackVoltage = 46.7; 21 | float AvgTemperature = 20.5; 22 | uint16_t currentact = 0; 23 | 24 | void setup() { 25 | 26 | Serial.begin(115200); 27 | 28 | // put your setup code here, to run once: 29 | if(CAN.begin(MCP_ANY, CAN_250KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!"); 30 | else Serial.println("Error Initializing MCP2515..."); 31 | 32 | CAN.setMode(MCP_NORMAL); 33 | } 34 | 35 | void loop() { 36 | // put your main code here, to run repeatedly: 37 | VEcan(); 38 | delay(200); 39 | } 40 | 41 | 42 | void VEcan() //communication with Victron system over CAN 43 | { 44 | mes[0] = lowByte(chargevoltage / 100); 45 | mes[1] = highByte(chargevoltage / 100); 46 | mes[2] = lowByte(chargecurrent / 100); 47 | mes[3] = highByte(chargecurrent / 100); 48 | mes[4] = lowByte(discurrent / 100); 49 | mes[5] = highByte(discurrent / 100); 50 | mes[6] = lowByte(disvoltage / 100); 51 | mes[7] = highByte(disvoltage / 100); 52 | 53 | CAN.sendMsgBuf(0x351, 0, 8, mes); 54 | Serial.println(" "); 55 | for (int i = 0; i<8; i++) 56 | { 57 | Serial.print(mes[i]); 58 | Serial.print(" , "); 59 | } 60 | 61 | mes[0] = lowByte(SOC); 62 | mes[1] = highByte(SOC); 63 | mes[2] = lowByte(SOH); 64 | mes[3] = highByte(SOH); 65 | mes[4] = lowByte(SOC * 10); 66 | mes[5] = highByte(SOC * 10); 67 | mes[6] = 0; 68 | mes[7] = 0; 69 | 70 | CAN.sendMsgBuf(0x355, 0, 8, mes); 71 | Serial.println(" "); 72 | for (int i = 0; i<8; i++) 73 | { 74 | Serial.print(mes[i]); 75 | Serial.print(" , "); 76 | } 77 | 78 | mes[0] = lowByte(uint16_t(PackVoltage * 100)); 79 | mes[1] = highByte(uint16_t(PackVoltage * 100)); 80 | mes[2] = lowByte(uint16_t(currentact / 100)); 81 | mes[3] = highByte(uint16_t(currentact / 100)); 82 | mes[4] = lowByte(uint16_t(AvgTemperature * 10)); 83 | mes[5] = highByte(uint16_t(AvgTemperature * 10)); 84 | 85 | CAN.sendMsgBuf(0x356, 0, 8, mes); 86 | Serial.println(" "); 87 | for (int i = 0; i<8; i++) 88 | { 89 | Serial.print(mes[i]); 90 | Serial.print(" , "); 91 | } 92 | 93 | mes[0] = 0; 94 | mes[1] = 0; 95 | mes[2] = 0; 96 | mes[3] = 0; 97 | mes[4] = 0; 98 | mes[5] = 0; 99 | mes[6] = 0; 100 | mes[7] = 0; 101 | 102 | CAN.sendMsgBuf(0x35A, 0, 8, mes); 103 | 104 | Serial.println(" "); 105 | for (int i = 0; i<8; i++) 106 | { 107 | Serial.print(mes[i]); 108 | Serial.print(" , "); 109 | } 110 | 111 | delay(5); 112 | CAN.sendMsgBuf(0x370, 0, 8, bmsname); 113 | 114 | Serial.println(" "); 115 | for (int i = 0; i<8; i++) 116 | { 117 | Serial.print(bmsname[i]); 118 | Serial.print(" , "); 119 | } 120 | delay(5); 121 | CAN.sendMsgBuf(0x35E, 0, 8, bmsmanu); 122 | Serial.println(" "); 123 | for (int i = 0; i<8; i++) 124 | { 125 | Serial.print(bmsmanu[i]); 126 | Serial.print(" , "); 127 | } 128 | 129 | } 130 | --------------------------------------------------------------------------------