Linker error after adding the RS485 library

I am a new user to Arduino but I found the PlatformIO IDE a lot better than the Arduino default. I hope I’m placingthis in the right place

From a working blinky program, I successfully added the RS485 library. (it took me a while but everything seems to be ok in that regard)

When I make a call to RS485.begin(9600) as stated in the RS485 Arduino example I get the following error message.

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_25'
avr8-stub.c.o (symbol from plugin):(.text+0x0): first defined here

Here is my simple code

#include <Arduino.h>
#include <Wire.h>
#include "avr8-stub.h"
#include "C:\\Users\\Rick\Documents\\PlatformIO\\Projects\\Blinky\\lib\\RS485\\src\\ArduinoRS485.h"

int iter;
int incomingByte = 0; // for incoming serial data

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
  Serial3.begin(9600); // opens serial port, sets data rate to 9600 bps
  iter = 0;
 // ***************   Adding this line causes the error - The RS485 library appears to have been 
 // succesfully installed  ****************************************

void loop() {
  // put your main code here, to run repeatedly:

Any suggestions are welcome. Thanks

This is the wrong way. Only add

#include <ArduinoRS485.h>

The intellisense error will go away after doing a Ctrl+Shift+P → Rebuild Intellisense.

And well, as you can read in

the RS485 library will, if RS485_SERIAL_PORT is not externally defined, try to use SERIAL_PORT_HARDWARE as its serial port, which as you can see in

is Serial.

As you can read in the documentation

and in the code

The AVR-stub code also by default tries to use the Serial object to host the GDB server.

And thus, you have a serial port conflict.

If you wanted to use Serial3 for the RS485 port / transceiver module, add

build_flags = -DRS485_SERIAL_PORT=Serial3

to the platformio.ini (docs).

If it was intentional to use the RS485 library with the default Serial port, you must connect an additional USB-UART adapter to a free serial port and set AVR8_UART_NUMBER accordingly to host the AVR stub server on that serial interface, e.g.

build_flags = -DAVR8_UART_NUMBER=3

Just a fantastic explanation of what my problem was. Still I must go over the explanation again to get a better understanding of what’s going on. (and changing the #include t your suggestion worked. )

I think my main problem was trying to use the Serial port for RS485 since this can only be used with the debugger. I have the debugger running and I am able to breakpoint and watch vars.
Next I decided to just figure out how to add a library and run a function from it successfully. I chose the RS485 library because my first task once the hardware is ready (next week) is to communicate with a Meerstetter temperature control through RS485. Perhaps it would be better to write my own routines. I just don’t know. I do not like the Arduino abstraction layer but I have no choice right now.

Again, thank you Max for the quick and excellent response.

The RS485 library is probably just fine, you just have to configure your serial ports correctly, so that you have one serial port dedicated to one function: E.g., AVR-Stub debugging on Serial, RS485 on Serial3, other printf() style output / debugging on Serial2, et cetera, then it can work just fine. You have 4 Serial objects available on your Mega :slight_smile:

Hi Max, For me I’ll be configuring the RS485 port using Serial1 (19,18) but actually I think I can treat the serial port as if it was a RS232 since I won’t need the dePin or the rePin according to the EE who is configuring the HW. I just need to write a buffer of bytes and read a response. (the other serial ports will be used later for other devices)

I haven’t worked in years on this stuff and I am more familiar (from my past life) with actually writing to the ports and setting up the clocks, registers etc. directly. The Arduino code kind of abstracts that lower layer from me so I appreciate very much you suggestions and advice.

I noticed that Serial1 inherits from SERIAL_PORT_HARDWARE . Would it be more beneficial to change this to RS485_SERIAL_PORT.

I will be looking into the many code examples for help as well.

Thank You for your expertise