Multi Axis Control

Hello Everyone!

I am trying to control multiple motors (5 motors but more possible) via a single main board (ideally a raspberrry pi or anything else that I can easily communicate to wirelessly from my application through wifi).

I was initially thinking of running a rs485 or canbus from a rpi to multiple arduinos, which would then control each motor, and each arduino would get position feedback via i2c. The problem with this is that I will have to use can/rs485 shields for each arduino. To reduce the cost and complexity, I’d like to avoid shields. My other concern is that I would like to dynamically reprogram certain variables in each arduino such as the PID variables based on estimated motor loads. I’m asking for a lot I know but is there a good way to 1. use no shields and 2. reprogram motor control boards on the fly? I am open to using any kind of board for each motor and for the main control board as long as the motor control boards meet conditions 1 and 2. For the main control board, I am also open to using anything as long as I can use it to dynamically reprogram variables in the motor boards with it. Is this achievable?

Thanks in advance!

  • S

Hello @slayerizer

Assuming a master/slave star configuration and not receiving telemetry back from the slaves.

The fastest and dirtiest way would be, if the frequency of updates is not very high:

  1. I2C master/slave, up to 127 slave devices.

  2. SPI master/slave, up to whatever number of slave control pins you have on your arduino. You may be able to do 5. RPi has quite a few available IO pins, so it may be a better choice.

Yes, you can listen to the I2C or SPI on each slave device, and set up the PID variables, speed, angle, whatever, on the fly inside the main loop for that motor.

It will take some learning curve to write the code but it’s really achievable.

The only restriction is that the wires must be relatively short, like, 50cm each. Also you need to use high quality twisted and shielded cables for the comms. Anything longer that 50cm you will need CANBus. You may be able to use a little bit longer wires but you need to experiment with the clock speeds. Lower clock speed == longer distance.

Welcome to the forum. Please post pictures/videos of your setup for us to learn from you.

Cheers,
Valentine

Hi Valentine!

Thank you for the response. Please see a pic of what I am trying to prototype. It is very early stages as you can see. All I have is an arduino connected to a position sensor and my attempt at making a strain wave drive. Still waiting for my BLDC motor and driver to arrive in the mail. As I was reading your response, I realized the following:

  1. My application will definitely be above 50cm. Guess that rules out i2c
  2. I do want to communicate position signals back to main board from motor boards. This will allow to know if motor has failed to reach desired position at a given time. This would be critical. Does that mean I really need a canbus?

I would like to avoid shields but if not actually possible with an arduino, then I guess that’s that. If this is the case as the next step in my project, I am open to making my own PCB to integrate canbus, arduino/MC, and maybe motor position sensor. I was also thinking that if using RPI to arduino, I’d have to use logic level converters as per 3.3v vs arduino’s 5v. Is it possible to avoid shields if I use Rpis for the motors too? (is it possible to control the motors with an rpi?)

Also was trying to research but was unable to figure this: for i2c, a master controls a slave, but can a slave be a master to its own slaves too? From your response it seems that way, but just confirming.

Thanks again,
s

Not really. As I mentioned, if you have low data rate, and lower the clock speed you can get long cables. Generally, 100cm (1 meter) I2C limits you to 100 kbps (10kbytes/s) and 10 meters cable limits you to 10kbps (1kbyte/s). If you are looking for motor control, and have 5 slaves, at 1 meter and 10 kbytes/s when you do timesharing of the data you cannot get anything better than 2kbytes/sec which is rather low. If that’s OK for your use case, you can get 1m cable. 10 meters I guess would not work in your case.

You can bi-directionally communicate with I2C, no problem, but then you need to lower the speed. Each roundtrip of data halves the data exchange rate. Now you see why CANBus (or any other differential protocol) is superior to I2C or SPI protocol in this case. CANBus achieves 1Mbps (100 kbyte/s) in a decentralized architecture out of the box.

I designed a very tiny and cheap CANBus module which uses SPI protocol and is very cheap, check this out, it may be the answer to your question.

No. I2C doesn’t work that way.

Only the oldest Arduinos use 5v, the newer ones use 3v, but yes, you need a logic level converter, or a just a simple voltage divider, depending on your architecture.

Also check this out

Nice 3d printing, please post some videos of the entire setup, hopefully you will make it work.

Cheers,
Valentine

Hey, @slayerizer ,

Regarding different protocols:

  • I2C will be simpler and cheaper, for small scale applications you can probably make it work up to a few m distance using buffers and I2C signal conditioners.
  • For applications requiring feedback, there are 2 approaches you can follow with normal I2C: poll at a regular interval, or use interrupts
  • polling can be achieved easily - your central controller simply talks to each bus target device in turn. Depending on the bus speed and number of devices involved, you can achieve a total polling frequency of several 100s of Hz.
  • interrupts require another signal line. There are even standardised ways to do it like SMBus Alerts, but basically a target device will pull down (open-drain) the interrupt line and the controller will detect this and poll the target devices to find out who wants attention.
  • you can use multiple I2C buses and communicate with targets on each bus in parallel to speed comms.

CAN-bus gets around these limitations by providing bi-directional communications, but there is no protocol level support really for SimpleFOC, so you’ll have to roll your own. There are a couple of forum threads with pointers, by people who have done so before.

@Valentine @runger Really appreciate both of your help. Based on what you both are mentioning, I would like to use the can bus for bi-directional communication. I am planning on creating a custom board that will meld a BLDC driver, canbus and micro into one package. Will update this thread once I get it off the ground so others can learn.

Thanks,
S

1 Like

Thanks and looking forward to seeing the board.

Cheers,
Valentine