Hi. I have a BMS controller sending out canbus data.
I want to read the data (already done)
Translate to readable data SOC 0-100%, Current, Voltage, temp and so on.
This is the canbus data I get on serial monitor: (With the demo code from seeed-studio)
Get data from ID: 150
0 0 F7 6 B6 4 17 14
Get data from ID: 650
79 31 32 64 B2 0 63 14
Get data from ID: 651
78 E 8C E 25 0 60 60
Get data from ID: 652
7D 0 F4 1 25 0 60 60
Current is ID150 byte 0/1 LSB/MSB. No scaling (0x00 actual 0Amp)
Voltage is ID150 byte 2/3 LSB/MSB. *10 (0x06F7 actual 178.3Volt)
And so on. (have to do some more digging to find the other values/scaling/formula)
This is the data I get with adding this code: Seeed CAN Shield & Uno R3 w/ Haltech ECU - Networking, Protocols, and Devices - Arduino Forum
Get data from ID: 652
7D 0 F4 1 25 0 60 60
Byte 0/1: 7D00
Get LSB/MSB.
So the data I want to see is on my LCD display is SOC in percent, voltage....
If anybody want to help with this, here on this tread or as a paid job, please send PM.
Here is the code I use: (Open to suggestions for other approach)
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13
// joey_20 Modified
#include <SPI.h>
#include "mcp_can.h"
#include <Wire.h> // include the I2C library
#include <FaBoLCD_PCF8574.h> // include the LCD library
FaBoLCD_PCF8574 lcd; // initialize the library
// the cs pin for Leonardo CAN BUS board is default to D17
const int SPI_CS_PIN = 17;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
lcd.begin(16, 2); // set up columns and rows
lcd.print("can_lcd_ver02"); // send version to the LCD.
while (CAN_OK != CAN.begin(CAN_250KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if (CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned int canId = CAN.getCanId();
if (canId == 0x652)
{
Serial.println("-----------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);
for (int i = 0; i < len; i++) // print the data
{
lcd.print(buf[i], HEX);
Serial.print(buf[i], HEX);
Serial.print("\t");
}
uint16_t reading = 0;
reading = (uint16_t)buf[0] << 8;
reading |= buf[1];
Serial.println();
Serial.println();
Serial.print("Byte 0/1: ");
Serial.println(reading, HEX);
}
}
}