2 Odrives 1 Arduino (Due)

I’m looking to control a total of 3 motors with 2 Odrives and 1 Arduino Due, my plan is to use 2 of the 3 hardware serial ports on the Due in order to communicate with the two ODrives. My question arises when figuring out how to talk to two individual ODrives through a single Arduino program. I’ve gone through the example ODrive Arduino sketch and attempted to modify it to work with 2 Odrives but I am stumped with it comes setting a position for the motor or velocity for the motor.

Establishing two odrives over two serial lines of communication:
ODriveArduino odrive(Serial1);
ODrive2Arduino odrive(Serial2);

Calibrate both odrive motors, go into closed loop control.
requested_state = ODriveArduino::AXIS_STATE_MOTOR_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

requested_state = ODriveArduino::AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

  requested_state = ODriveArduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(motornum, requested_state, false); // don't wait

requested_state = ODrive2Arduino::AXIS_STATE_MOTOR_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);
requested_state = ODrive2Arduino::AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
Serial << “Axis” << c << ": Requesting state " << requested_state << ‘\n’;
odrive.run_state(motornum, requested_state, true);

  requested_state = ODrive2Arduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
  Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
  odrive.run_state(motornum, requested_state, false); // don't wait

Giving commands:
odrive.SetPosition(1, pos_m1);??
odrive.SetVelocity(0, vel_m1);??

How do I differentiate between telling the first odrive vs. the second odrive?

Any insight would be greatly appreciated!

Upon further research it looks like James Bruton has figured it out

Yeah, Due has enough Serial ports to do it. Or you can try out the CAN interface :slight_smile:

@Matthew_Wiese @Wetmelon I need to do exactly the same. I’m unsure how you connected the ground for both your ODrives though?

The Arduino Mega board with 3 x RC/TC ports, but only 1 Gnd port:

Any advice?

There are two other ground ports on the arduino mega, on the opposite side where it says POWER. A few suggestions/things to point out:

  1. the arduino mega runs a 5V logic, so if you’re communicating through serial to the ODrive you’ll need a logic level converter to step that 5V logic down to the 3.3V logic that the ODrive runs on, that was one of the reasons I chose the Arduino Due since that is also 3.3V logic.

  2. If you’re looking to control multiple ODrives from the same arduino, be wary that some versions of the ODrive might induce ground loops and cause issues, this is outlined in the post below as well as potential solutions:

Newer versions of the ODrive board I believe already have an opto-isolator in place to prevent problems but I haven’t used ODrive in a while and am not sure what versions do and don’t have the opto-isolator.

Happy to help/answer any further questions, but it has been a couple years since I used the ODrive

Thanks a lot for responding even though you haven’t been using ODrives for a while @Matthew_Wiese and thanks for the advice!

From what I can see the new ODrives are 5V tolerant (ODrive Pinout — ODrive Pro Documentation 0.6.5 documentation). I’m trying my hands on the new ODrive S1.

Thanks for the link. Seems like people on that thread are really recommending CAN instead of running it over Arduino. I wonder if I should bite the bullet straight away and go directly to the CAN protocol?

I hadn’t noticed the two other GND pins. Is it just as fine to use them?

Would it also be possible to make a 3-1 jumper wire and connect them all to the same ground? Like in the image below and this link: FYI Making DuPont jumper wires. - General Electronics - Arduino Forum.

You’re welcome! Very cool, good to know that the new ODrives are 5V tolerant! I think I was using V3.6 at the time which was only 3.3V.

CAN is certainly a more robust and reliable protocol, I don’t have much experience with it. That’s up to you, it would be fairly easy to grab a CAN shield for your arduino mega and try it.

The ODrive S1 you have already has the opto-isolator installed so you should be good to go to communicate with multiple ODrives with the same arduino over UART/Serial without much problem.

In terms of the ground pins, yes those pins are the exact same electrical connection as the one you’re using, it all connects to the same ground plane. there are a total of 5 ground pins you could hook up to on the Mega, the other 2 are under pin 52 on the double header section. Most microcontrollers have multiple grounding points so you can connect multiple sensors to it without needing something like the 3-1 jumper wire that you linked to. That will also work, just requires another thing to make/buy.

Thanks a lot for clearing all that up for me. I’m a software guy trying out things in the hardware world, so I feel like I’ve thrown myself into the deep end of the pool. There’s a lot of new stuff to figure out :stuck_out_tongue:.

I think I’ll go ahead with UART and serial ports on the Arduino Mega and if it doesn’t work out I’ll have to switch over to CAN.

Thanks again!

No worries, happy to help! Good luck with your project!

-Matt