GM CanBus project

Hi Guys,

I'm starting out learning arduino and GM Can bus sniffing.

My project what i'm trying to achieve is to read the steering wheel next /previous track buttons
translate the result and send via bluetooth the next track.

I'm very close to achieving this but my coding is letting me down somewhat.

i can filter and read the Canbus results and i can send the next track information to my phone ok however when i code it is the downfall for me.
when i push any of the steering wheel controls with the current code below it will just skip to the next song even if it's volume up or down ( not what im looking for )
obviously this is my code but i'm lacking the knowledge to rectify this if someone can assist?
there are 4 bits from this header 0x100d0060 and it's the 3rd bit that the information changes on

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

#include <SoftwareSerial.h>
SoftwareSerial hc06(8, 9);

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128];  // Array to store serial string
 
#define CAN0_INT 7 // Set Interrupt to pin 2
MCP_CAN CAN0(17); // Set CS to pin 10
 
void setup()
{
  Serial.begin(115200);

  while (!Serial)
{
    // do nothing
} ;
Serial.println("I am in setup Loop, Initialising now");
 
  if(CAN0.begin(MCP_ANY, CAN_33K3BPS, MCP_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
 
  CAN0.setMode(MCP_NORMAL);    // Set operation mode to normal so the MCP2515 sends acks to received data.
 
  pinMode(CAN0_INT, INPUT);    // Configuring pin for /INT input


  //Initialize Serial Monitor
  Serial.begin(115200);
  Serial.println("Bluetooth Initialised:");
  //Initialize Bluetooth Serial Port
  hc06.begin(115200);
}


 
void loop()
{
  if(!digitalRead(CAN0_INT))  // If CAN0_INT pin is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf);   // Read data: len = data length, buf = data byte(s)
 
    // 0x100d0060 = Wheel Controls
    if ((rxId & 0x1FFFFFFF) == 0x100d0060)
    {
      sprintf(msgString, "0x%.8lX,%1d,", (rxId & 0x1FFFFFFF), len); //formats text so it prints nice in serial monitor
      Serial.print(msgString);
 
      if((rxId & 0x40000000) != 0x40000000) //if rxif contains steering wheel controls ID of 0x100d0060 with 4 bytes of data do below
      {
        for(byte i = 0; i < len; i++)
       {
         sprintf(msgString, " 0x%.2X", rxBuf[i]); //0x%.2X helps with hex bit data conversion
         Serial.print(msgString);
         Serial.print("\n");
         Serial.print("Printing RXBuffer 2\n");
         Serial.print(rxBuf[2]);
         }

          
    if ((rxBuf[2] & 0x01) == 0x01);
    {
     hc06.write("AT+FORWARD\r\n"); 
     Serial.print("Track Changed Forward\n");
     }
      }     else if ((rxBuf[2] & 0x1F) == 0x1F);
     {
     hc06.write("AT+BACKWARD\r\n"); 
     Serial.print("Track Changed Backward\n");
     }  
          
  }
  }
  }

here is the console outputs can2 hosted at ImgBB — ImgBB

If you want to change the behavior of the "steering wheel next /previous track buttons" then you need to intercept the data, not just monitor it.

Essentially you do a "man in the middle" attack redirecting the output from the buttons to your phone then putting a doctored message back onto the CAN bus.

This will require 2 CAN interfaces, one for the button side, the other for the music system.

Thanks Mikb - understand what your saying but thats not what i'm trying to achieve.

All i want to do is read the button press on the steering wheel the arduino sees the request, then in the script with it's own attached bluetooth module that my phone is connected too it sends the next track.

i can get this functioning to a point but i think i have some errors in my code to get it functioning that way properly as any steering wheel button i press goes to the next song.

Is it using 11 or 29 bit addressing?

How many rxIds are you expecting to see? Just one or more than one?

What bits in the 4 bytes correspond to the steering wheel next /previous track buttons?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.