Arduino CanOpen Control

Arduino and CanOpen Control

Comming Soon


Arduino code with CanOPen control for 3 motors.

Library is VESC GitHub for 1 motor, we share the modification for 3 motors soon.


#include <mcp_can.h>

#include "vesc_can_bus_arduino.h"

float vitesse;


CAN can;  // get torque sensor data, throttle for now


bool print_realtime_data;

long last_print_data;



void setup() {

  vitesse = 200;

  //pinMode(CAN0_INT, INPUT);

  Serial.begin(115200);  // Wired comms from USB port

  can.initialize();

}


void loop() {

  can.spin();

  vitesse = vitesse + 1;

  if (vitesse > 3000) { vitesse = 1; }

  print_realtime_data = true;

  delay(10);

  if (print_realtime_data == true) {

    if (millis() - last_print_data > 400) {

      can.vesc_set_current(2);  //2 amps of current

      can.vesc_set_erpm(1000, 10);

      // can.vesc_set_duty(0.2);


      delay(10);

      can.vesc_set_erpm(2000, 11);

      delay(10);




      can.vesc_set_erpm(vitesse, 12);

      delay(10);


      Serial.println(vitesse);

      Serial.print("Erpm:");

      Serial.print(can.erpm);

      Serial.print(" Volt:");

      Serial.print(can.inpVoltage[0]);

      Serial.print(" Volt:");

      Serial.print(can.inpVoltage[1]);

      Serial.print(" Volt:");

      Serial.print(can.inpVoltage[2]);

      Serial.print(" Duty:");

      Serial.println(can.dutyCycleNow);

      Serial.print("avgCurrent:");

      Serial.print(can.avgInputCurrent);

      Serial.print(" AvgMotor:");

      Serial.print(can.avgMotorCurrent);

      Serial.print(" temp:");

      Serial.print(can.tempFET);

      Serial.print(" tempM:");

      Serial.println(can.tempMotor);


      last_print_data = millis();

    }

  }

}