Inputting and Reading Commander Commands

Hello All,

Apologizes if this is an obvious question, however for the life of me I can’t not figure it out (I am still fairly new to SimpleFOC and programming): How do you input or read a commander command to the motor driver while its running?

For example if I define M as a commander command to move the motor to a position, ahead of time, and then I want to tell the driver to run “M5” (or any other number of radians I want it to move while its running) how do I accomplish this through code? I want to eventually run a script that can read and send lots of commander commands autonomously, rather than doing it through the keyboard.

Thanks in Advance,


Hi Logan,

You can talk to the Commander via Serial, so depending on where your script is running, and what scripting technology you plan to use, you would solve this in different ways.
But in essence it would be a matter of opening the serial port in your script, and sending the commands as ASCII text, separated by newlines.

If you want to control from another Arduino board, then I2C might also be an option, check out the I2CCommander in our drivers repository.

@runger thank you for your reply. I would like to use I2C Commander because I would like to control many motors. Reviewing the I2C Commander information I now realize that my goal is a more complex one than I had anticipated.

Taking a quote for the read me of I2C Commander ReadMe:

As would be expected for I2C, each target device needs a unique I2C address on its bus, and setting up and discovering these addresses is out-of-scope for I2CCommander. Setting up and configuring the TwoWire objects (which pins, speed, etc…) is also out of scope and finished, initialized TwoWire objects must be passed to I2CCommander. If you don’t specify a different reference, the standard Wire object is assumed.

Communication with the motor drivers happens via a register paradigm. The driver board offers many registers, some of which can be read, some can be written, and some are read/write. The controller MCU sends I2C messages to the target device to read or write a register as desired. The size of the data to be read/written depends on the register, and must be known by the controller. See Registers, below, for more details on the individual registers.

The following is beyond my current skill level:

  • Creating a unique I2C address
  • Setting up and discovering these addresses
  • Setting up and configuring the TwoWire objects (which pins, speed, etc…)
  • Passing Initialized TwoWire objects to the I2CCommander
  • Getting the controller to know size of the data to be read/written depending on the register

And my original goal:

  • Sending commander commands to the controller in one serial port (while everything is running) and then the controller outputting the commander commands to the I2C bus to target drivers (and also doing that in reverse when reading values).

Obviously there is a lot I don’t know. I would greatly appreciate if someone could point me to learning resources to resolve my lack of understanding on the above six bulleted items.



Buy three Arduino Nano from Amazon:

Connect them:


1 Like

Thank you @Valentine those are very helpful resources.

I’m going spend some time experimenting. Additional resources are welcome. Especially @runger if you see anything that might not be covered in Valentine’s links that I should know that would be very much appreciated.



Hi Logan,

I think you’re in for a longer journey, but if you are motivated and have a bit of patience, I am sure you will get to your goal. Its not a “first timer” kind of excecise, but its also not rocket science, so I am sure you can make it if you want to.

I think Valentine’s suggestions are very good. You need to get familiar with the basics of I2C, Arduino and working with the Arduino IDE, and following these kinds of tutorials is a good way to do it.

As you do so, you can keep your ultimate goal in mind, and see if you can adapt the examples a little bit, in small ways, to bring yourself closer to the goal.

When working with I2C, a logic analyser is a very useful tool. If you don’t already have one, then something like this: is sufficient for I2C, together with the free software “PulseView”, that’s a cheap I2C debugging solution.

You will also need to decide on cables, here I would recommend the Stemma/QT aka Qwiic standard - it is I2C over 4 wire cables with JST-SH-1.0 connectors. If you follow this convention you will find cheap pre-made cables - single plug, double plug (buy the ‘reverse side’ kind), and also helpful ready-made boards like this or this.

Also Sparkfun and Adafruit make various Arduino-compatible MCU boards like the “Thing Plus” or “Feather” boards, many of which come with Qwiic I2C connectors already on-board.
Anything you can do to simplify your life regarding cables, soldering, pin-choices etc will eliminate sources of error, and make things much easier for you.

So you could imagine ordering a few Thing-Plus boards with on-board I2C connector, the Qwiic Multi-Port adapter, and then connecting everything up with some ready-made cables. Then you could immediately start testing I2C communications.

When testing, you might want to consider ordering a USB hub and some extra USB cables. Then you can connect all the MCU boards to the same computer at the same time, and watch the Serial output for all the MCUs at the same time. This will make it much easier to debug, since each MCU can print the data it sends and receives to its own serial port, and you can compare the debug messages to see what is going on.

These are just some top level ideas… give it a go, and let us know how you’re doing with it!

1 Like

Hello runger,

Thank you for all this advice! I will look into these resources/ideas and starting experimenting and report back later.