Forwarding traffic between two hardware UART and monitoring traffic?

Hi,

I am trying to understand what command my ebike sends, and to do that I am going to purchase a RobotDyn Mega 2560 PRO MINI which has 4 hardware UARTs.
To two of the ports I will cut the two signal wires from the bike and connect each pair to two different ports on the board.
To the third port I will connect a HC-05 Bluetooth board which I will use to monitor traffic.

So how do I forward traffic from Serial2 to Serial3 while monitoring traffic with HC-05 on Serial1?

I don't want to touch the traffic, only monitor the signals sent. The communication sent in the bike signal wires is in HEX format.

How do I program the Mega 2560 Pro Mini to do this, and how can I monitor the traffic?

Thank you!

Don't cut the wires in the way you describe. Trying to forward signals runs the risk of breaking everything.

If you want to monitor a serial communication you need to connect Rx of Serial1 to one of the pair of lines on your Ebike and connect Rx of Serial2 to the other line.

That way Serial1 will pick up the data from A to B and Serial2 will pick up the data from B to A.

You also need a GND connection between the Mega and the bike's serial system.

...R

Robin2:
Don't cut the wires in the way you describe. Trying to forward signals runs the risk of breaking everything.

If you want to monitor a serial communication you need to connect Rx of Serial1 to one of the pair of lines on your Ebike and connect Rx of Serial2 to the other line.

That way Serial1 will pick up the data from A to B and Serial2 will pick up the data from B to A.

You also need a GND connection between the Mega and the bike's serial system.

...R

I have schematics of a person who has done this before, and attached you can see how it is wired.


Connect to display and connect to controller contains the white and green wire that needs to be cut.

I will connect all the grounds to the bikes +5V ground cable. Does this look alright to you?

How would I program the arduino to monitor the traffic?

No, don't cut them :slight_smile: You absolutely don't need to. You don't even need an Arduino. Just two serial USB converters.

septillion:
No, don't cut them :slight_smile: You absolutely don't need to. You don't even need an Arduino. Just two serial USB converters.

But I will use this board later to input signals to this. And that's why I can cut them because I need to do it to be able to use it for what I need.
Here you can see the topic which does what I want to do:

But the thing is that my bike doesn't use the exact same model of engine, which means the signals are not identical, that is why I need to monitor them first.

joq3:
How would I program the arduino to monitor the traffic?

That question is the reason why you should NOT cut the wires.

When you know enough not to need to ask that question it may be time to cut the wires.

If you just monitor as I suggested you can probably use the code in Serial Input Basics to capture the messages. Just make two copies of the code, one to listen to Serial1 and the other to listen to Serial2

...R

Robin2:
That question is the reason why you should NOT cut the wires.

When you know enough not to need to ask that question it may be time to cut the wires.

If you just monitor as I suggested you can probably use the code in Serial Input Basics to capture the messages. Just make two copies of the code, one to listen to Serial1 and the other to listen to Serial2

...R

But as you can see in the thread I posted, I will need to cut these wires later to make this project. And the traffic is already forwarded in the arduino code in the project. Just that I don't need the other functions at first because I need to find out what HEX codes my bike is sending.
https://hastebin.com/xufapekane.cs
Pasted the code here.

joq3:
But I will use this board later to input signals to this.

That's stage 2 :wink: For now, you have far less change of introducing errors in the process of simply monitoring it and giving yourself headaches if you don't cut them.

Look on the web for Virtual Serial Port Emulator VSPE.
you should be able to find a free version, there are at least 3 which come up on google as top ranking.
with VSPE you can monitor the serial ports within windows without requiring hardware. Its simply a case of creating a virtual port of one serial device then splitting that port to a number of connections.
so ebike, The Arduino serial monitor and whatever else you need connected. Ebike will talk to pc through the virtual port and the serial monitor will display what is being transmitted/received.

I doubt the ebike is connected to a computer atm :wink:

JT007:
Look on the web for Virtual Serial Port Emulator VSPE.
you should be able to find a free version, there are at least 3 which come up on google as top ranking.
with VSPE you can monitor the serial ports within windows without requiring hardware. Its simply a case of creating a virtual port of one serial device then splitting that port to a number of connections.
so ebike, The Arduino serial monitor and whatever else you need connected. Ebike will talk to pc through the virtual port and the serial monitor will display what is being transmitted/received.

Yes, I have used something similar to find out how the programming software communicates with the bike. Used com0com and HTerm. But this was without the bike connected (I imitated a bike).

I am going to purchase the USB variant of the RobotDyn Mega 2560 PRO MINI anyway. But I will listen to your advice and not cut the cables at first, only tap into them with the Arduino. Do I need to connect RX to ground also, as the sketch is showing?

Always connect GND. Remember, current need a path and thus a voltage (which serial data is in essence) always needs a reference.

septillion:
Always connect GND. Remember, current need a path and thus a voltage (which serial data is in essence) always needs a reference.

I just made this diagram, is this how you mean it should be connected?

So the green and white cables are each different TX and RX in either end?

I don't believe you need any resistors on the wires connecting the Mega to the signal system on the right in the diagram. And both lines should go to separate RX pins on the Mega so it can receive both sides of the dialogue.

You need to have a GND connection between the Mega and the signal system on the right in the diagram

A photo of a simple wiring diagram made with pencil and paper would be clearer even if less artistic. At least one could read the pin labels.

...R

Robin2:
I don't believe you need any resistors on the wires connecting the Mega to the signal system on the right in the diagram. And both lines should go to separate RX pins on the Mega so it can receive both sides of the dialogue.

You need to have a GND connection between the Mega and the signal system on the right in the diagram

A photo of a simple wiring diagram made with pencil and paper would be clearer even if less artistic. At least one could read the pin labels.

...R

You can open the photo in full size https://i.imgur.com/ExtkqA8.png
Right now they go to separate TX pins, should I change that to the RX pins?
The resistors are there because the guy who made the original has resistors there, maybe not necessary for monitoring though?

But I have GND connection on both of the wires on the right?

joq3:
You can open the photo in full size https://i.imgur.com/ExtkqA8.png

You're the guy who wants help. Don't make work for people who are willing to help

But I have GND connection on both of the wires on the right?

That GND is connected to the wrong thing. You need a GND connection between the Arduino and bike's communication system.

...R

Robin2:
You're the guy who wants help. Don't make work for people who are willing to help
That GND is connected to the wrong thing. You need a GND connection between the Arduino and bike's communication system.

...R

Sorry if that sounded rude, I tried my best doing schematic to explain. Did not know the forum downsized it.
And I am very new to this, that's why I have all these dumb questions.

Is there another ground on the Arduino, because the bikes communication system is already connected to the arduinos ground?

joq3:
Is there another ground on the Arduino, because the bikes communication system is already connected to the arduinos ground?

I only made my comment because I did not see that GND connection in your diagram.

...R

I see the GND connection that you say that it isn't. Maybe you are saying in other words to use the GND pin on the external connector that is not connected here? @jog13 is using 4 PINs as original thread, and you are suggesting use also the remaining unused pin for that?

Please, can you give more clarity about that? I'm also interested in doing something similar.

I think that @jog13 and I, we found to the same source here BAFANG BBSxx change settings on the fly (aka 'cop button') and BBSxx communication protocol | Endless Sphere

An with the other contradiction, why don't completely do a "man in the middle" at this time? Without that, we can't know who is saying what, and maybe the direction is important.

shawe:
I see the GND connection that you say that it isn't. Maybe you are saying in other words to use the GND pin on the external connector that is not connected here? @jog13 is using 4 PINs as original thread, and you are suggesting use also the remaining unused pin for that?

You posted the diagram 3 months ago - I have forgotten all about it.

I don't understand what GND pin or what external connector you are talking about. Or what you mean by "the remaining unused pin"

You can always solder wires together if you need several wires going into a single connector.

GND is a more general concept than a set of pins. Every DC voltage is measured between a GND connection (usually the negative connection on a battery) and some other point on the circuit. A voltage cannot be measured unless there is a GND point. It would be like trying to measure a person's height without bring the tape measure down to the floor.

The Arduino detects HIGH or LOW voltages on its I/O pins by reference to the Arduino GND. If you connect a piece of wire from an external circuit to an I/O pin it won't register anything even if there is a huge battery at the other end of the wire. There must also be GND connection associated with the external circuit.

Of course you must ensure that the max voltage between a I/O pin and GND never (even for a microsecond) exceeds 5 volts.

...R