I'm working on a project that requires two Arduino boards, one is an UNO and the other is a MEGA. The MEGA board has an LCD connected via an I2C backpack to pins 20 and 21. The code is not relevant because the issue happens regardless of the code.
The two are connected as follows in a standard way to connect two boards to send and receive data to each other:
The Serial TX from the MEGA is connected to Serial RX on the UNO.
The Serial RX (pin 10, software serial) from the MEGA is connected to the Serial TX on the UNO.
Ground to ground between the two boards.
With just the TX on the MEGA to the RX on the UNO, if the MEGA's USB is disconnected the LCD powers off as expected.
However, with both the RX and TX pins connected between the two, when the USB is removed from the MEGA and the UNO is still powered on the LCD backlight on the MEGA stays dimly lit.
What could be causing this and how can it be resolved?
Im not and expert, but I would guess that the serial communcation is leaving trace amounts of power to the UNO, which might power it. Can I see a picture?
Disconnect the serial interface and it will go off. You are backfeeding power through the serial port, that in turn is being applied via the input protection devices of the processor to VCC, that in turn is powering the LCD. This is not a good thing and can damage either or both of the Arduinos. You can put a resistor in the lines, try 10K maybe lower, not sure. That will protect the Arduinos but may still allow some glow.
Pullup resistor on the Rx pin of the receiving Arduino, with the Tx line of the sending Arduino connected through a diode, so that the Tx line only pulls the line down to ground, and the pullup resistor pulls it high. Internal pullup should work ok.
Generally, it is a bad idea to have two Arduinos without also powering them from the same source, so that you avoid having one phantom power the other.
Your serial connection between the two boards is nowhere near standard. Using Tx on one port and Rx on another is unusual, and there is rarely a good reason for using SoftwareSerial on a Mega, which as four hardware serial ports (one being used for the USB Serial).
Please explain. The only reason I can think of is distance.
Using more than one Arduino can result in more problems, like phantom-powering, as you have found out.
On an Uno you should use SoftwareSerial on different pins, not 0 or 1.
Why use SoftwareSerial when a Mega has three spare hardware serial ports.
With a direct connection you should also include power (5volt) and ground.
If you don't, then the boards will try to power each other through the I/O pins (phantom-powering), which could will eventually damage the pins.
If you must turn the LCD off, then do it with code.
Leo..
Please explain. The only reason I can think of is distance. Using more than one Arduino can result in more problems, like phantom-powering, as you have found out.
The reason I'm using two boards is that the UNO is running GRBL through a CNC shield and has zero resources left. The MEGA is reading and sending GRBL code and commands to the UNO.
On an Uno you should use SoftwareSerial on different pins, not 0 or 1.
As I mentioned earlier there is nothing left on the UNO to run anything else and GRBL sends and receives commands through the default serial on the UNO.
Why use SoftwareSerial when a Mega has three spare hardware serial ports.
I am migrating code from an UNO (has no other serial ports) to the MEGA. The code is fully functional as it is and I'm not too concerned which serial I use at this time.
With a direct connection you should also include power (5volt) and ground.
That I know of there is no issue with running separate power supplies as long as they share a common ground which they do.
If you must turn the LCD off, then do it with code.
OK but I don't see how turning off the LCD will prevent the back feed issue.
I am going to try running the common ground through a relay powered by the MEGA. I think this way once the MEGA is powered off the common ground is disconnected and there is no way for the UNO to back feed into the MEGA.
You should still use hardware serial if available.
There could be.
If they don't start up and shut down at the same time, then you still have the possibility of burning out pins. Just power one Arduino, and power the other one from it.
No need for two supplies.
No, it won't fix phantom-powering.
I just thought you wanted to turn off one of the Arduinos.
Bad idea. That could still phantom-power through the pin protection diodes it if one pin is LOW.
Leo..
Your serial connection between the two boards is nowhere near standard. Using Tx on one port and Rx on another is unusual
Really? Where have you been? It is documented in countless posts everywhere...
How else would the MEGA see what the UNO is sending to the computer and how would the MEGA send commands to the UNO if the RX and TX are not cross connected between them?
I was referring to using a hardware serial port for Tx and a software serial port for Rx.
I have often seen the use of software serial on the mega, but almost always followed by someone questioning why when there are three hardware serial ports available and not being taken advantage of - software serial has some significant limitations.
I agree with what you are saying about the software serial on the MEGA but the reason is that I am in the middle of combining parts of three sketches I wrote and was testing originally on an UNO and since it is functioning it is not something I've decided to clean up yet and am instead concentrating on solving this issue first.
Instead of the relay to cut GND between the two boards I think I'll try this first.
The idea is that both boards power down at the same time and the UNO cannot power on from the USB while the MEGA is powered off.
NOTE: Do not use this diagram as it shows Vin power being feed to the USB jack that only accepts 5V. Towards the bottom of this post is the correct wiring diagram.
There is no point posting diagrams when the labels are too fuzzy to read. No, I am not going to spend part of my morning finding Uno and Mega pinout diagrams to figure it out.
Pick up a pen, draw a diagram on paper, take a picture of that and post it.
Vin is intended as the input to the on-board voltage regulator, and needs to be at least 7 volts or so to work properly. When powering from a regulated 5 volt source (USB would be regulated in this case), it would be better to connect to the 5V pins of the UNO and Mega.
I was just making an adaptor that goes between the PC USB cable and the UNO's USB jack when I realized what you just pointed out. Thank you for keeping an eye out.
NOTE: After testing, the USB cable does not need the red 5V cable connected to anything for it to send and receive data through the USB cable between the PC and the board.
I don't see how the Mega gets powered when the Uno is on USB.
It could even go backwards through the Uno's 5volt regulator (back-powering == bad).
12volt is borderline. You can't draw more than ~100mA from the Uno/Mega before the regulator shuts down (if you're lucky).
I advised you to share 5volt and ground (post#7).
Adding that V-in connection could be ok, but the 5volt regulators on both boards would be fighting each other. One of them would do most of the work, and they still could shut down under >150mA load.
Leo..