Uart Class


I am trying and failing :frowning: to covert a sketch into a libiary.

Using an Arduino Zero.

In sketch form:

Variable of type Uart is defined as follows:

Uart* serPort = &serial2;

There is a function that switches between &serial1 and &serial2.

This works.

Now i am trying to implement the same into the library:

Defined in the main code as follows:

Sender Sender(Serial2);

Here is the header file:

class Sender

Sender(Uart PortIn);


Uart* serPort;

Here is the .cpp file:

Sender::Sender(Uart PortIn)

byte data={0xff,0xaa};
serPort = &PortIn;



This complies but somthing must crash on startup as the USB port is lost. Resetbutton has to be presed to start the bootloader.

Please help....

I cannot seem to find what is wrong.


Define the Uart to be always a pointer:

Sender::Sender(Uart *PortIn)

   byte data[]={0xff,0xaa};
   serPort = PortIn;



Make copies of Uart objects isn't a good idea.

Don't forget to use code tags!