Arduino Portenta CAN Library

Hi all, you can find a libary for Arduino Portenta Machine control. It works.
I didnt try it on the Portenta Breakout, but it should work also for it (!! there is no Tranceiver on Breakout !!).

*/
#include <Arduino_MachineControl.h>
#include <CAN.h>
using namespace machinecontrol;

#define DATARATE_250KB 250000

void setup() {
Serial.begin(115200);

Serial.println("Start CAN initialization");
comm_protocols.enableCAN();
comm_protocols.can.frequency(DATARATE_250KB);
Serial.println("Initialization done");
}

int counter = 0;
unsigned char data[8];
int data_size = 8;

void loop() {

data[0] = 0x49;
data[1] = 0x32;
data[2] = 0x31;
data[3] = 0x30;
data[4] = 0x29;
data[5] = 0x28;
data[6] = 0x27;
data[7] = 0x26;

mbed::CANMessage msg = mbed::CANMessage(13ul, &data[0], data_size);
if (comm_protocols.can.write(msg)) {
Serial.println("Message sent");
} else {
Serial.println("Transmission Error: ");
Serial.println(comm_protocols.can.tderror());
comm_protocols.can.reset();
}

delay(100);
}

1 Like