Project Idea: data from PC to PC

Hello everyone! I'm rather new to the Arduino scene and need a little help in conceptualizing the approach to the flow of data for a project. Here is what I am trying to do and how I think I can achieve it.

The Project:
Pass data (x/y coordinates) from one Windows PC (PC1) to another Windows PC (PC2). Seems simple enough, right? But I also want to be able to control when the data flows to PC2 by pushing a key on the keyboard of PC2. I may scrap the keyboard and use a button on a breadboard.

The Proposed Solution:

  1. Generate x/y coordinates in a python script on PC1 (one set of x/y every second)
  2. Send coordinates via python to Arduino Uno R3 (a board I have handy) using the USB cable to a specific com port
  3. Uno reads data from python and sends coordinates directly to Arduino Leonardo via Tx/Rx serial connection (not sure how to differentiate serial connections USB com port vs Tx/Rx pins)
  4. Leonardo regularly checks for serial input over com port
  5. Leonardo gets input from PC2 over com port via python script to start collecting data from Tx/Rx serial connection
  6. Leonardo immediately prints those coordinates to PC2 via USB cable to the com port, which is then read with a python script

As you can see in the proposed solution, the approach hinges on the ability to explicitly identify and use the two serial ports on each Arduino. I am hoping that the speed to move from one serial port to the other can keep up with the flow of coordinates so there isn't much lag. I did a sample script in python to hit a key on my keyboard, turn on a LED, and then return a message. Worked all within a second so I am hopeful.

So there it is. I welcome comments or suggestions on my plan. I'm curious if a more advanced Arduino user would take a totally different approach. Or am I just off in thinking I can use the different serial ports like this.

You can connect USB-serial to a second serial-USB (S-->R, R-->S) and simply control everything in Python.

An Uno only has one UART port, so software-serial would need to be used to create the second serial port.
Leonardo has a single UART port, so software-serial is needed here too.

Your writeup is very confusing and PC + Python just adds clutter but you can find info about connecting PC + Arduino, Arduino + Arduino all from this link:
PC serial to Uno to Leonardo to PC at DuckDuckGo

Kermit via COM port to COM port.

So you're saying no Arduino at all? Not sure what R represents.

Lots of solutions that do not require any Arduino.

Get two USB to TTL leads and connect them together.
Or two USB to RS232 leads and connect them together.
When connecting them together make sure the output of one is connected to the input of the other.

Or
Send the data over Bluetooth or WI+FI

No need for software serial there; Leonardo has native USB (Serial) and UART (Serial1).

Yes on pins 1 & 2.

S = Send
R = Receive

Thanks for all the input everyone. I purchased a USB to TTL device off Amazon and started playing with it. I have been able to get my Arduino to send a simple string to the com port of the computer (I used Putty to monitor serial port). Unfortunately I can't get the PC to send a message to the Arduino. Here's my code on the sender (PC using python) and Arduino Leonardo. I do not get errors when running these codes and I have double checked, wiring, com ports and baud rate. All I get in the serial monitor is "Waiting.." See any issues with my code?

Python code:

import keyboard
import time
import serial
arduinoData=serial.Serial('com7',9600)

while True:

    if keyboard.is_pressed('o'):
        cmd='ON\r'
        arduinoData.write(cmd.encode())
        time.sleep(1)
    
    if keyboard.is_pressed('p'):
        cmd='OFF\r'
        arduinoData.write(cmd.encode())
        time.sleep(1)

    if keyboard.is_pressed('q'):
        break

And Arduino Leonard code:

#include <SoftwareSerial.h>

String myMessage;

SoftwareSerial mySerial (0,1);

void setup() {
  pinMode(0, INPUT);
  pinMode(1, OUTPUT);
  Serial.begin(19200); //serial to PC1 so I can see IDE's serial monitor
  mySerial.begin(9600); //serial to PC2 via USB to TTL

}

void loop() {
  
  while(mySerial.available()==0){
    Serial.println("Waiting..");
    delay(1000);
  }
  myMessage=mySerial.readStringUntil('\r'); 
  Serial.println("Message Rev'd");
  Serial.print("Message was: ");
  Serial.println(myMessage);
  delay(250);
 
}

It's never a good idea to use SoftwareSerial on hardware UARTs. Pins 0 and 1 are Serial1 on the Leonardo, use that instead.

You use two ports on the Arduino (USB and TTL-to-USB adapter. Your python is talking to one, which one? And what is the second port talking to? Serial monitor?

Appreciate the help. I'll try removing the software serial port and see how it goes. I also bought a new USB to TTL today.

And I think you're on to something about which ports I'm directing things to. I'll double check my setup.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.