I'm working with a CAN to serial module that I connected to my Arduino and I have a simple sketch that displays the CAN information on the Serial Monitor which looks like this:
What would I need to to if I wanted to do "something" whenever I receive the message:
0x0 0x2 0xD0 0xC4 0x0 0x0 0x0 0x5
From ID: 91
I've never done anything with character arrays before and I really don't know where to start.
Here is the sketch I'm working on:
#include <Serial_CAN_Module.h>
#include <SoftwareSerial.h>
Serial_CAN can;
#define CAN_RATE_125 13
#define can_tx 2 // tx of serial can module connect to D3
#define can_rx 3 // rx of serial can module connect to D2
int Message_Count = 1;
unsigned long id = 0;
unsigned char dta[8];
void setup()
{
Serial.begin(9600);
while(!Serial);
can.begin(can_tx, can_rx, 9600); // tx, rx
if(can.canRate(CAN_RATE_125))
{Serial.println("ArduiCAN started!"); }
else
{Serial.println("Set can rate fail"); }
}
void loop()
{
if(can.recv(&id, dta))
{
Serial.print("[");
Serial.print(Message_Count);
Serial.print("]");
Serial.print(" from: ");
Serial.print(id, HEX);
Serial.print("(ID)");
Serial.print('\t');
for(int i=0; i<8; i++)
{
Serial.print("0x");
Serial.print(dta[i], HEX);
Serial.print(" ");
}
Serial.println();
Message_Count++;
}
}
