I need to get another serial port working in addition to Serial. I have been working with a Teensy, which has three serial ports. I just address them as Serial1, Serial2 and Serial3.
I soldered wired onto the castellated contacts for TX2 and RX2 and added the Teensy code to my Blues project. The code won’t build. I get an error “Undefined reference to `Serial2’.”
Are the pins labelled Serial 2 (or Serial0 or Serial3) usable in the PlatformIO/Arduino environment? If so, how do I use them?
Thanks in advance,
After some reading and lots of tries I added the following line to my code:
HardwareSerial Serial2(PD_6, PA_2);
Assuming that PD_6 corresponds to RX2 and PA_2 corresponds to PA_2.
I tried lots of variations on this. The code now builds, but the no communication is happening on the RX2 and TX2 pins.
I’m assuming you’re using a Swan, since you mentioned the castellated contacts (we do have a Swan Carrier in the store, that can make it easier to make connections to the castellated pins without soldering.
To use an alternative serial port you can add this to your app:
HardwareSerial Serial2(A5, A4);
This is particularly useful if you want to use our Notecard Outboard Firmware Updates feature with a Feather. The ODFU runs over
Serial2 is used for serial communication in the sketch.
If you want to use
RX2/TX2, then this is the declaration
HardwareSerial Serial2(PB6, PA2_ALT);
Don’t forget to call
Serial2.begin() before using it
Thank you. The A5, A4 did the trick,
I am moving code over from a Teensy, which has ports that just work. I wish this stuff was in the documentation. I have wasted hours.
Can you suggest suitable pins for Serial3? I am getting sick of the usbSerial failing every time I load new code.
I’m sorry to hear this has cost you some time. We do have documentation for this in the pipeline.
A5/A4 uses the
USART3 peripheral so we could have named it
Serial3 in the example above, for clarity and consistency.
I’ve not personally tried this one, according to my notes, the
LPUART1 peripheral is available on pins A0 and A3.
I hope this helps!
Thank you. I will give that a go. Another port would be nice.
That worked. I can now get on with getting outboard DFU working.
For future reference, these lines make Serial2 and Serial3 available:
Glad to hear you’re able to move forward. Thanks for confirming that serial on A0/A3 works.