frankjoshua / rosserial_arduino_lib

56 stars 46 forks source link

Add #define for Serial2 & Serial3 #13

Closed matthijsfh closed 3 years ago

matthijsfh commented 3 years ago

Feature request for ArduinoHardware.h

It would be very convenient for the arduino MEGA to have a define that will use either Serial2 or Serial3.

Mega has 4 serial ports and Port "Serial1" maps onto 2 inputs with interrupt capabilities. Serial2 & Serial3 do not "block" interrupt lines and are therefore better to use for serial communication.

Serial itself is locked to the USB - serial converter by the MEGA hardware and very usefull for debugging. Having ROS Serial communication on Serial2 or Serial3 would be great.

if defined(USBCON) and !(defined(USE_USBCON))

  /* Leonardo support */
  iostream = &Serial1;

elif defined(USE_TEENSY_HW_SERIAL) or defined(USE_STM32_HW_SERIAL)

  iostream = &Serial1;

else

  iostream = &Serial;

endif

  baud_ = 57600;
}

Thanks Matthijs

frankjoshua commented 3 years ago

Although I maintain this repo I don't work on any issues. This sounds like a good feature. If you want to make the changes please fork the repository and make a pull request. I'll merge it in.

danidask commented 3 years ago

A better way than defines is to be able to select the port you want to use, and this feature is already implemented in version 0.9.1, You can do something like this:

  nh.getHardware()->setPort(&Serial3);
  nh.getHardware()->setBaud(57600);
  nh.initNode();

Not very intuitive or well documented, but It does the job

frankjoshua commented 3 years ago

@danidask pointed out a good solution. Closing.