CAN shield data bytes only one digit in some instances

Hello,

i recently got a seeed studio can bus shield (v1.2) and put together this code based on info in this instructable and the help in the attached comments and some searching around for info on filtering and hex output rather than decimal output.

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

INT32U canId = 0x000;

unsigned char len = 0;
unsigned char buf[8];
char str[20];

const int SPI_CS_PIN = 9; // select your can shield cs pin
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin

void setup() 
{
Serial.begin(115200);
START_INIT:
if(CAN_OK == CAN.begin(CAN_500KBPS))
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;  

}
}

void loop(){
   if(CAN_MSGAVAIL == CAN.checkReceive())
    {
        CAN.readMsgBuf(&len, buf);
        canId = CAN.getCanId();
    }
    //below is the code that i added to ignore all of the cars regular functions that are streaming like mad over the can bus.... this is just the OBD2 can ID's. 
   if(canId==0x7DF || canId==0x7E0 || canId==0x7E1 || canId==0x7E2 || canId==0x7E3 || canId==0x7E4 || canId==0x7E5 || canId==0x7E6 || canId==0x7E7 || canId==0x7E8 || canId==0x7E9 || canId==0x7EA || canId==0x7EB || canId==0x7EC || canId==0x7ED || canId==0x7EE || canId==0x7EF)    
     {   
        Serial.print(canId, HEX);Serial.print(",");//the commas that are printed are so the log file is already in csv format for easy sorting and manipulating
        for(int i = 0; i<len; i++)
  {
    Serial.print(buf[i], HEX);Serial.print(",");//i added "HEX" cause i wanted what was actually coming across the bus. 
  }
  Serial.println();
   }

}

the only issue that i have is that when it spits out a can bus value that can be described in one digit, it does just that. like “0” vs “00” or “D” instead of “0D”.

on my android can reader setup (bluetooth elm327 and a can terminal app) when you ask for data for a certain canID and command, it spits back the byte values displayed “properly” with 2 decimal places.

does anyone know how i can fix this?

thanks

Brian

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2016.10.31 15:11:00 =~=~=~=~=~=~=~=~=~=~=~= CAN BUS Shield init ok! 7DF,2,1,D,0,0,0,0,0, 7E8,3,41,D,0,0,0,0,0, 7DF,2,1,C,0,0,0,0,0, 7E8,4,41,C,B,E6,0,0,0, 7E8,4,41,C,B,E6,0,0,0, 7DF,2,1,2F,0,0,0,0,0, 7DF,2,1,2F,0,0,0,0,0, 7E8,3,41,2F,61,0,0,0,0, 7DF,2,1,D,0,0,0,0,0, 7DF,2,1,D,0,0,0,0,0, 7E8,3,41,D,0,0,0,0,0, 7DF,2,1,2F,0,0,0,0,0, 7DF,2,1,2F,0,0,0,0,0, 7E8,3,41,2F,61,0,0,0,0, 7E0,3,22,1E,1C,0,0,0,0, 7E8,5,62,1E,1C,4,8C,0,0,

the data looks like this. the single character reply may be just fine but im not sure.

(deleted)

thanks, ill try it. :)

Brian