Skip to content

Commit

Permalink
Merge pull request #56 from dalathegreat/user-config-rewrite
Browse files Browse the repository at this point in the history
Rewrite with central user settings file
  • Loading branch information
dalathegreat authored Sep 15, 2023
2 parents 120fa9b + b1ee3ae commit 363fdbe
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 136 deletions.
5 changes: 2 additions & 3 deletions Software/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ void update_values_i3_battery()
CANstillAlive--;
}

if(printValues)
{ //values heading towards the inverter
#ifdef DEBUG_VIA_USB
Serial.print("SOC% battery: ");
Serial.print(Display_SOC);
Serial.print(" SOC% sent to inverter: ");
Expand All @@ -114,7 +113,7 @@ void update_values_i3_battery()
Serial.print(max_target_charge_power);
Serial.print(" Max discharge power: ");
Serial.print(max_target_discharge_power);
}
#endif
}

void receive_can_i3_battery(CAN_frame_t rx_frame)
Expand Down
5 changes: 1 addition & 4 deletions Software/BMW-I3-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define BMW_I3_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 24000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 1; //Should debug values be printed to serial output?

// These parameters need to be mapped for the inverter
extern uint16_t SOC;
Expand Down
1 change: 1 addition & 0 deletions Software/BYD-CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BYD_CAN_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

extern uint16_t SOC;
extern uint16_t StateOfHealth;
Expand Down
5 changes: 2 additions & 3 deletions Software/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void update_values_chademo_battery()
CANstillAlive--;
}

if(printValues)
{ //values heading towards the modbus registers
#ifdef DEBUG_VIA_USB
if(errorCode > 0)
{
Serial.print("ERROR CODE ACTIVE IN SYSTEM. NUMBER: ");
Expand Down Expand Up @@ -120,7 +119,7 @@ void update_values_chademo_battery()
Serial.println(temperature_min);
Serial.print("Temperature Max: ");
Serial.println(temperature_max);
}
#endif
}

void receive_can_chademo_battery(CAN_frame_t rx_frame)
Expand Down
5 changes: 1 addition & 4 deletions Software/CHADEMO-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define CHADEMO_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 24000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 0; //Should debug values be printed to serial output?

// These parameters need to be mapped
extern uint16_t SOC;
Expand Down
5 changes: 2 additions & 3 deletions Software/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ void update_values_imiev_battery()
CANstillAlive--;
}

if(printValues)
{ //values heading towards the modbus registers
#ifdef DEBUG_VIA_USB
Serial.print("BMU SOC: ");
Serial.println(BMU_SOC);
Serial.print("BMU Current: ");
Serial.println(BMU_Current);
Serial.print("BMU Battery Voltage: ");
Serial.println(BMU_PackVoltage);
}
#endif
}

void receive_can_imiev_battery(CAN_frame_t rx_frame)
Expand Down
5 changes: 1 addition & 4 deletions Software/IMIEV-CZERO-ION-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define IMIEV_CZERO_ION_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 22000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE_ZOE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE_ZOE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 1; //Should modbus values be printed to serial output?

// These parameters need to be mapped for the Gen24
extern uint16_t SOC;
Expand Down
5 changes: 2 additions & 3 deletions Software/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ void update_values_kiaHyundai_64_battery()
CANstillAlive--;
}

if(printValues)
{ //values heading towards the inverter
#ifdef DEBUG_VIA_USB
Serial.print("SOC% candidate 1: ");
Serial.println(SOC_1);
Serial.print("SOC% candidate 2: ");
Serial.println(SOC_2);
Serial.print("SOC% candidate 3: ");
Serial.println(SOC_3);
}
#endif
}

void receive_can_kiaHyundai_64_battery(CAN_frame_t rx_frame)
Expand Down
5 changes: 1 addition & 4 deletions Software/KIA-HYUNDAI-64-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define KIA_HYUNDAI_64_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 60000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 1; //Should debug values be printed to serial output?

// These parameters need to be mapped for the Gen24
extern uint16_t SOC;
Expand Down
5 changes: 2 additions & 3 deletions Software/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ void update_values_leaf_battery()
}

/*Finally print out values to serial if configured to do so*/
if(printValues)
{
#ifdef DEBUG_VIA_USB
if(errorCode > 0)
{
Serial.print("ERROR CODE ACTIVE IN SYSTEM. NUMBER: ");
Expand Down Expand Up @@ -350,7 +349,7 @@ void update_values_leaf_battery()
Serial.print(Battery_current_1);
Serial.print(" Current 2: ");
Serial.println(Battery_current_2);
}
#endif
}

void receive_can_leaf_battery(CAN_frame_t rx_frame)
Expand Down
6 changes: 1 addition & 5 deletions Software/NISSAN-LEAF-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
#define NISSAN_LEAF_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 30000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
//#define INTERLOCK_REQUIRED //Uncomment this line to skip requiring both high voltage connectors to be seated on the LEAF battery
static byte printValues = 0; //Should modbus values be printed to serial output?

// These parameters need to be mapped for the Gen24
extern uint16_t SOC;
Expand Down
1 change: 1 addition & 0 deletions Software/PYLON-CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PYLON_CAN_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

extern uint16_t SOC;
extern uint16_t StateOfHealth;
Expand Down
7 changes: 3 additions & 4 deletions Software/RENAULT-ZOE-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void update_values_zoe_battery()
StateOfHealth = (LB_SOH * 100); //Increase range from 99% -> 99.00%

//Calculate the SOC% value to send to Fronius
LB_SOC = LB_MIN_SOC + (LB_MAX_SOC - LB_MIN_SOC) * (LB_SOC - MINPERCENTAGE_ZOE) / (MAXPERCENTAGE_ZOE - MINPERCENTAGE_ZOE);
LB_SOC = LB_MIN_SOC + (LB_MAX_SOC - LB_MIN_SOC) * (LB_SOC - MINPERCENTAGE) / (MAXPERCENTAGE - MINPERCENTAGE);
if (LB_SOC < 0)
{ //We are in the real SOC% range of 0-20%, always set SOC sent to Fronius as 0%
LB_SOC = 0;
Expand Down Expand Up @@ -98,8 +98,7 @@ void update_values_zoe_battery()
temperature_min;
temperature_max;

if(printValues)
{ //values heading towards the modbus registers
#ifdef DEBUG_VIA_USB
Serial.print("BMS Status (3=OK): ");
Serial.println(bms_status);
Serial.print("Max discharge power: ");
Expand All @@ -118,7 +117,7 @@ void update_values_zoe_battery()
Serial.println(temperature_min);
Serial.print("Temperature Max: ");
Serial.println(temperature_max);
}
#endif
}

void receive_can_zoe_battery(CAN_frame_t rx_frame)
Expand Down
5 changes: 1 addition & 4 deletions Software/RENAULT-ZOE-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define RENAULT_ZOE_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#include "USER_SETTINGS.h"

#define BATTERY_WH_MAX 22000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE_ZOE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE_ZOE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 1; //Should modbus values be printed to serial output?

// These parameters need to be mapped for the Gen24
extern uint16_t SOC;
Expand Down
7 changes: 3 additions & 4 deletions Software/SOLAX-CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CAN_frame_t SOLAX_100A001 = {.FIR = {.B = {.DLC = 0,.FF = CAN_frame_ext,}},.MsgI

void CAN_WriteFrame(CAN_frame_t* tx_frame)
{
if(dual_can){
#ifdef DUAL_CAN
CANMessage MCP2515Frame; //Struct with ACAN2515 library format, needed to use the MCP2515 library
MCP2515Frame.id = tx_frame->MsgID;
MCP2515Frame.ext = tx_frame->FIR.B.FF;
Expand All @@ -39,10 +39,9 @@ if(dual_can){
MCP2515Frame.data[i] = tx_frame->data.u8[i];
}
can.tryToSend(MCP2515Frame);
}
else{
#else
ESP32Can.CANWriteFrame(tx_frame);
}
#endif
}

void update_values_can_solax()
Expand Down
2 changes: 1 addition & 1 deletion Software/SOLAX-CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <Arduino.h>
#include "ESP32CAN.h"
#include "config.h"
#include "USER_SETTINGS.h"

#include "ACAN2515.h"
extern ACAN2515 can;
extern bool dual_can;

extern uint16_t SOC;
extern uint16_t StateOfHealth;
Expand Down
26 changes: 2 additions & 24 deletions Software/Software.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
/* Select battery used */
#define BATTERY_TYPE_LEAF // See NISSAN-LEAF-BATTERY.h for more LEAF battery settings
//#define TESLA_MODEL_3_BATTERY // See TESLA-MODEL-3-BATTERY.h for more Tesla battery settings
//#define RENAULT_ZOE_BATTERY // See RENAULT-ZOE-BATTERY.h for more Zoe battery settings
//#define BMW_I3_BATTERY // See BMW-I3-BATTERY.h for more i3 battery settings
//#define IMIEV_ION_CZERO_BATTERY // See IMIEV-CZERO-ION-BATTERY.h for more triplet battery settings
//#define KIA_HYUNDAI_64_BATTERY // See KIA-HYUNDAI-64-BATTERY.h for more battery settings
//#define CHADEMO // See CHADEMO.h for more Chademo related settings

/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */
#define MODBUS_BYD //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU
//#define CAN_BYD //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus
//#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus

/* Other options */
#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle precharge/contactor+/contactor- closing sequence
//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM logic for contactors, which lower power consumption and heat generation
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters)

/* Do not change any code below this line unless you are sure what you are doing */
/* Only change battery specific settings and limits in their respective .h files */
/* Only change battery specific settings in "USER_SETTINGS.h" and limits in their respective .h files */

#include <Arduino.h>
#include "HardwareSerial.h"
#include "USER_SETTINGS.h"
#include "config.h"
#include "Logging.h"
#include "mbServerFCs.h"
Expand All @@ -38,13 +19,10 @@ CAN_device_t CAN_cfg; // CAN Config
const int rx_queue_size = 10; // Receive Queue size

#ifdef DUAL_CAN
bool dual_can = 1;
#include "ACAN2515.h"
static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; // 8 MHz
ACAN2515 can(MCP2515_CS, SPI, MCP2515_INT);
static ACAN2515_Buffer16 gBuffer;
#else
bool dual_can = 0;
#endif

//Interval settings
Expand Down
Loading

0 comments on commit 363fdbe

Please sign in to comment.