Mixing two serial signals

Hello

I have a home made CNC machine that uses a Rambo board (basically a mega2560p).
From literally forever investigating this, I cannot seem to enable a second serial port, as it seems the Marlin code is not set up properly to support it.

I am trying to make a serial remote control to send basic commands to the CNC (G-code), such as home etc.

Normally, I do this in the printing software, but it would be good to be able to control the CNC immediately without firing up my laptop.

There is an LCD attached to the Rambo, but the interface is horrible.

My question (got there in the end), is could you 'mix' serial inputs?
I am never going to operate two input devices at the same time, so could you connect two serial transmissions to the same RX pin on the Rambo board>

I would imagine you need some kind of resistor in-line.

Obviously, the data will be corrupt if it receives data at the same time, but that won't happen. If it did, then nothing happens anyway.

Any thoughts?

My question (got there in the end), is could you 'mix' serial inputs?

Yes, but.

I have a GSM module and a mains voltage measuring device both sending serial data to the same serial input. They are multiplexed with a 4502 analogue input selector (more because I happen to have loads of them than for any other reason) so the controller knows which serial data it is getting and runs the correct code to read it.

I would imagine you need some kind of resistor in-line.

I can't imagine that working.

If you just want to switch between 2 otherwise identical sources of identical data then a double pole (for tx and rx) double throw switch might be all you need.

I have a home made CNC machine that uses a Rambo board (basically a mega2560p).
From literally forever investigating this, I cannot seem to enable a second serial port, as it seems the Marlin code is not set up properly to support it.

Please share your code and your attempts to enable one of the serial ports, maybe someone here will spot your mistake.

SteveRC2017:
My question (got there in the end), is could you 'mix' serial inputs?
I am never going to operate two input devices at the same time, so could you connect two serial transmissions to the same RX pin on the Rambo board>

"mix" is probably not the correct word because (even if the connection was possible) you would have to restrict the system to one or the other at any one time or you would get garbage.

IIRC the RAMBO (or is it RAMPS?) board connects to the PC with a USB cable. When a serial system is idle the TX line is HIGH which means that the TX from the on-board USB-TTL converter will be pulling the Serial Rx line HIGH. You would need to prevent that in order to feed another TX to the Serial Rx and that would require surgery to the circuit board - which I would not try and would not recommend.

...R

The official Mega has current limiting resistors between the usb-to-ttl RX and TX lines and the TX and RX lines of the Mega2560 micro.

You should be able to safely connect the TX of whatever other device to the RX of the Mega2560 processor (Mega board pin 0).

Note:
No idea about the specifics if your board; you can add an additional resistor in series between the TX of your device and the RX (pin 0) of the Rambo board.

It's the Rambo board.

I did think of cutting the entire USB connection while using the remote, but then I will have to 'reconnect' the software every time.

The Rambo Marlin code does have a second Serial declared in the code, but it is commented out and some experimenting has not managed to get it working.
I am finding information on the advanced functions and abilities of the Rambo board quite hard to come by.

For instance, there are various available commands for LED lighting etc. all accessible via G-Code, but no mention anywhere of what pins are activated when you send the command.

I have the wiring diagram of the Rambo board, and all serial ports are brought out to a header, but not much good if they are not configured.

My only other option is a keystroke replicator connected to the laptop instead, and maybe utilise the USB connection that is already there?

You can type in any G-code command on the CNC software. I will check later to see if you can actually access the command box, and then send a command just using the keyboard.

If that works, then I could just macro the commands and send the sequence mimicking the keyboard.

OK. Repetier has basically no keyboard shortcuts, so that idea isn’t going to fly.

Looks like it might be serial piggyback then.

So, if I fire my serial TX out of my Pro-Mini with the correct serial code on it, I should ‘in theory’ be able to simply piggyback onto the RX pin of the 2560p that is currently being used by the PC?

I assume we are talking a resistor in-line here. What kind of value? I was thinking 100R, but I have not based that on anything scientific.

What happens if you disconnect the RX pin on the Rambo (2560p) from the pc briefly, while you give it a new command from somewhere else?
Will the attached PC lose its connection? or is that kept alive by the transmission from the Rambo to the PC?

I already have the ‘known working’ Arduino code here that talks to the Rambo board through the standard USB serial port.

It only transmits data, not receive. So maybe just swap the Rambos RX input for a brief period?

The PC USB connection goes to the USB chip which converts the USB bus to Serial. If you don't break that connection, then it doesn't care what happens on the Serial side of that chip.

The standard Arduinos (Uno and Mega) have their USB chip permanently connected to pins 0 and 1 for Serial communication. But you can override that by connecting another device to those pins. Like a GPS, for example. The reason why the override works is the resistor between the USB chip and pin 1. But it only works one way. You can't un-override it without disconnecting the [GPS] device.

OK. I think best way forward is experimenting.
Worst case scenario... new Rambo board

Robin2:
"When a serial system is idle the TX line is HIGH

I remember learning this... twice almost 20 years apart.

Serial works opposite to uninformed "common sense" that would say when it's off, the line is LOW.

But idle-HIGH is how serial avoids induced noise, otherwise the cables would be shorter.

Mega has 4 UARTs. Are they all used?

No, I don't think all the UARTs are used. But, unless they are coded into the Marlin software to actually do something (or even be read), then that doesn't help me (unless I am totally wrong).

The following is in the Marlin config.h file

/**
 * Select the serial port on the board to use for communication with the host.
 * This allows the connection of wireless adapters (for instance) to non-default port pins.
 * Note: The first serial port (-1 or 0) will always be used by the Arduino bootloader.
 *
 * :[-1, 0, 1, 2, 3, 4, 5, 6, 7]
 */
#define SERIAL_PORT 0

/**
 * Select a secondary serial port on the board to use for communication with the host.
 * This allows the connection of wireless adapters (for instance) to non-default port pins.
 * Serial port -1 is the USB emulated serial port, if available.
 *
 * :[-1, 0, 1, 2, 3, 4, 5, 6, 7]
 */
//#define SERIAL_PORT_2 -1

But I don't understand what to do with that second serial port? Any value I put in there seems to stop the compiling. Why does it give you options from -1 to 7?
Does this second serial give you the same options/functions as the primary serial?

I wish there were slightly clearer explanations of the functions of these widely used Rambo boards... it's very sporadic (not helped by my ignorance)

OK. Found why it would not compile. I have now got it to set the second serial as:

#define SERIAL_PORT_2 1

So, in theory?.. this should enable serial port 1.

Attached pic is what I believe is the serial header.

But idle-HIGH is how serial avoids induced noise, otherwise the cables would be shorter.

Eh?
I cannot imagine how that could be true. Please explain.

If you can reduce noise then you can have longer cables for the same S/N ratio. If you cannot then you must limit the maximum length on the connections.

If you can reduce noise then you can have longer cables for the same S/N ratio. If you cannot then you must limit the maximum length on the connections.

I understand that. I don't see how the idle voltage does this. Shielding, twisted pairs, correct impedance matching and termination do that.

The original RS232 specification used +12V to represent "space" or logic 0 and -12V to represent "mark" or logic 1. So it "idles" with a positive voltage.

It's rare to see actual 12V in modern RS232 transmitters. You are more likely to see +6V and -5V, but it still uses negative for "1".

I think it is really the 24V difference which contributes to the S/N ratio of the original specification.

PerryBebbington:
Eh?
I cannot imagine how that could be true. Please explain.

Because a line with 5V is less likely to become digital LOW due to inductive interference than a 0V line is likely to become digital HIGH for the same reason.

When you connect an unterminated wire to an analog pin, electrical noise tends to raise the voltage. Once the reads get HIGH they tend to stay that way.

That's why.

But you can believe that engineers would keep idle wires HIGH for no good reason but to waste current if you want.

I'm pretty sure that this was known in the 19th century just getting telegraph working.

MorganS:
The original RS232 specification used +12V to represent "space" or logic 0 and -12V to represent "mark" or logic 1. So it "idles" with a positive voltage.

It's rare to see actual 12V in modern RS232 transmitters. You are more likely to see +6V and -5V, but it still uses negative for "1".

I think it is really the 24V difference which contributes to the S/N ratio of the original specification.

RS485 that can have cables 100's of meters long is +12 to -12 isn't it?