How-to control Robotis Dynamixel via Pika Spark’s RS485 interface

Pika Spark is an Arduino Portenta X8 based micro robot control system combining an unprecedented amount of computing power and interfaces within an extremely small form factor. The Pika Spark has two (2) galvanically isolated RS485 interfaces which can be used for communication with external devices. Galvanic isolation prevents ground-loops and increases overall system resilience and is an important feature in industrial-grade control systems.

RS485 is a differential, multi-drop capable bus which makes it an ideal choice for connecting a wide range of computer and automation systems leading to RS485 becoming the bus of choice for industrial control systems. This tutorials explains how to use Pika Spark's RS485A interface, which is connected to the Yocto-Linux-running IMX8 application processor of the Arduino Portenta X8, for controlling and configuring multiple Robotis Dynamixel MX28AR servo motors.

Pika Spark controlling four (4) Robotis Dynamixel MX28AR via RS485

(Module in red housing is a RS485 Power Injector)

The preferred way of getting anything done on the Arduino Portenta X8 is by using Docker. So let's start by creating a Dockerfile that installs builds and installs libdynamixelplusplus as well as all library provided examples. libdynamixelplusplus is a MIT-licensed C++17 wrapper for the Robotis DynamixelSDK allowing servo motor configuration and control using advanced C++ language features.

FROM alpine:3.18

RUN apk add git g++ make cmake linux-headers && \
    cd /tmp && \
    git clone && \
    cd libdynamixelplusplus && \
    mkdir build && \
    cd build && \
    cmake -DBUILD_EXAMPLES=ON .. && \

ENV PATH='$PATH:/tmp/libdynamixelplusplus/build'

In the next step a Docker image is built from the Dockerfile using docker build.

docker build --pull --no-cache --tag pika_spark_rs485a_libdynamixelplusplus .

Next we need to grant read/write access to the RS485A interface for our newly created Docker container. This is simply done by granting +rw access for all users, groups and others ugo. Note: a better solution would be to add our own user to the group that owns the /dev/ttymxc1 interface.

sudo chmod ugo+rw /dev/ttymxc1

Example 1: Discover all connected servos

As a final step run (docker run) the newly created pika_spark_rs485a_libdynamixelplusplus container passing the RS485A tty interface via --device /dev/ttymxc1 and execute the ping example program passing the interface name and desired baud rate as parameters example-01-ping /dev/ttymxc1 57600. This example is broadcasting a ping command to all servos and subsequently collects and prints the IDs of all connected servos.

sudo -u fio docker run -it \
  --device /dev/ttymxc1 \
  pika_spark_rs485a_libdynamixelplusplus \
  example-01-ping /dev/ttymxc1 57600

Example 2: Read firmware version

This example program first determines the IDs of all connected servos and then reads and prints the firmware version number of every single servo to the shell.

sudo -u fio docker run -it \
  --device /dev/ttymxc1 \
  pika_spark_rs485a_libdynamixelplusplus \
  example-02-read /dev/ttymxc1 57600

Example 3: Periodically blink the status LED of all connected servos

This example program first determines the IDs of all connected servos and then simultaneously turns on and off the LEDs of all connected servos in a periodic pattern.

sudo -u fio docker run -it \
  --device /dev/ttymxc1 \
  pika_spark_rs485a_libdynamixelplusplus \
  example-05-write /dev/ttymxc1 57600

Example 4: Set random goal position and read current position

This example program first determines the IDs of all connected servos and then sets a randomly generated goal position for each servo. Finally the current servo position is read and printed to the shell.

sudo -u fio docker run -it \
  --device /dev/ttymxc1 \
  pika_spark_rs485a_libdynamixelplusplus \
  example-xx-minimal /dev/ttymxc1 57600


In order to simplify trying out those examples for controlling Robotis Dynamixel servos via Pika Spark's galvanically isolated RS485 interfaces ready-made bash scripts with integrated error handling and convenience features have been prepared.

git clone
cd pika-spark-containers/rs485a-libdynamixelplusplus
sudo ./

All the best controlling Robotis Dynamixel servos with your Pika Spark!