Arduino Leonardo and external ON/RX/TX leds

Hello,

I would like to make simple visualisation of LED´s (ON/RX/TX) state by external LED on my panel.

I will use:
Arduino Leonardo
5mm, 5-9V LED (with resistor of course).

I was not able to find easy how-to. I know that D0 and D1 are marked as RX and TX but am I able to just connect GND - GND and + to RX/TX and be ready to go or I need to also add something into code?

Thank you very much.

No.

For a start you need a resistor in series with any LED.

However the thing that mainly stops you is that on this processor the serial interface to the computer is virtual, that its software makes a USB interface to talk to the computer.

Yes pins 0 &1 carry serial data but only for the Serial1 port. So in order to see anything you will need to send everything to this other port as well.

The TX and RX lines are normally high and you will see nothing as an off blink is hard to spot. So you will have to connect your LED the other way round with it connected to the +ve and the RX pin.

I would use this diode with resistor on it - LED with resistor

For now I am using Arduino just for collecting signals from potentiometers and buttons so this is a bit new for me.

Anyway thanks for info.

Are you wanting to use Serial1 (D0 and D1) to transfer serial data to/from another device or just flash LEDs by writing to Serial1?

That looks fine. What are you going to connect the RX line to? This will only receive signals from what you wire it up to. It will not receive anything from the computer, because you do not have hardware access to that.

I would like to just flash LEDs.
Arduino is covered and I would like to have visual on LEDs so that is why I want to make them external.

In fact, I do not receive anthing from PC to Arduino.. I am just transmiting from Arduino to PC.
This leads me to thing that I only need TX.

Why not blink/flash an LED connected to another pin when you transmit something ?

I think I understad what do you mean, but I have 5 potentiometers and 7 buttons and I would like to see that communication is active and not check every single transmision.
In past I used to have problem with loosing communication - Arduino was ON but TX LED was OFF. So I would like to have this light infront of eyes all the time, atleast for testing.

Put the code that transmits your values in a single function and call the LED flashing code from there when you transmit something.

Of course, the fact that you transmit something does not actually mean that the Serial link is connected

Good idea Bob, thanks.
Not exactly what I was thinking at the beggining, but I think it is good for my needs. Will give it a try.

For the Leonardo the TXLED for serial communications is defined as:
#define TXLED0 PORTD |= (1<<5)
#define TXLED1 PORTD &= ~(1<<5)

If you redefine in your code to:
#define TXLED0 PORTD |= (1<<4)
#define TXLED1 PORTD &= ~(1<<4)

You should be able to connect your LED to D4

I have not tested this.

Correct me if I'm wrong, if you are not configuring Serial1, you can

#define TXLED0 PORTD |= (1<<3)
#define TXLED1 PORTD &= ~(1<<3)

and connect your LED to D1, anode to +5V, cathode to D1.

D0 and D1 are just 2 more available DIO pins unless Serial1 is define.

You can use any pin you want!

This is the code within leonardo pins_arduino.h

#define TX_RX_LED_INIT	DDRD |= (1<<5), DDRB |= (1<<0)
#define TXLED0			PORTD |= (1<<5)
#define TXLED1			PORTD &= ~(1<<5)
#define RXLED0			PORTB |= (1<<0)
#define RXLED1			PORTB &= ~(1<<0)

I believe the first INIT line would need to be modified as well.

I may have time this afternoon to pull out my Leonardo to play around with this. I may have to do the re-direction within a copy of this h file and saved in the sketch folder

That would be super helpful.

Thanks everyone for time and help.

I Failed
I added the below lines to a test code: No Joy
I modified the lines in pins_Arduino.h and saved a copy in its sketchbook: No Joy
Rebooted the IDE and tried again: No Joy
No Joy = tx and rx activity still lights the built in LEDS

#define TX_RX_LED_INIT	DDRD |= (1<<3), DDRD |= (1<<2)
#define TXLED0			PORTD |= (1<<3)
#define TXLED1			PORTD &= ~(1<<3)
#define RXLED0			PORTD |= (1<<2)
#define RXLED1			PORTD &= ~(1<<2)

#define LED_BUILTIN_RX 0 / 17
#define LED_BUILTIN_TX 1 / 30

I'm willing to try any suggestions. Now I want to know how to make this work by modifying h and cpp files for my own personal knowledge.

Changing the macros in the sketch has no effect outside the sketch file(s).
You have to modify/add core files.

This adds RX/TX LEDs menu for Leonardo under Tools.

Add variants/leonardo_rxtxled_01/pins_arduino.h

#include "../leonardo/pins_arduino.h"

#undef TXLED0
#undef TXLED1
#undef RXLED0
#undef RXLED1
#undef TX_RX_LED_INIT

#define TXLED0                  PORTD &= ~(1<<3)
#define TXLED1                  PORTD |= (1<<3)
#define RXLED0                  PORTD &= ~(1<<2)
#define RXLED1                  PORTD |= (1<<2)
#define TX_RX_LED_INIT  DDRD |= ((1<<2) | (1<<3)), TXLED0, RXLED0

#define LED_BUILTIN_RX 0
#define LED_BUILTIN_TX 1

Add boards.local.txt

menu.rxtxleds=RX/TX LEDs

leonardo.menu.rxtxleds.normal=Normal
leonardo.menu.rxtxleds.normal.build.variant=leonardo
leonardo.menu.rxtxleds.pins_0_1=Pins 0 & 1
leonardo.menu.rxtxleds.pins_0_1.build.variant=leonardo_rxtxled_01

Thank you for helping me learn this.

Where do I add boards.local.txt? My boards.h is located in
C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.h

As I previously mentioned you can try this:
Put in your setup()

#undef TXLED0
#undef TXLED1
#define TXLED0 PORTD |= (1<<4)
#define TXLED1 PORTD &= ~(1<<4)

You should be able to connect your LED to D4