← Back to Docs

Firmware flashing and teleoperation

Build and flash the Teensy firmware, monitor the serial output, start the micro‑ROS agent, and control the robot via keyboard.
1

Compile and flash the Teensy firmware

Build and upload the microcontroller firmware for closed‑loop control.

The closed‑loop motor controller firmware for the robot runs on a Teensy 4.0 microcontroller. Follow these steps to compile and upload the firmware using arduino-cli and teensy_loader_cli.

bash
cd ~/repos/common_platform/firmware/closed_loop
rm -rf build
mkdir build
bash
arduino-cli compile --fqbn teensy:avr:teensy40 --build-property build.usbtype=USB_DUAL_SERIAL --build-path . ../closed_loop.ino
bash
SERIAL_TEENSY_DEVICE=$(find /dev/serial/by-id/ -name "usb-Teensyduino*if00" | head -1)
echo $SERIAL_TEENSY_DEVICE
bash
sudo stty -F $SERIAL_TEENSY_DEVICE 9600
sudo stty -F $SERIAL_TEENSY_DEVICE 134
bash
lsusb | grep Teensy
bash
sudo teensy_loader_cli -v --mcu=TEENSY40 closed_loop.ino.hex
2

Monitor Teensy debug output

Connect to the Teensy serial port to view debug information.

The firmware prints diagnostic messages over USB serial. Use Python’s serial tools to open the port and inspect output.

bash
SERIAL_NUM=$(ls /dev/serial/by-id/ | grep -i teensy | head -n1)
SERIAL_DEV=/dev/serial/by-id/${SERIAL_NUM}
echo $SERIAL_DEV
bash
python3 -m serial.tools.miniterm $SERIAL_DEV 115200
3

Start the micro‑ROS agent

Run the micro‑ROS serial agent in a Docker container to bridge the Teensy with ROS 2.

The Teensy communicates with ROS 2 via a micro‑ROS agent, which runs in a Docker container. Launch the agent on your development computer, mounting /dev for serial access, loading environment variables (including ROS_NAMESPACE), using the data channel interface (if00), and enabling verbose logging.

bash
SERIAL_NUM=$(find /dev/serial/by-id/ -name "usb-Teensyduino*if00" | head -1 | sed 's/.*_Dual_Serial_\(.*\)-if00/\1/')
SERIAL_DEV="/dev/serial/by-id/usb-Teensyduino_Dual_Serial_${SERIAL_NUM}-if00"
echo "Using device: $SERIAL_DEV"
bash
sudo docker run -it --rm \
  -v /dev:/dev --privileged --net=host \
  --env-file ~/env.list \
  --name agent microros/micro-ros-agent:kilted \
  serial --dev $SERIAL_DEV -v4
4

Launch keyboard teleoperation node

Use your keyboard to manually control the robot via evdev_teleop.

Use keyboard controls to manually drive your robot. Before launching keyboard teleoperation, ensure the following prerequisites are met:

Prerequisites:

  • Fast DDS discovery server is running
  • Robot is powered on and Teensy is flashed with the latest firmware
  • Network connectivity is established between host and robot
  • micro‑ROS agent is running and connected to the Teensy

Optional: Monitor Teensy debug output:
Open a separate terminal to view firmware debug messages from the Teensy:

SERIAL_NUM=$(find /dev/serial/by-id/ -name "usb-Teensyduino*if01" | head -1 | sed 's/.*_Dual_Serial_\(.*\)-if01/\1/')
python3 -m serial.tools.miniterm /dev/serial/by-id/usb-Teensyduino_Dual_Serial_${SERIAL_NUM}-if01 115200

Note: Use if01 for debug output, not if00 (which is used by the micro‑ROS agent). Press Ctrl+] then q to exit miniterm.

bash
cd ~/repos/common_platform/common_platform_ws
source install/setup.bash
ros2 launch evdev_teleop evdev_teleop.launch.py

Subscribe to our newsletter

The latest educational robotics news and articles, sent to your inbox weekly.