SerialConnection to RPi Pico / Arduino mystery

Hello guys!
I have used Xojo serial communication over USB to different Arduino platforms for over ten years but now I am stuck.
The task is pretty straight forward: Send some ascii bytes to the Pico and then recieve the reply from the Pico.

Edit: The strange behavior can only be seen when communicating with Pico on Arduino. For another device, both type of serial connections work as expected.
End edit.

I have tried this with both the Xojo SerialConnection and the MBS SerialPort. Here is what happens:

Xojo SerialConnection: The port opens without problems and the string is successfully sent using SerialConnection.Write. The Pico sends a reply but the DataRecieved event does not fire. When I close the SerialConnection and then opens the Arduino Serial Monitor the reply from the Pico turns up there.
MBS SerialPort: The port opens without problems and the string is successfully sent using SerialPort.Write. The Pico sends a reply but the DataAvailable event does not fire. When I close the SerialConnection and then opens the Arduino Serial Monitor the reply from the Pico turns up there.

So far the same behavior for both.
Here comes the mystery:
With the MBS SerialPort, after just opening and closing the connection with the Arduino Serial Monitor (not writing anything), everything just works fine! That is everything works until I restart the Pico. After a restart we are back to not working, until I open and close the connection with Arduino Serial Monitor again.
However the opening and closing with the Arduino Serial Monitor does not have any effect on the Xojo SerialConnection. It still does not fire its DataRecieved event.

What is it that the Arduino Serial Monitor does that makes the communication work? Some kind of reset? Something related to the control signals?

I run Xojo 2022r2 on W11 pro

Wanted to upload example projects but don’t know how.

Does your SerialConnection go out of scope before it can get the response?

Tim, thank you for your reply. I don’t exactly know what you mean but in my stripped down test project there is just one window with a SerialConnection control, a popup to select the port, a button to connect and another button to send. Nothing goes anywhere else :). Everything is referencing the SerialControl instance directly.

I added an edit in the original message clarifying that the problem only occurs when trying to communicate with Pico on Arduino. With other devices it works fine.

If you have something like

var sc as SerialConnection
// set up sc
sc.write "abc"

As soon as the method/event ends, sc goes out of scope and is destroyed. Instead, make the SerialConnection a property of the window and instantiate as needed.

Ok, I see what you mean. That is not the problem. The SerialControl is in the windows controls list.

I realize now that everybody is at the Developer Conference and focusing on that :slight_smile: .
In the mean time I managed to solve the mystery by using a serial analyzer. In the end the problem was quite trivial. The serial monitor that was able to communicate with the Pico, set DTR on opening, but the XOJO Serial connection did not. Apparently setting DTR was a required for communicating with the Pico.
By adding the line:

SerialConnection1.DataTerminalReady = True

before the open command, this was taken care of and communication works.

Problem solved! Have a great conference!

2 Likes