sandeepmistry / arduino-CAN

An Arduino library for sending and receiving data using CAN bus.
MIT License
682 stars 232 forks source link

General Question: convert raw data to a can message #48

Open ashwinsarvesh opened 4 years ago

ashwinsarvesh commented 4 years ago

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?

Petros144 commented 4 years ago

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.