if it requires seperate programing of the atmega16u2,
It does. Often an ATMega8U2 is used here instead though.
i'd like to know how.
You might start by having a look at HoodLoader2 and NicoHood's related projects.
This involves replacing the normal Xu2 transceiver firmware with HoodLoader. There are different ways to do that outlined in the installation instructions. If you don't have an ISP programmer or a second Arduino to behave as one, there's a method that involved burning an installer-sketch to the 328P which turns around and reprograms the Xu2 chip.
Once you have that done you can use their board definitions for put sketches onto the ATMegaXU2 itself.
Apparently, JP2's layout is flipped on some boards. So, beware of that. In any case, the header it makes the ATMegaXU2's PB4, PB4, PB6, and PB7 available. Sketches on the XU2 would use the Hoodloader pin mapping of these:
Arduino Pin No. |
AVR GPIO PIN |
D4 |
PB4 |
D5 |
PB5 |
D6 |
PB6 |
D7 |
PB7 |
Or course, now you need to find some way to coordinate what happens on the ATMegaXU2 with the ATMega328P.
i find my arduino has less pins and jp2 are the only ones left.
There are clever ways to reuse pins on microcontrollers. For example, it is possible to put an LED and a switch on the same GPIO pin. And there are GPIO expanders, SPI/I2C ADCs, etc.
Messing with JP2 and programming the ATMegaXU2 and having it coordinate with the 328P may be more trouble than you like just to get a couple extra pins.
but if it is not accessable, why do they have it ?
Just added capability. Usually that header is unpopulated, so there's no part cost there.
and also , i completely dunno a thing about atmega16u2 . only thing i understand is that it makes the arduino more compatible with the usb input ...
It serves the role of a USB to logic-level-serial converter for connecting to the USART of the otherwise non-USB-aware ATMega328P (you have tagged UNO). But, it can be made to run sketches. Usually if you're doing this, it's to get native USB support on an UNO (or Mega, or..), e.g. so you can have your board act as a keyboard, like you might with a Leonardo or Micro or any other board that has native-USB in normal use. And that's a large part of what NicoHood's project is about.