0

I am trying to set the SET parameters in a Daly BMS by programming an ESP32.

Below is the sample code. I am not able to set the parameters or receive any response.

#include <HardwareSerial.h>

HardwareSerial SerialPort(2);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
}

void loop() {
  byte data[] = {22, 104, 0, 0, 0, 0, 0, 0};
  byte frame[13];
  frame[0] = 165;
  frame[1] = 64;
  frame[2] = 31;
  frame[3] = 8;
  
  for (int i = 0; i < 8; i++) {
    frame[i + 4] = data[i];
  } 
  
  frame[12] = 138;
 
  for (int i = 0; i < 13; i++) {
    //Serial2.write(frame, 13);
    Serial2.write(frame[i]);
    //delay(50);
  }

  Serial.println("start of frame");

  for (int i = 0; i < 13; i++) {
    Serial.println(frame[i]);
  }

  Serial.println("end of frame");
  Serial.println("start of response");
   
  while (Serial2.available()) {
    Serial.println((String (Serial2.read()));
  }

  Serial.println("end of response");  
}  

Can someone please inform me whether any modifications are required and if any new methods or coding are available?

ocrdu
  • 8,705
  • 21
  • 30
  • 42

0 Answers0