Create random byte data

Hello,
I want to build a CANBUS simulator , to be able to check some things.

but I didn't use Arduino in a while - and I forgot how to use ..... :frowning:

want to create a array of bytes (let say 6-7)
CAN_PID_LIST[] = { "184217D0", "184417D1", "184617D0", "0CFE6CEE", "18FEC1EE", "184317D0", "18FE117" };

and also make random value in the data any value of byte from (00-FF)

this is a "static" version of the code

canMsg.data[0] = 0xAA;               //Update humidity value in [0]

  canMsg.data[1] = 0x12;            

  canMsg.data[2] = 0x34;           

  canMsg.data[3] = 0x56;

  canMsg.data[4] = 0xCC;

  canMsg.data[5] = 0xDF;

  canMsg.data[6] = 0x99;

  canMsg.data[7] = 0x1C;

how do I do write it?
Create list and them pick 1 value from it , and random data bytes
for example it will create me something like this:
184217D0 : 123456CCDF991C
0CFE6CEE : FFAACCDDEEBBC1

Thanks,

Hi
Try to explain why you need it, because nothing is clear yet

I want to create a simulation for my testing device
so it will send me random canbus data

this gives you a random number:

canMsg.data[0] = random(256);  

?

you mean valid canbus messages with random data values for status or sensors?

yes (with a random PID of my own list)

i'm a big fan of developing code by simulating it off target on a laptop

so you need a sub-function to generate a specific canbus msg with random data values or specific values for specific cases. the code for both generating the msgs and deciding which msg to generate is part of the simulation code, not the target code

i usually read commands from a file for controlling external inputs and driving the simulation (e.g. invoking loop() 1 or more times). different cmd files can be used to simulate different scenarios

this is what I manage to do:

#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg2;
MCP2515 mcp2515(10);

void setup() {
canMsg2.can_id = 0x18FEC1EE;
canMsg2.can_dlc = 8;

  while (!Serial)
    ;
  Serial.begin(115200);

  mcp2515.reset();
  mcp2515.setBitrate(CAN_500KBPS);
  mcp2515.setNormalMode();

  Serial.println("Example: Write to CAN");
}

void loop() {

  canMsg2.data[0] = random(256);
  canMsg2.data[1] = random(256);
  canMsg2.data[2] = random(256);
  canMsg2.data[3] = random(256);
  canMsg2.data[4] = random(256);
  canMsg2.data[5] = random(256);
  canMsg2.data[6] = random(256);
  canMsg2.data[7] = random(256);
  
  mcp2515.sendMessage(&canMsg2);

  Serial.println("Messages sent");

  delay(200);
}

and it's working and sending random data

but when I read it I get this :

can0 1EE [8] A8 F2 91 FB 1E B4 E1 EE

when it won't send me the full PID I wrote ?
0x18FEC1EE
?

Thanks,

doesn't seem like a simulator, can you describe your setup? how are you receiving frames?

seems like your using the MCP2515 chip to interface with a cabbus and transmitting the frame your generating.

yes
this is what I want to do:
build a device with Arduino and MCP2515 that will send me random data (which I mange to do) from a known PID list ,
it is connected to a computer that read the canbus data and analyze it .
very easy setup .

but as I wrote - he is sending me just the last 3 chars of the PID
"1EE"
and not the all PID I have wrote
"0x18FEC1EE"

why is that ? and how I fix this ?

Thanks,