3

The nano is inside of the house, and the pro mini is outside of the house. I want to send/receive text between them. The communication will be always nano sending text to mini, and then mini sending text to pro in response. There will be no case where mini sends text on its own first.

The line has three wires, but since I have to power the mini with that line, one is used for VCC and another is used for ground, leaving only one wire free. It this case, can I do UART communication between the two? If so, how should I connect the wire to them (including the ground)? And on the software side, how should I handle the communication? Could you give a simple code example in which nano sends "Hello" to pro mini, and then pro mini, after receiving "hello", sends "World" to nano?

enter image description here

4
  • The main question is the distance and the desired connection speed. You can use, for example, even two-core cable for power and some HF-modulation magic for data. Or, you can use wires only for power and use some radio (i.e., WiFi) for data. The radio solution is more simple and cost-effective, because it is pretty common.
    – gbg
    Sep 4 '21 at 15:07
  • 4
    pjon.org/SoftwareBitBang.php
    – jsotola
    Sep 4 '21 at 15:44
  • 2
    What you want is called half-duplex. A search turned up a bunch of good articles: forum.arduino.cc/t/… and nerdralph.blogspot.com/2014/01/… You'll have to devise some handshaking so each side knows when the other is done transmitting. Have fun!
    – aMike
    Sep 5 '21 at 2:07
  • You can use that kind of "Ethernet protocol" that was used on coaxial cable ? Or used with " high frequency modem" ? Or more simple, a "circuit coupler" as in old "line telephony" ?
    – Antonio51
    Sep 6 '21 at 11:02
5

You can have bidirectional communication over a single wire by using open-collector outputs. For this, you could add a circuit like this on each side of the link:

schematic

simulate this circuit – Schematic created using CircuitLab

Here, TX is the transmit pin of the Arduino, and DATA is the data wire. The RX pin is connected directly to the data wire and, while writing your sketches, you should account for the fact that anything you send will be received back by the sender as an “echo”.

This scheme will slow down your signal transitions, limiting the maximum achievable baud rate. Start with something conservative, like 9600 bps, and lower further if it doesn't work reliably.

2
  • The "TX pin on Arduino" means the "TX1 - UART -Out" of Nano and the "RX pin" means the "RX --- 0" of Pro Mini, on the diagram above? Or is it ignoring the UART feature of Arduino completely, and use a reuglar digital output pin instead? Sep 5 '21 at 10:48
  • @DamnVegetables: This assumes you are using the hardware UART, and thus the corresponding pins. On the Nano, those pins are labeled TX1 and RX0. On the Pro Mini, they are labeled TXO and RXI. Sep 5 '21 at 12:13
3

This question likely suffers from the X Y problem. Where the question (about software) and possible answer (centered on hardware) do not approach the solution using the same methods.

The question is essentially asking how to design a 1-wire interface over longer than normal distances. There are 1-wire Arduino libraries and 1-wire Arduino tutorials. But it is likely you will run into problems if your cable is very long.

Guessing at the distance you want to run your 3 wires (power, ground and data), this may be more an electrical engineering than a software problem.

Power:

All wires have resistance. Using a voltage drop calculator from here we can calculate, assuming we are trying to send 5V over an 18 AWG copper wire 100 meters long to a 250mA load, an expected voltage drop of slightly over a volt. That may cause unexpected results.

enter image description here

If this might be an issue, consider an alternate power source such as batteries, solar power or a second mains power adapter for the far Arduino. It may even be considered to over drive the power lines several volts and regulate the voltage at the far end Arduino.

Data:

Reference to ground type data transmission is more susceptible to error the longer the cable run. Several options to mitigating unexpected behavior can be made. However switching over to a balanced pair is usually the best option.

Options:

If you are willing to power the far Arduino independently or add 1 additional data wire (either of these options will make available 2 wires for data) we can run the data portion of the cable for a good distance while mitigating noise problems associated with long communication cable runs.

Try RS485:

Consider using an RS485 hardware interface at the near and far Arduino. RS485 interfaces can be source easily for Arduino projects (here and here are two examples) and there are Arduino RS485 software libraries which handle the communications.

The intent of the project was not disclosed in the question. However here is an example RS485 project where connected Arduinos communicate the position of a potentiometer such that the RS485 connected Arduino at the far end can mimic the potentiometer's movements on a motor driven servo.

The keen eye may note that the above project only uses 2 wires between the two Arduinos. This is possible because in the above project the two Arduinos are independently powered (this is not seen in the diagram on the linked to web page). Additionally, RS485 uses a balanced pair of signals (the 2 wires) and does not need to run an additional ground between the two Arduinos as a reference to detect the difference between 1s and 0s.

7
  • 2
    This might be an XY problem and there might be a hardware solution, but if the question is "how can I make this work with 3 wires" the answer "just use 4 wires" is not helpful. Most likely the cable is already there. If punching through walls to hook up an Arduino would be acceptable OP wouldn't ask the question.
    – AndreKR
    Sep 5 '21 at 1:41
  • @AndreKR Yeah, the cable has already been installed (I did), and at that time, I thought I would not need bi-directional communication and 3-core cable was cheaper than 4-core cable, so I chose the former. Now, after using the system, I realised that I need a way to get the status of the remote device. I could remove the old one and install a new cable (not impossible), but it will be such a hassle, so I was looking for a way to do it with the existing wire. Sep 5 '21 at 10:53
  • Thanks. Replacing the existing 3-core cable with a 4-core cable is not impossible, but I thought if I had two free wires available for data, I could just connect two Arduino's directly using the TX/RX pins already there. You mean that using RS485 needs two free wires (other than the two for powering the remote Arduino), right? The distance is about 30 metres (=100 feet), and I do not need fast communication (even 100 bps is more than enough). The module called "TTL to RS485" seem cheap. Do you think it is better than direct connection even in my case? Sep 5 '21 at 11:33
  • @AndreKR, at the end of my answer was a 2 wire solution. It will only work if the remote was powered by some other meas then by cable. And RS485 will almost always out preform a return to ground reference signal. Time and time again people who do not know that try to extend I2C and SPI only to find they can not live w/the noise. I'll amend my answer and explain this more clearly.
    – st2000
    Sep 5 '21 at 12:47
  • @DamnVegetables, FYI, you are essentially asking how to design a 1-wire interface over longer than normal distances. I could have just said that in my answer and point you to Arduino tutorials and libraires. But it is likely you will run into problems if your cable is too long. Actually, I think I'm going to put the above in my answer. But, just to help us create a better answer ... just how long is your cable?
    – st2000
    Sep 5 '21 at 14:43
1

An example of protocol using a single wire (besides ground, so a total of 2) for both bi-directional communication AND power: Dallas 1-wire

There are few other similar standard protocols and you are free to think about your own as long as you are willing to implement all the internals instead of using a well-written and widely used library.

2
  • While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Sep 5 '21 at 11:41
  • will it work on 30 meters long cable?
    – Juraj
    Sep 5 '21 at 15:03
1

You could do it by using one wire for ground, one wire for nano->mini, and one wire for mini->nano. The nano->mini wire carries both power and data. You can keep it at some voltage above ground to provide the power and superimpose a data signal that is AC coupled off at the mini end. Alternately, you can rectify the data to provide power if you make sure to send 01010101 whenever you don't have something else to say.

1
  • 1
    Note that an UART idles high. Sep 5 '21 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.