Ask Your Question

rosserial with Teensy 3.1 comm port

asked 2015-09-21 17:57:51 -0500

bsculley gravatar image

updated 2015-09-22 17:00:16 -0500

The current rosserial package (Jade) includes an Arduino library (ros_lib) that has been updated to recognize Teensy 3.1. It appears that when Teensy 3.1 is recognized, the serial port is automatically set to USB. I don't want to use USB, I want to use a UART to communicate with the ROS master (Beaglebone Black).

Am I missing something? Is there a configuration parameter or function call that will let me set the desired serial port on the Teensy? Or, failing that, some safe way to hack it?

If anyone has been successful (or not) setting up rosserial communication between Beaglebone Black (Ubuntu 14.04) and Teensy 3.1 I would like any information you can provide.

Below is some code from ArduinoHardware.h. If I don't want USB communications, which of the alternatives will work best for Teensy 3.1?

#if ARDUINO>=100
  #include <Arduino.h>  // Arduino 1.0
  #include <WProgram.h>  // Arduino 0022

#if defined(__MK20DX128__) || defined(__MK20DX256__)
  #include <usb_serial.h>  // Teensy 3.0 and 3.1
  #define SERIAL_CLASS usb_serial_class
#elif defined(_SAM3XA_)
  #include <UARTClass.h>  // Arduino Due
  #define SERIAL_CLASS UARTClass
#elif defined(USE_USBCON)
  // Arduino Leonardo USB Serial Port
  #define SERIAL_CLASS Serial_
  #include <HardwareSerial.h>  // Arduino AVR
  #define SERIAL_CLASS HardwareSerial
edit retag flag offensive close merge delete


Did you see this answer? I've got this to work for changing the serial port of the Mega, haven't tried with the Teensy yet.

Gary Servin gravatar image Gary Servin  ( 2015-09-22 22:09:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-23 00:33:59 -0500

I've created a PR to rosserial to add HW Serial ports support for Teensy.

For the moment, you need to manually add the changes:

1- Modify your ArduinoHardware.h to:

#if defined(__MK20DX128__) || defined(__MK20DX256__)
  #if defined(USE_TEENSY_HW_SERIAL)
    #define SERIAL_CLASS HardwareSerial // Teensy HW Serial
    #include <usb_serial.h>  // Teensy 3.0 and 3.1
    #define SERIAL_CLASS usb_serial_class
#elif defined(_SAM3XA_)


#if defined(USBCON) and !(defined(USE_USBCON))
      /* Leonardo support */
      iostream = &Serial1;
#elif defined(USE_TEENSY_HW_SERIAL)
      iostream = &Serial1;
      iostream = &Serial;

2- On your arduino sketch use the following at the beginning:


#include <ros.h>

class NewHardware : public ArduinoHardware
  NewHardware():ArduinoHardware(&Serial1, 57600){}; // Specify which port you want to use

ros::NodeHandle_<NewHardware> nh;

Hope this helps you!

edit flag offensive delete link more


Just the ticket. Thanks!

bsculley gravatar image bsculley  ( 2015-09-23 11:33:41 -0500 )edit

Adding the #define USE_TEENSY_HW_SERIAL was what solved my problem with the Teensy 3.6, Arduino 1.8.5 and ROS Kinetic.

flurin4 gravatar image flurin4  ( 2017-11-07 07:57:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-09-21 17:57:51 -0500

Seen: 2,277 times

Last updated: Sep 23 '15