ตอนนี้กำลังใช้ Arduino ติดต่อกับ BMS ในแบตครับ รูปภาพเพิมเติ่มและข้อมูล เช็คได้ที่โพสนี้ครับ
https://forum.arduino.cc/t/false-calculation-of-the-bms-data-canbus/951480
อยากทราว่าจะเขียนรับค่ายังไงครับ ขอบคุณครับ
byte incomingBytes[8]; // array for 8 bytes incoming serial data
//byte message[] = {0x01,0x05,0x81,0x01,0x00,0x00}; //message to BMS to ask for battery SOC
byte message[] = {0x01,0x05,0x09,0x81,0x01,0x00,0x00};
int period = 3600000;
unsigned long time_now = 0;
void setup() {
Serial.begin(25000); // opens serial port, sets data rate to 9600 bps
Serial1.begin(25000); // opens serial port, sets data rate to 115200 bps
delay(5000); // a delay of 5 seconds to see the incoming data on screen
}
void loop() {
time_now = millis();
Serial1.write(message, sizeof(message)); // send request message to wake BMS if in deep sleep mode
delay(500); // delay of 500 ms
while(Serial1.read()>=0){
}
Serial1.write(message, sizeof(message)); //send request message
delay(500);
Serial.print("\n");
if (Serial1.available()) {
Serial1.readBytes(incomingBytes, 8);
}
for (int i=0; i<8; i++){ // print the received bytes
Serial.print(incomingBytes
, HEX);
Serial.print(" ");
}
unsigned long combined = 0; // clear it out
long x0 = incomingBytes[5]<<24;
long x1 = incomingBytes[4]<<16;
long x2 = incomingBytes[3]<<8;
long x3 = incomingBytes[2];
combined = x0 | x1 | x2 | x3; // combining required 4 data bytes of received 8 bytes
}
สอบถามวิธีส่งค่า Tx แล้วรับ Rx กลับ ผ่าน Arduino ครับ
https://forum.arduino.cc/t/false-calculation-of-the-bms-data-canbus/951480
อยากทราว่าจะเขียนรับค่ายังไงครับ ขอบคุณครับ
byte incomingBytes[8]; // array for 8 bytes incoming serial data
//byte message[] = {0x01,0x05,0x81,0x01,0x00,0x00}; //message to BMS to ask for battery SOC
byte message[] = {0x01,0x05,0x09,0x81,0x01,0x00,0x00};
int period = 3600000;
unsigned long time_now = 0;
void setup() {
Serial.begin(25000); // opens serial port, sets data rate to 9600 bps
Serial1.begin(25000); // opens serial port, sets data rate to 115200 bps
delay(5000); // a delay of 5 seconds to see the incoming data on screen
}
void loop() {
time_now = millis();
Serial1.write(message, sizeof(message)); // send request message to wake BMS if in deep sleep mode
delay(500); // delay of 500 ms
while(Serial1.read()>=0){
}
Serial1.write(message, sizeof(message)); //send request message
delay(500);
Serial.print("\n");
if (Serial1.available()) {
Serial1.readBytes(incomingBytes, 8);
}
for (int i=0; i<8; i++){ // print the received bytes
Serial.print(incomingBytes, HEX);
Serial.print(" ");
}
unsigned long combined = 0; // clear it out
long x0 = incomingBytes[5]<<24;
long x1 = incomingBytes[4]<<16;
long x2 = incomingBytes[3]<<8;
long x3 = incomingBytes[2];
combined = x0 | x1 | x2 | x3; // combining required 4 data bytes of received 8 bytes
}