-1
\$\begingroup\$

I use ATmel ATmega32U4 in a schematic which copies Arduino Leonardo almost completely. So, Caterina-Leonardo bootloader works fine with it.

Unfortunately, I have run out of all available output pins. So, I wonder whether I can use pin 22 (TXLED, PD5) as additional digital output.

As I understand from many forums and Q&As out there, I have to build custom bootloader. I’ve added my own board to Arduino IDE and built new bootloader from Caterina code (so, the compiler and LUFO libraries work well), but I don’t have a clue how to properly disable TXLED and RXLED signals, in order to use these pins for output correctly (RXLED as the 17-th Leonardo digital pin and TXLED as the 30-th one).

On the other hand, the board uses USB (ATmega32U4 pins of 3 and 4) for communication with the computer (it needs to be a plug-and-play device), sending some data to it, and for uploading new sketch’s versions through Arduino IDE. So I need to use USB functionality and TXLED as an output pin simultaneously. (The output pin doesn’t lead to the computer, just in case).

Can you please tell me, is this issue solvable, and, if yes, how can I get things done? What should I change in the bootloader sources (like caterina.h, caterina.c, descriptors.c etc.)?

Any useful information on that will be highly appreciated.


I spend hours digging bootloader code and different websites but eventually failed. For instance:

Seems like the last guy had the same problem and successfully solved it, but unfortunately he didn’t describe his solution and didn’t attach any source.


Here is my circuit diagram: Here is my circuit diagram
I enabled internal pull-ups in ROW1..ROW4 and want to make them LOW when switch is pressed. It works well with all STRs except the 3rd one. The problem is that STR3 is connected to pin 22 (TXLED).

\$\endgroup\$
  • \$\begingroup\$ Ye, it's solvable. So N people do not have to dig it up, please provide cct diagram of system - relevant parts at least. | As you are making uyour own I assume a SMALL extra amount of hardware is OK. Yes? \$\endgroup\$ – Russell McMahon Jan 18 '17 at 9:38
  • \$\begingroup\$ The thing is I'm trying to fix software for already designed schematic where keyboard matrix is used, and TXLED pin is used for output row from where signal goes through a diode and a switch to some input (column) pin. \$\endgroup\$ – Sasha MaximAL Jan 19 '17 at 6:55
  • 1
    \$\begingroup\$ In that case you really must give us a circuit diagram. \$\endgroup\$ – Russell McMahon Jan 19 '17 at 14:50
  • \$\begingroup\$ I have added the diagram. Thanks for your patience. \$\endgroup\$ – Sasha MaximAL Jan 20 '17 at 20:26
  • 1
    \$\begingroup\$ I'm voting to close this question as off-topic because it has been abandoned for a year and a half during which the asker has ignored pointed requests to explain how the provided responses fail to meet their needs. If the asker refuses to clarify, closure is the only means of putting this to rest. \$\endgroup\$ – Chris Stratton Jun 19 '18 at 1:48
0
\$\begingroup\$

In the Arduino IDE 1.8.1 is the Catarina bootloader at /hardware/arduino/avr/bootloaders/caterina

Open the files Catarina.c and Catarina.h and search for TX_LED and RX_LED, you will see that they are used a lot. When you remove them, you could adapt the LED_SETUP() macro as well, since that macro sets three pins for output (RX, TX, L).

Did you connect AREF to VCC ? That is not okay. When the internal voltage reference is selected it will cause an internal shortcut.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the reply. I cannot remember, maybe I already nulled these macros, like TX_LED() {} and so on. Will try your solution, and write here then. As for AREF, I use analogReference(DEFAULT) in the code, but I’m an ordinary web programmer and am too far away of being an expert of electronics. How should I connect AREF pin in your opinion? \$\endgroup\$ – Sasha MaximAL Jan 21 '17 at 10:11
  • \$\begingroup\$ Connect the AREF pin to 100nF capacitor and that capacitor to GND. Nothing else. It reduces the noise for the voltage reference inside the chip. If you don't use analogRead(), you can omit the capacitor and just leave it open. Clearing those macros should work as well of course. Did we miss something ? As far as I know, only the macros are used to set those pins. Do you use LED_BUILTIN_RX and LED_BUILTIN_TX in your sketch ? You can use them in a normal way with digitalWrite and pinMode with a newer Arduino IDE. \$\endgroup\$ – Jot Jan 21 '17 at 20:20
  • \$\begingroup\$ Sorry, do you mean I should connect it like this? sishot.ru/i/blJYiduSABY5 \$\endgroup\$ – Sasha MaximAL Feb 1 '17 at 14:54
0
\$\begingroup\$

You did not show the whole diagram that is relevant.
How is the TX LED driven?

If TX LED is driven by the pin with a series resistor:

LED circuit can be

  • pin - resistor - LED - ground or

  • pin - LED - resistor - ground

either works equally well in the modification below.

Add any "Jellybean" NPN transistor (BC337 or ....) as Q1

  • Disconnect connection from pin to TX LED circuit
  • Connect pin to Q1 base.
  • Connect Q1 collector to Vcc.
  • Connect Q1 emitter to LED circuit.
  • Drive switch matrix from pin as before.

The transistor acts as and emitter follower and as a buffer for the pin.
Te LED drive will be slightly reduced as now it is being drivem by Vpin-Vbe_Q1 instead of by the pin directly. The resistor size could be somewhat reduced if more brightness is required.

\$\endgroup\$
  • \$\begingroup\$ This is a whole diagram. There are no LEDs on those pins at all. I wanted to use those pins for my switch matrix (as shown on the diagram). TX pin here is 22 (PD5), and RX pin here is 8 (PB0). \$\endgroup\$ – Sasha MaximAL Apr 26 '18 at 11:49
  • 1
    \$\begingroup\$ @SashaMaximAL t's now 15 months since I answered. I need a better explanation of what you want than a few extra words. I could spend much time going over the old material trying to work out what you want and have it wasted by misunderstanding you. YOU need to do the work to bring thngs up to date so we can better help you. \$\endgroup\$ – Russell McMahon Apr 27 '18 at 12:55

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.