I picked up an Arduino Uno and the Sparkfun CANBus shield to do some tinkering, however, while I've gotten it working and outputting data, and I've gotten it mostly where I want it, there's one bit that I haven't been able to figure out. I used the info here to get it going, and initially, it spit out data like this: 'ID: 1BC, Data: 0 0 0 0 0 0 0 '. I don't need the 'ID' or 'Data' added, just want the raw output, so I got it to where it now outputs like this: 'F9 0 23 40 0 0 0 0 FF'. That's where what I can't figure out resides. It's dropping leading zeros, which I don't want it to do. That last string should actually be '0F9 00 23 40 00 00 00 00 FF'. How would I go about getting it to spit out the raw CAN messages, without dropping zeros and whatnot? For reference, below is the exact code that's running in it as of now (yes, I set the serial baud rate really high so as to not have that be a bottleneck to the 500kbps CAN traffic...).
While I'm at it, there is one other thing I haven't figured out... I can filter by ID using 'if(message.id == 0x100)' for example, but that is exact, so only ID 100 would be displayed - how would I go about masking? So if I want to see every ID that is '1**' or '1', etc?
#include <Canbus.h> // don't forget to include these
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
void setup()
{
Serial.begin(921600);
//Initialise MCP2515 CAN controller at the specified speed
if(Canbus.init(CANSPEED_500))
Serial.println("CAN Init ok");
else
Serial.println("Can't Init CAN");
delay(1000);
}
void loop()
{
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
//{
//if(message.id == 0x100) //filtering based on CAN bus message ID.
{
//Serial.print("ID: ");
Serial.print(message.id,HEX);
Serial.print(" ");
//Serial.print("Data: ");
for(int i=0;i<message.header.length;i++)
{
Serial.print(message.data[i],HEX);
Serial.print(" ");
}
Serial.println(" ");
}}//}
}