0
$\begingroup$

Rosanswers logo

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
#else
  #include <WProgram.h>  // Arduino 0022
#endif

#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_
#else 
  #include <HardwareSerial.h>  // Arduino AVR
  #define SERIAL_CLASS HardwareSerial
#endif

Originally posted by bsculley on ROS Answers with karma: 17 on 2015-09-21

Post score: 1


Original comments

Comment by Gary Servin on 2015-09-22:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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
  #else
    #include <usb_serial.h>  // Teensy 3.0 and 3.1
    #define SERIAL_CLASS usb_serial_class
  #endif
#elif defined(_SAM3XA_)

and

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

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

#define USE_TEENSY_HW_SERIAL

#include <ros.h>

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

ros::NodeHandle_<NewHardware> nh;

Hope this helps you!


Originally posted by Gary Servin with karma: 962 on 2015-09-23

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by bsculley on 2015-09-23:
Just the ticket. Thanks!

Comment by flurin4 on 2017-11-07:
Adding the #define USE_TEENSY_HW_SERIAL was what solved my problem with the Teensy 3.6, Arduino 1.8.5 and ROS Kinetic.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.