I can't quite figure this one out

I have a working project using the Arduino Mega 2560. I receive serial input on serial1 from a device that sends me ASCII data. When I have my laptop connected via serial, I can monitor the data received using serial.print to the serial monitor. I can see the Rx LED flashing as the data comes in and is sent to the serial monitor.
However, under normal operation I don't have the USB cable connected to the laptop, so there is no data being sent to the serial monitor. I power the Arduino with the auxiliary power input. As I developed this project I used the flashing Tx LED as a sign that my data was coming in just fine. So, as a sign of good operation, I'd like to duplicate that Tx LED flashing as a sign that the incoming data is coming in. This I would like to do with an external LED that I would flash at the same rate as the Tx LED would. That external LED would be connected to another output pin, and would become part of the operating circuit. Can anyone tell me how I can do this in code to pin 3, for example.

The TX led should be flashing regardless of the USB connection. You are sending on Serial0

The Arduino doesn't know or care whether anything is listening. I would expect that the LED will flash anyway.

Ninja'd by Deva_Rishi.

1 Like

Since the USB cable isn't connected, there is no serial0 connection, so no LED is flashing with the Input received on serial1. But I know that I'm receiving data because I record everything with a microSD card. When I view the data after the fact, I can see it, but I'd like to be able to see this flashing at a glance, to know that my data is being received.

Please format Your code in the IDE and post it here using code tags, the </> symbol.
Calling a function that blinks an LED at every Serial1.print is easy.

Just hook up an external LED (and current limiting resistor) to pin 1 (Serial TX line) and it should blink regardless of whether or not the USB is connected.

Will downloading code using USB work with that load?

Should not affect the TX line to the USB interface as long as the LED is not overloading the output and preventing it from producing a valid HIGH or LOW output. No affect at all on the RX line from the USB interface to the atmega2560 because there is no reason to put an LED on the RX line - when the USB is disconnected there should never be a serial signal on RX.

You're perfectly right. Limiting the current to the LED to some 5 - 10 mA gives a good margin. My mistake.....

The regular flashing of the TX LED is done with the ATMEGA16U2 on an official MEGA2560 or a good clone. This processor blinks the LED once every two bytes, which is 20 times slower than the bits on the TX line. If the USB cable is not connected, I imagine the ATMEGA16U2 firmware isn't accepting any serial input and thus isn't blinking its LED. If you just attach an LED on the TX line, even with proper current limiting resistor, you will be disappointed to see the LED doesn't actually blink unless you send data in a certain way that causes blinking. You will see the LED turn off, then back on, stay on until the next data batch is sent, when it turns off briefly during the sending. If your baud rate is low, then you could see blink. To replicate the effect, you may have to add code to HardwareSerial::write().

If you wire the LED to ground instead of +5, then it would turn on briefly while data is being sent, possibly enough to see that there is some activity.

Would be fairly easy to just toggle the state of a pin every time a line of data was received from Serial1, that should give enough of a status indication to be useful.

You could add one in line with the serial data to to SD card

The Serial0 does exist and is connected, but after some testing i can confirm that the TX-led actually depends on the USB port.
In that case i suggest you use the builtin LED on pin 13, and toggle it's state every so many bytes depending on the baud rate you are using.

Hi, @sdingman
if you are going to connect an LED directly to the TX, don't forget a series current limit resistor.

Tom.. :smiley: :+1: :coffee: :australia:

I have found a solution that works for me. I parallel connected the Rx of Serial1 to a 10k resistor to the Base of a NPN transistor. I connected 5 v to the Collector and connected the Emitter to 320 ohm resistor in series with a clear LED to GND. If flickers when data is coming in. Done

Hi,
Can you post a circuit diagram of your working project please.
It will help anyone looking at this thread for help.

Thanks.. Tom... :smiley: :+1: :coffee: :australia: