Advertisement
pleasedontcode

CAN message sender

Jul 27th, 2024
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.51 KB | Source Code | 0 0
  1. #include <mcp_can.h>
  2. #include <SPI.h>
  3.  
  4. const int SPI_CS_PIN = 10;
  5. MCP_CAN CAN(SPI_CS_PIN);
  6.  
  7. void setup() {
  8.   Serial.begin(115200);
  9.   while (CAN_OK != CAN.begin(CAN_500KBPS)) {
  10.     Serial.println("CAN BUS Shield init fail");
  11.     delay(100);
  12.   }
  13.   Serial.println("CAN BUS Shield init ok!");
  14. }
  15.  
  16. void loop() {
  17.   unsigned char message[8] = {'H', 'e', 'l', 'l', 'o', ' ', '!', ' '};
  18.   CAN.sendMsgBuf(0x00, 0, 8, message);
  19.   Serial.println("Message sent: Hello !");
  20.   delay(1000); // Send message every second
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement