My first attempt to use a Pi Pico.
I am using Earle Philhower's core wit the board selected as Raspberry Pi Pico W
I want a function to which I can pass the required setup parameters and have the function configure the serial ports as desired (I've done similar with the 4809 without issue).
This compiles OK:
#include "Arduino.h" // I know, it's included automatically,
// I have included it to make this example close to the actual, much larger, sketch I am working on.
void setup_serial(HardwareSerial* ptr = nullptr, uint8_t RxPin = 2, uint8_t TxPin = 1, uint32_t baudRate = 9600);
void setup() {
setup_serial(&Serial1, 2, 1, 115200);
}
void loop() {
}
void setup_serial(HardwareSerial * ptr, uint8_t RxPin, uint8_t TxPin, uint32_t baudRate) {
if (ptr != nullptr) {
Serial1.end();
Serial1.setRX(RxPin);
Serial1.setTX(TxPin);
Serial1.begin(baudRate);
//ptr -> end();
//ptr -> setRX(RxPin);
//ptr -> setTX(TxPin);
//ptr -> begin(baudRate);
}
}
So that tells me that the class that contains the function begin also contains the functions setRX and setTX.
If I change the code to this then it fails:
#include "Arduino.h" // I know, it's included automatically,
// I have included it to make this example close to the actual, much larger, sketch I am working on.
void setup_serial(HardwareSerial* ptr = nullptr, uint8_t RxPin = 2, uint8_t TxPin = 1, uint32_t baudRate = 9600);
void setup() {
setup_serial(&Serial1, 2, 1, 115200);
}
void loop() {
}
void setup_serial(HardwareSerial * ptr, uint8_t RxPin, uint8_t TxPin, uint32_t baudRate) {
if (ptr != nullptr) {
//Serial1.end();
//Serial1.setRX(RxPin);
//Serial1.setTX(TxPin);
//Serial1.begin(baudRate);
ptr -> end();
ptr -> setRX(RxPin);
ptr -> setTX(TxPin);
ptr -> begin(baudRate);
}
}
The error message is:
C:\Users\Perry Bebbington\Documents\Arduino\Forum questions\pi_pico_serial_setup\pi_pico_serial_setup.ino: In function 'void setup_serial(arduino::HardwareSerial*, uint8_t, uint8_t, uint32_t)':
pi_pico_serial_setup:22:16: error: 'class arduino::HardwareSerial' has no member named 'setRX'
22 | ptr -> setRX(RxPin);
| ^~~~~
pi_pico_serial_setup:23:16: error: 'class arduino::HardwareSerial' has no member named 'setTX'
23 | ptr -> setTX(TxPin);
| ^~~~~
exit status 1
'class arduino::HardwareSerial' has no member named 'setRX'
So my guess is that the class I really want isn't the Arduino HardwareSerial but some other class inside Earle Philhower's core. Is this correct? If so, I don't know how to find it because of the vast number of files involved. I've searched header files with names that look likely and not found it. Or maybe I've got the wrong idea.
Suggestions and help welcome please.