What is needed, ideally, is another com port so you can use the serial terminal built into the IDE.
I have, in the past, used an Arduino Mega with an added FTDI Serial USB converter for a second com port - 1 to Air Manager messageport and the other to the debug terminal. - 2 com ports, 2 usb leads, 2 usb ports used etc. Ok,it works, but it is a pain.
It looked like this.
Using the PICO I thought there has to be a better way. It uses virtual com ports - so surely there must be a way to add more as we are hardly taxing the USB port with one little com port.
Well, long story short, it IS possible. After a bit of digging I found it is possible to add the native USB (USBSer1) as well as the standard 'Serial' that messageport uses.
From the Arduino IDE using Earle Philhowers core for rp2040, you select, from the 'tools' menu, the Adafruit tinyusb stack for USB. You will need to edit the tusb_config_rp2040.h file to assign more potential CDC class devices by changing this line in the file -
Code: Select all
#define CFG_TUD_CDC 2 // was 1 - edited by Joe for dual VCP on pico
Code: Select all
// Joe Hanley (JPH) 9 2022
// test of two virtual com ports over a single usb on PICO with AM Messageport
#include <Adafruit_TinyUSB.h>
#include <si_message_port.hpp>
// Create extra USB Serial Ports. "Serial" is already created.
Adafruit_USBD_CDC USBSer1;
SiMessagePort* messagePort;
void setup() { // setup: run once
//messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_UNO, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_RPI_PICO, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
pinMode(LED_BUILTIN, OUTPUT);
//Serial.begin(115200); // dont need to 'begin' here as messageport does it already
USBSer1.begin(115200); // start our second virtual com port
} // setup end
void loop() { // main program loop
messagePort->Tick(); // make sure to call frequently
} // loop end
static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
if (message_id == 100) {
digitalWrite(LED_BUILTIN, HIGH);
// send data to our debug terminal on USBSer1
USBSer1.print("We received message_id ");
USBSer1.println(message_id);
}
if (message_id == 101) {
digitalWrite(LED_BUILTIN, LOW);
USBSer1.print("We received message_id ");
USBSer1.println(message_id);
}
}
Code: Select all
pico_test_led = hw_message_port_add("PICO_1", new_message_received)
function new_message_received(pico_test_led, payload)
--
end
if hw_connected("RPI_PICO_A") then
print("We have the right hardware hooked up !")
end
hw_message_port_send(pico_test_led,100) -- pico built in led on
--hw_message_port_send(pico_test_led,101) -- pico built in led off
the lower number is the 'serial' port for messageport so start AM and add device COM4 and you should see - Pico is connected,
You can select com 30 in the arduino IDE and open the serial monitor and you can have full debug messages and outputs via USBSer1.
You use it just like any other print in Arduino - as in USBSer1.print or USBSer1.println etc.
All over a single USB cable.
Neat !
left window is IDE Serial Terminal on com 30 and right is AM messageport on com 4 You can always use the
#ifdef DEBUG
USBSer1.print(xyz); // print some useful stuff on the serial terminal on the second virtual com port ...
#endif
and add all the debug areas through your code for debugging and control it with a single #define DEBUG - or just comment uncomment
Very useful.
2 com ports via one USB cable.!
Next we need multiple instances of messageport so we can run one instance on each core of the pico with it's own vcp and still only use 1 usb cable.
That's for later though lol
Joe
ps - and, no, it's not limited to two com ports ! - you can have more if you wanted ! - all over the same single USB cable. You could run one device as a master to collect data from other devices and send it all over 1 nice neat single USB from a complete cockpit if you wanted to. How neat is that ? - figuratively and literally !.
Some of the STM32 dev boards have 6 hardware serial ports built in. These can be linked to other boards. Endless possibilities.