On my PC I have 2 applications connected via a pair of virtual ports COM1 and COM2. I have also 2 Arduino Nano connected to the PC via 2 USB port COM3 and COM4.
Application1 act as a hub and exchanges data via COM1(Virtual) with Application2 via COM2(Virtual) and with the 2 Arduino via COM3 and COM4.
So, if I want to send a data from Arduino2 to Application2, data goes from Arduino2 to Application1 (hub) and from Application1 to Application2.
The same process for Arduino1. The system works fine, but for speed reasons it would be better if each Arduino could exchange data directly with the two Applications. In other words my question is if it is possible that each Arduino can exchange data directly with the 2 Applications on the PC, and if yes, how to perform the task. The code is written in VB. Thanks.
you could use a microcontroller with multiple hardware serial ports as the hub, e.g. Arduino Mega
the application and nanos transmit packets to the Mega indicating the destination of the data
the Mega forwards the packets to the appropriate destination
how fast do you require the communication ?
if the nanos are transmitting to the hub do you also require serial monitor communications
any particular reason to be using two applications and two nanos?
won't one more powerful microcontroller do the work?
edit: a diagram showing the data flows may help?
Nano (assuming you mean classic Nano 3) have only one hardware serial port. If you wanted to attach a second serial port, you would need to use software serial, which is quite slow, and additional USB-serial adapters. Some of these are also slow, it seems.
Most (but not all) Nano will communicate at up to 2,000,000 baud using their hardware serial ports.
If you switch to a model of Arduino with multiple serial ports, and choose your USB-serial adapters carefully, you should be able to get 2,000,000 baud on each port.
If you choose a model of Arduino with native USB, the baud rate you choose on the code is actually irrelevant. The port will always run at the full speed of USB (albeit only USB 1.0/1.1). I'm not sure how fast that is in practice but could be as high as 12,000,000 baud.
In general, if speed is important, connecting multiple Arduino to a PC, and using virtual COM ports between processes, is not a good strategy!
You'll need to open two serial connections, one for each application. You can use the Serial library in Arduino to manage multiple serial ports.
void setup() {
Serial.begin(9600); // Start serial communication
Serial1.begin(9600); // Start second serial communication
}
The system is used for the management of a radio amateur station. I can't use just one microcontroller because each Nano manages a different piece of equipment, an antenna switch to one side and a linear amplifier to another side. The Application2 manages via another USB port the radio exciter and is written by the radio manifacturer, so I can only set the COM port. The Application1 was written by me in VB and act as hub. The speed is important because involve protection functions.
This could be a good solution. Can you give me the link to download the library, because I didn't find it in the library management section of the IDE. Thanks.
to interconnect a pair on nanos using serial communications have a look at AltSoftSerial
in particular read the section on Serial Port Options
Thanks for help, I'll try for the best solution
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.