I am working on a project with a Nano Connect where I need to interface to a GPS unit serial is only interface available and to a radio transceiver which also requires a serial interface. Going in I assumed I could use the hardware serial port identified in the pinout and use a soft serial for the other required serial port.
The problem is it looks like there are no libraries available (or that I can find) for a software serial for the Nano RP2040 Connect board so I am a bit lost. The onboard IMU and microphone make this Nano an excellent fit for my application and I would like to keep the board.
Are there multiple hardware serial ports on the board, I have searched for at least an hour on this topic alone, or does a library exist for software serial ports on the Nano connect?
I appreciate any and all help that the community can provide.
In theory, the rp2040 has two hardware serial ports (in addition to the USBSerial used to talk to the PC.) But I think the 2nd Serial port is used to talk to the on-board WiFi module, and isn't available for other use.
(The Variant says there is a 3rd Serial port, but I don't see how to use it, and being layered on top of mBed makes it difficult to track down.) (likewise, I find it difficult to imagine layering a softwareSerial port over mBed )
I saw the second serial port on the RP2040 datasheet but did not see that it was used for the WIFI comms. I guess I will have to look for a different GPS unit that interfaces with I2C.
I have programmed a solution for Nano RP2040 Connect to read serial data from a GPS GT-U7 unit. It works fine. Perhaps my code could give you some inspiration to solve your problem.
#define RXpin 11
const int maxPacketLength = 300; // 300 µs; this applies to my GPS GT-U7.
// you have to determin the max packet length
// of your device
char c[500]; // data buffer
void setup() {
Serial.begin(9600);
pinMode(RXpin, INPUT);
}
void loop() {
// wait until RXpin is LOW -> hence inside the data packet.
// Reason: Between data packets RXpin is always high.
while (digitalRead(RXpin) == HIGH)
{
;
}
// now RXpin is low
delay(maxPacketLength);
// inside data idle -> RXpin is HIGH
for (int i = 0; i < 500; i++) // read 500 byte in data buffer
// if there are less data
// handle it with your code
// if packet length is constant and known,
// change 500 bytes to what is needed
{
c[i] = 0; // clear byte i from old data
// wait for start bit
while (digitalRead(RXpin))
{
;
}
// RXpin is LOW -> begin of start bit
delayMicroseconds(150); // wait 150 µs to be in the middle of data bit0
// 9600 baud rate -> bit length is 104 µs.
// 104 µs * 1,5 = 156 µs -> allow 6 µs for code
// execution
c[i] = c[i] | digitalRead(RXpin); // read first data bit in buffer c[0]
delayMicroseconds(100); // wait for next data bit; allow 4 µs for code.
c[i] = c[i] | digitalRead(RXpin) << 1;
delayMicroseconds(100); // the same for all remaining bits
c[i] = c[i] | digitalRead(RXpin) << 2;
delayMicroseconds(100);
c[i] = c[i] | digitalRead(RXpin) << 3;
delayMicroseconds(100);
c[i] = c[i] | digitalRead(RXpin) << 4;
delayMicroseconds(100);
c[i] = c[i] | digitalRead(RXpin) << 5;
delayMicroseconds(100);
c[i] = c[i] | digitalRead(RXpin) << 6;
delayMicroseconds(100);
c[i] = c[i] | digitalRead(RXpin) << 7;
delayMicroseconds(100);
}
Serial.println(String(c)); // print out data buffer containing 500 byte data
// fill in code for your application
}
I used a PIO based soft serial to get additional serial ports and was very happy with it.
Because the PIO's are dedicated co-processors on the RP2040 provided for doing hardware I/O, it has all of the benefits of a real hardware UART and none of the typical soft serial drawbacks. The RP2040 has eight PIO state machines and each PIO UART takes up two of them (one per direction). You can get four extra bidirectional or eight extra unidirectional UARTs on a RP2040 with PIO, above and beyond the two hardware UARTs.
Will you please provide a link to where you found the PIO based soft serial? I'm stuck trying to get more serial communications on the Nano RP2040 connect. I looked around and couldn't find anything.
Thanks
I am faced with a similar scenario. I found this link for a PIO Based Software Serial. Check it out and see if it helps. I am actively battling with the same problem.
I managed to fix the problem by installing a new board manager for Arduino Pico which contains Arduino Nano RP2040 Connect as a supported board.
This baord manager has a standard library that contains a wrapper around SoftwareSerial. It effectively allows you to use the GPIO pins for UART in addition to TX and RX pins accessible via Serial1
After installing the new board manager in Arduino IDE. Select Board->Raspberry Pi Pico/RP2040->Arduino Nano RP2040 Connect
After selecting the board under the newly installed board manager, create a new sketch and you can create UART interfaces like this
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(21,20); // these are GPIO pins on Arduino RP2040 D9 and D8
void setup(){
Serial.begin(9600); // USB
while(!Serial); // For USB
Serial1.begin(9600); // for the provided UART port on the Nano RP2040
mySerial.begin(9600); // our custom created Serial UART interface
}
void loop(){
Serial.write("Hello World"); // writes to USB serial monitor
Serial1.write("AT"); // writes to device connected to TX and RX of the nano rp2040 e.g GSM
mySerial.write("AT"); // writes to device connected to D9 and D8 of the nano rp2040 e.g another GSM
}
I hope this helps someone facing the same issue with the Arduino Nano RP2040 Connect