หลังจากลองมาหลายวันแล้ว ตอนแรกซึ่งใช้ python ติดต่อ กับ BMS ใน battery ซึ่งผลออกมาค้าง
ซึ่งจำต้องใช้ Arduino ติดต่อกับ BMS ซึ่งส่งค่าไปได้ และส่งกลับมา แต่ค่าที่ส่งไปเหมือนจะไม่ถูกต้องเลย
อยากสอบถามผู้ที่เคยศึกษาเรื่องนี้ อยากรบกวนให้ช่วยแนวทางให้ด้วยครับ เพราะค่า ที่ดึงจาก BMS จะนำไปต่อใน python และเปลี่ยนเป็น file json และส่งขึ้นไปใช้งานในงานถนัดๆ ไปซึ่ง งานช่วงหลังเตรียมไว้หมด แล้ว เหลือเพียงแค่ดึงค่า จาก BMS ครับ
arduino leonardo
battery
https://github.com/KomaCrazy/page-/blob/main/ENG2021002_%20InSight%20CANbus%20Specification.pdf
เป็นไฟล์เอกสารครับ ซึ่งลองพยายามแล้วแต่ไม่สำเร็จผล
อันนี้เป้นไฟล์ Aduino ครับ ตรงไฟล์ message ซึ่งลองแล้วก็ไม่ตอบสนองเลย
byte incomingBytes[8]; // array for 8 bytes incoming serial data
byte message[] = {0x01,0x05,0x09,0x81,0x01,0x00,0x00}; //message to BMS to ask for battery SOC
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);
if (Serial1.available()) {
Serial1.readBytes(incomingBytes, 8);
}
for (int i=0; i<8; i++){ // print the received bytes
Serial.print(incomingBytes
, HEX);
Serial.print(" ");
}
Serial.println();
Serial.println(" ");
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
Serial.print("Data value in HEX = ");
Serial.println(combined, HEX); // print the 4 combined HEX bytes in HEX
Serial.println("");
Serial.print("Data value in DEC = ");
Serial.println(combined, DEC); // print them in decimal
Serial.println("");
Serial.print("Battery SOC = ");
float batterySOC = (float)combined/1000000.0; //dividing the dec values by 1000000 to get the values of SOC in BMS register
Serial.print(batterySOC); // print the SOC value
Serial.println(" %");
Serial.println("");
while (millis() < time_now + period){
// delay of 10 minutes
}
}
อยากสอบถามวิธีส่งค่า Hex เพื่อไปติดต่อกับ BMS ใน แบต ผ่าน Arduino ครับ
ซึ่งจำต้องใช้ Arduino ติดต่อกับ BMS ซึ่งส่งค่าไปได้ และส่งกลับมา แต่ค่าที่ส่งไปเหมือนจะไม่ถูกต้องเลย
อยากสอบถามผู้ที่เคยศึกษาเรื่องนี้ อยากรบกวนให้ช่วยแนวทางให้ด้วยครับ เพราะค่า ที่ดึงจาก BMS จะนำไปต่อใน python และเปลี่ยนเป็น file json และส่งขึ้นไปใช้งานในงานถนัดๆ ไปซึ่ง งานช่วงหลังเตรียมไว้หมด แล้ว เหลือเพียงแค่ดึงค่า จาก BMS ครับ
arduino leonardo
battery https://github.com/KomaCrazy/page-/blob/main/ENG2021002_%20InSight%20CANbus%20Specification.pdf
เป็นไฟล์เอกสารครับ ซึ่งลองพยายามแล้วแต่ไม่สำเร็จผล
อันนี้เป้นไฟล์ Aduino ครับ ตรงไฟล์ message ซึ่งลองแล้วก็ไม่ตอบสนองเลย
byte incomingBytes[8]; // array for 8 bytes incoming serial data
byte message[] = {0x01,0x05,0x09,0x81,0x01,0x00,0x00}; //message to BMS to ask for battery SOC
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);
if (Serial1.available()) {
Serial1.readBytes(incomingBytes, 8);
}
for (int i=0; i<8; i++){ // print the received bytes
Serial.print(incomingBytes, HEX);
Serial.print(" ");
}
Serial.println();
Serial.println(" ");
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
Serial.print("Data value in HEX = ");
Serial.println(combined, HEX); // print the 4 combined HEX bytes in HEX
Serial.println("");
Serial.print("Data value in DEC = ");
Serial.println(combined, DEC); // print them in decimal
Serial.println("");
Serial.print("Battery SOC = ");
float batterySOC = (float)combined/1000000.0; //dividing the dec values by 1000000 to get the values of SOC in BMS register
Serial.print(batterySOC); // print the SOC value
Serial.println(" %");
Serial.println("");
while (millis() < time_now + period){
// delay of 10 minutes
}
}