Help please to isolate incoming CAN messages

Hi Forum.
Please can anyone help with a CAN bus question.
I am receiving CAN bus messages (5 off) but would like to be able to select just one of those messages and use the data, can someone help show what I need to do please?
Thanks in advance. Peter

// CAN data reader //

#include <SPI.h>
#include "mcp_can.h"

const int SPI_CS_PIN = 10;

MCP_CAN CAN(SPI_CS_PIN);

void setup()
{ Serial.begin(9600);
while (CAN_OK != CAN.begin(CAN_250KBPS))
{ Serial.println("CAN comms fail");
delay(100);
}
Serial.println("CAN comms OK");
}

void loop()
{
unsigned char len = 0;
unsigned char buf[8];

if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf);

unsigned long canId = CAN.getCanId();

Serial.print("ID: 0x");
Serial.println(canId, DEC);

{
Serial.print(buf[0], DEC);
Serial.print("\t");
}
Serial.println();
}
}

Compare the value of canId with the one you are searching for.
If there is a match then do something with the data in the buf array.

What you precisely need to do depends on how the data is formatted. If you don't know, and it's from your car, then you need to seek out a car hacking forum that deals with your specific make, model and year of car.

Thanks mikb55. If possible could you expand on that idea with some programming please? When I check against the incoming CAN messages I get 0x4, 0x5, 0x6, 0x7, 0x8, the data appears as I expect but is given after each Id. In my case I wish to isolate the ID such as only reading 0x5 with its data. Thanks. Peter

To progress you will need to learn some basic programming skills. Perhaps head over to Programming Questions

Thanks mikb55. Sorted the issue...

if (canId == 4) // or whatever number I wish to read
Value4 = (buf[0])

All the best. Peter