Hardware Serial to Software Serial on Same Uno

First, if this has been addressed, I apologize. I was not able to find what I was looking for after some searching.

With the Uno connected to the pc via the usb cable, I want to send data to the Uno hardware serial via the serial monitor. I then want the hardware serial to send the data to a software serial on the same Uno. I then want the software serial to send a modified version of the received data back to the hardware serial where it is displayed on the serial monitor.

The obvious question I expect is, why would I want to do that? Well, I'm just tinkering and want to see if I can. I can't think of a reason why it shouldn't be possible (I know I can do this with the PIC controllers, though the ide I use for that doesn't have a serial monitor), but everything I have tried didn't work. So, I'm asking people with more experience - you guys.

So, does anyone have an idea how to do this?

straight forward
base it on the SerialPassthrough example

Well the hardware Serial won't send anything to the soft serial: the Arduino will do that, but I guess that's what you meant. Read Serial, write serial.

But where will it go from software serial?- that would need to be connected to something external where your modified version will be created and sent back in on soft serial and out again over Serial.

Serial or serial, hard or soft, they're just ports.... So yes, monitor to Serial, serial to some other device, modify, serial back to Arduino, Serial to monitor.

Or maybe I'm missing something....

If all you effectively want to do is send thing A in over Serial from the monitor and get thing B sent back to the monitor, then the Arduino can of course do that on its own with only Serial: Read Serial, do stuff, write Serial.

Ok, Thanks for that.

Juraj, I'm looking at the passthrough example. It won't compile, and I don't really follow it. I don't see a softwareserial port being used in there, so I'm not really sure what to do with it. Looks like it just echoes input from rx to tx, but again, not really sure. I'm accustomed to more detailed control of registers (PIC controllers) so I see more of the stuff under the hood, so to speak.

sayHovis, I don't have any other device. So everything is to reside on the single Uno. So, to be a bit more specific, I want to enter data (let's say the number 12) in the serial monitor. I want the Uno to receive that number (I presume the data is received on pin 0) and send it to a softwareserial port on pins 4 and 5. I want the number received from the software serial to be modified (add one - 13) and send that number back to the hardware serial port to then be displayed on the serial monitor.

I have a sketch that I tried to make work, but the port(s) never stopped yelling at each other. In other words the serial monitor showed a continuous stream of data even though I wasn't entering anyting in the serial monitor.

mityeltu:
I want the number received from the software serial to be modified (add one - 13)

Where?

I don't have any other device

What's on the software serial pins?

Perhaps it's time to post your code....

mityeltu:
I want the number received from the software serial...

O.k. basic question...WHAT do you think is receiving anything sent from software serial? What is it connected to?

Steve

Well, that might all be where the problem lies. The way I have this connected is as follows:
pin 0 (hardware Rx) to pin 5 (Software Tx) and pin 1 (hardware Tx) to pin 4 (Software Rx). The usb cable is plugged into the pc and serial data is entered via the serial monitor. As I think about it, I see a big problem with this, but here's the sketch anyway.

#include <NeoSWSerial.h>
NeoSWSerial ss(4,5);  //  Rx, Tx

#define pulse 13

void setup() 
{
  // put your setup code here, to run once:

  //set pin 13 as input for hc05 state
  pinMode(pulse,OUTPUT);
  
  //initialize tmr1
  noInterrupts(); //  diable interrupt
  TCCR1A = 0; //  normal port operation
  TCCR1B = 0;
  TCNT1 = 34286;  //  tmr loaded for 0.5 S int (65536 - 16 MHz/256/2)
  TCCR1B |= (1 << CS12);  //  256 prescale
  TIMSK1 |= (1 << TOIE1); //  tmr1 overflow int enabled
  interrupts(); //  interrupts enabled

  
  //start serial comm with pc
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Ready");

  //start software serial port
  ss.begin(9600);
}



void loop() 
{
  unsigned char inByte = 0;
  
  // put your main code here, to run repeatedly:
  if(ss.available() > 0)
    {
      inByte = Serial.read();
      Serial.print("Received: ");
      Serial.write(inByte);
      Serial.print(" - ");
      Serial.println(inByte, HEX);

      ss.write(inByte);
      ss.print(" - ");
      ss.println(inByte, HEX);
    }
}


ISR(TIMER1_OVF_vect)
{
  TCNT1 = 34286;  //  reset timer for 0.5 s int
  digitalWrite(pulse, !digitalRead(pulse));
}

OMG

mityeltu:
So, does anyone have an idea how to do this?

Leaving aside the question of why you would want to do this ...

If you connect the HardwareSerial RX pin to the SoftwareSerial Rx pin then anything that is received with HardwareSerial will also be received by SoftwareSerial.

Connection in the other direction is not so simple because the Serial (either hard or soft) Tx line idles HIGH so if you connect the SS Tx pin directly to the HW Tx pin you are likely to have problems. I have never tried this so I don't know if there really would be a problem, or how to solve it.

Alternatively, you could connect HW Tx to SS Rx. That way anything that is sent from HW serial to the PC can be received with SSerial. There may still be a problem with data sent from SSerial with HW Rx connected to SS Tx.

Which all brings me to the conclusion that I would need a lot of justification to be persuaded to go to all that trouble.

I know how to connect several separate Arduinos to a single Serial master using one of the spare HW serial ports on a Mega as the master - just in case that idea looms somewhere in your future plans.

...R

Just to put you out of your misery: as I understand it, you want to connect to the serial monitor and the hardware serial to connect to another device, i.e. the software serial. You can do this in principle but not to communicate with the serial monitor. You could swap data port to port, I guess, and I will leave it to you to work out why you would want to pursue such a pointless exercise, but the serial monitor serves no other purpose than to show what is going on.

I don't know much about software serial, but you may be able to have the serial monitor participate in the comedy by adding another software serial port and use that for the "internal" conversation with the software serial port you have already created.

The fundamental problem is that the hardware serial facility is shared between the serial monitor and the COM port, which brings limitations, as I expect you have already found when trying to upload your programme.

Yeah, I sorta figured all that out not long after I posted the sketch and really considered what it was I was doing with the wiring. My bad. Just stupid. I'm just trying to learn the Arduino having come from a lot of experience with PICs. Completely different platform that confuses me. Coming from a platform that makes me work at the registry/bit level, the Arduino is a bit troublesome.

Anyway. I have abandoned this as fruitless and probably impossible. I did however attach a PIC to the ss port and manage to make the system work kinda like I wanted: data from pc sent to Arduino via the serial monitor then to the ss port, modified (by the PIC) and sent back to ss port (by the PIC) and then displayed on the serial monitor.

If nothing else, it was an entertaining mess.

Thanks for putting up with me. I got a good laugh from the OMG post. I saw that after I tweeked and realized just how idiotic this was. Thanks again, all of you.

mityeltu:
I did however attach a PIC to the ss port and manage to make the system work kinda like I wanted: data from pc sent to Arduino via the serial monitor then to the ss port, modified (by the PIC) and sent back to ss port (by the PIC) and then displayed on the serial monitor.

.... which is what I thought you were getting at all along, so that's a result.

mityeltu:
I did however attach a PIC to the ss port and manage to make the system work kinda like I wanted: data from pc sent to Arduino via the serial monitor then to the ss port, modified (by the PIC) and sent back to ss port (by the PIC) and then displayed on the serial monitor.

I must say that is not what came to my mind when I read the Original Post but it is an entirely practical arrangement. And any Arduino could be used in place of the PIC.

...R

from the library's doc:
You can use the SerialPassthrough sketch from WiFiEspAT/Tools in IDE Example menu to bridge the esp8266 to computer over Arduino with the above wiring. You can then send AT commands to the AT firmware from the Serial Monitor. It is even possible to upload AT firmware if the esp8266 is on hardware Serial.

I was able to interface the Uno with WiFi without any difficulty earlier.

Snce I only have the one Uno (uno Uno - Ha!) I decided to use the PIC.