Moteino and two Serial connections

Started by d00m178, February 04, 2017, 08:14:41 AM

d00m178

Hello,

I have Moteino R4 and USB FTDI adapter for programming this MCU and debugging code via Serial Terminal.
Usually device works without FTDI adapter connected, but I often connect adapter to MCU for debugging and watch what is happened on Serial output.

I need connect to this MCU second device (laser distance sensor) which uses UART port to communicate with MCU.
And I need use it simultaneously with FTDI adapter.
This device needs to connect RX and TX pins on MCU and it will do (not often) some measurement and send result via UART to Serial port MCU.
I want to see this data in Serial Terminal via FTDI adapter.
How can I connect TWO devices to ONE UART on MCU?
Is it possible?

perky

#1
Do you just want the terminal just to display what the MCU is sending to the laser and what the laser device is replying with, and you're not using the terminal to send anything? You can do this with a pair of schottky diodes and a pull-up. This allows both the MCU's TX and laser's TX to drive the terminal's RX, while still allowing the MCU to send commands to the laser device and get back the reply.

Mark.

                   10k
   3V3 ------/\/\/\/\------+-------- TERMINAL_RX
                                   |
MCU_TX -----+--|<|----+-----|>|------+
                    |                                   |
                    +---------- LASER_RX     |
                                                        |
MCU_RX ---------------------------------+---- LASER_TX

d00m178

Thank you!

I suppose TERMINAL_RX it is RX on the FTDI adapter?
For only watching the data exchanging it will be useful.
The MCU will send request to laser and receive answer and for debugging purposes I need to see this answer in Serial Terminal on my laptop

But I definitely will need re-programming MCU, so probably I can just connect only FTDI adapter to MCU without laser and this circuit, write the new FW and after that again connect laser via this circuit.

perky


d00m178

QuoteDo you just want the terminal just to display what the MCU is sending to the laser and what the laser device is replying with, and you're not using the terminal to send anything?

I just noticed that I need send command via Serial to laser module to start measurement - first send capital char "O" to open laser and the send "D" to measure distance.
It successfully works when I connect laser module to FTDI adapter directly.

But I need get results of measurement into program code, another words - I want send this command via FTDI adapter connected to Moteino and this command should get to laser module connected to Moteino UART..
Is it possible?

perky

#5
It is possible for the MCU to send to the laser and the FTDI, the FTDI to send to the laser and the MCU, and the laser to send to the FTDI and the MCU. This will give you the best of all worlds, you could use the terminal to initate commands, see the results on the terminal and also use the MCU to capture the results, and when the terminal is not fitted use the MCU to initiate commands and get the results. The circuit is a little more complex, but based on the same principle of using two schottky diodes as a 'wired OR' arrangement. See attached schematic.

Mark.

Edit: This will also allow you to plug in a FTDI header and 'snoop' on the packets being sent rom the MCU to the laser and the reply packets coming back, that'll be handy for debugging ;)

d00m178

#6
Thank you!

I successfully solved my task using SoftwareSerial module.
https://www.arduino.cc/en/Reference/softwareSerial

I connected RX and TX to 3 and 5 digital pins and added several strings from example in my program code and everything works as expected )