Hello everyone,
I'm trying to use a Seeed CAN Shield and Arduino Uno to create an LCD gauge. I'm not having any issues connecting to the ECU, (Haltech Pro-Plugin), and using the examples provided with the libraries. I can see the CAN ID and buffer information in the serial screen just fine.
Using the provided sample code, (and switching to 1000Kbps):
#include <SPI.h>
#include "mcp_can.h"
const int SPI_CS_PIN = 9;
MCP_CAN CAN(SPI_CS_PIN);
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_1000KBPS)) // Haltech uses 1,000Kbps
{
Serial.println("CAN BUS Failure...");
delay(100);
}
Serial.println("CAN BUS is ready!");
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned char canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.print("CAN ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();
}
}
I receive clear and accurate CAN information from the ECU:
CAN ID: 68
3 AC 0 0 0 0 0 0
-----------------------------
CAN ID: 6F
0 0 0 0 0 0 0 0
-----------------------------
CAN ID: 75
0 0 0 0 0 0 0 0
-----------------------------
CAN ID: 60
5 8 1 7F 0 0 0 0
What I'm having trouble with, is pulling out pieces of the buffer to convert and display on the serial screen, or an LCD screen. ID 68 shows 8 bytes in the buffer, 0 & 1 being lambda(air-fuel ratio) information. The remaining bytes are not used, as those would be for additional wideband sensors. Bytes 0 & 1 combine to hexadecimal 3AC, or decimal 940. I should be able to convert these values further on my own, (940 x .001 = .940 lambda = 13.82 AFR).
I'm having a difficult time pulling these values out directly to display a simple AFR reading on an LCD screen, or the serial screen at least.
Does anyone have any recommendations?
I appreciate any and all help. I've been at this for a few days with no luck. I won't bother showing my botched attempts as there's quite a few, and they're embarrassing.
Thank you