4

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

Damn Vegetables
  • 357
  • 1
  • 3
  • 9

4 Answers4

7

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.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
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.

st2000
  • 7,513
  • 2
  • 13
  • 19
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.

fraxinus
  • 111
  • 2
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.