I have code developed to read sensors via UART which have worked fine on different boards uno, mega, esp32 in the Arduino IDE, to make things easy to debug it also echos values to a terminal via the USB to Arduino IDEs serial monitor, which is all fine and dandy and causes no problems at all using SoftwareSerial or hardwired UARTS. I am trying to get the same system working on a Pi Pico and am not having any luck, there is no software serial and the only way to get a hardware UART and debug running at the same time seems to involve using cmake and something that is not the Arduino IDE since it doesn't seem to use cmake, neither of which I am familiar with. Is there an easy way round this? or do I have to wait until SoftwareSerial is written for the pico? or heaven forbid learn how to use visual studio, what cmake is and how to use it.? Thanks in advance! */
Did you try using Serial1.xxx(), which shows up on pins 1 and 2 of the PICO?
Don't be confused by the RPi SDK documentation; all of that is hidden when you use the Arduino core(s).
No, I want to use UART1 on pins 6 and 7 to control the sensor and I want to use UART0 to send data via the USB to serial monitor on the Arduino IDE, this is easy normally!
With the Arduino, Serial.xxx is the Virtual serial port over USB (which doesn't actually use a UART), Serial1 is UART0 on pins 1/2, and UART1 doesn't appear to be implemented by default, but it looks like you can add it by putting:
UART Serial2(8, 9, NC, NC);
at the top of your sketch. I'm not sure whether you can use pins 6&7 instead, but it seems likely.
Arduino: 1.8.13 (Linux), Board: "Raspberry Pi Pico, 2MB (no FS), 125 MHz, Disabled, None, Pico SDK"
Cheers
Russsh
sketch_jul07a:6:1: error: 'UART' does not name a type
6 | UART Serial2(8, 9, NC, NC);
| ^~~~
sketch_jul07a:16:6: error: variable or field 'loop' declared void
16 | void loop {
| ^~~~
sketch_jul07a:18:11: error: expected '}' before ';' token
18 | delay(100);
| ^
/home/russ/Arduino/sketch_jul07a/sketch_jul07a.ino:16:11: note: to match this '{'
16 | void loop {
| ^
sketch_jul07a:20:3: error: expected declaration before '}' token
20 | }
| ^
exit status 1
'UART' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I looked at the Philhower core more carefully, and it seems to me that Serial1 and Serial2 are already both defined and set up. Have you actually tried using them, or are you just being misled by the RPi SDK documentation?
Is there a way to put this in the Arduino IDE?, how do I set up the UARTS and serial port in the Arduino IDE as I do with standard Arduino devices, Due, Mega etc...
What I've been describing IS in the Arduino IDE. Once you install either the Arduino "MBed OS rp2040" or the Philhower core.
how do I set up the UARTS and serial port in the Arduino IDE as I do with standard Arduino devices
The same way, possibly with the addition of that UART statement, if you're using the Arduino Mbed core type.
Here; this demo sketch works with either core. Tested, and everything!
/*
* Demonstration of using multiple Serial Ports on RPi Pico board.
* By default when using the Arduino Cores:
* Serial is a virtual Serial port operating over the USB
* Serial1 is tied to UART0 on pins 1 and 2
* Serial2 may need creating, and is UART1 on pins 8&9
*/
#ifdef ARDUINO_ARCH_MBED_RP2040
// For the Arduino MBedOS Core, we must create Serial2
UART Serial2(8, 9, NC, NC);
#else
// For the Earl Philhower core ( https://github.com/earlephilhower )
// Serial2 is already defined.
#endif
void setup() {
Serial.begin(9600);
Serial1.begin(115200);
Serial2.begin(115200);
while (!Serial)
; // Serial is via USB; wait for enumeration
}
void loop() {
Serial.println("This is port \"Serial\"");
Serial1.println("1111111111111\r\nThis is port \"Serial1\"");
Serial2.println("2222222222222\r\nThis is port \"Serial2\"");
if (Serial1.read() > 0) { // read and discard data from UART0
Serial.println("Input detected on UART0");
}
if (Serial2.read() > 0) { // read and discard data from UART1
Serial.println("Input on UART1");
}
delay(2000);
}