arduino-CAN icon indicating copy to clipboard operation
arduino-CAN copied to clipboard

General Question: convert raw data to a can message

Open ashwinsarvesh opened this issue 5 years ago • 1 comments

Hello,

I want to convert raw data into CAN messages of the type can_msgs/Frame These are the data of a moving car in a driving simulator(for eg. speed of the car), so they keep changing instantaneously. Can I do this conversion in real-time?

ashwinsarvesh avatar Aug 02 '20 09:08 ashwinsarvesh

Hi, I had the same problem when I started with the Can bus.

The solution is easy- use this : https://github.com/deltaphi/arduino-CAN

This Pull request gives you access to the Raw Can Data.

for example (to use inside the on revice callback):

//GLOBAL
uint8_t CanB[8]; // Name of the array and size




    CAN.readBytes(CanB, 8); //Access to the raw buffer


    if (CAN.packetId() == 0x100)  // ID

    {
//DATA
 Serial.println(CanB[0]);
 Serial.println(CanB[1]);
 Serial.println(CanB[2]);
 Serial.println(CanB[3]);
 Serial.println(CanB[4]);
 Serial.println(CanB[5]);
 Serial.println(CanB[6]);
 Serial.println(CanB[7]);


    }


this gives you all 8 bytes of data.

Petros144 avatar Aug 03 '20 17:08 Petros144