Hi, i'm pretty new at this, so if this post is wrong placed or something, pls tell me right away.
I have an Arduino Mega 2560 that I want to programm through an ESP 8266. It works just fine, thank you to ESP LINK (you can find it in GitHub), but I need to attach a RaspberryPi too, so the USB serial port that also connects through RX0 and TX0 is going to be occupated.
Is any way to programm Arduino through some of his other serial ports like RX1 TX1 or RX2 TX2? If it exists, can someway give me some guidance?
Yes it's possible. You will need an ISP programmer. If you don't have a dedicated programmer you can use an extra Arduino board as an "Arduino as ISP" programmer. I believe it's possible to use the ESP8266 for this purpose using ESP8266AVRISP (available via File > Examples > ESP8266AVRISP > Arduino_Wifi_AVRISP when you have an ESP8266 board selected from the Tools > Board menu) but you'd need to do some research on that because I have no experience with that.
Navigate up four folder levels until you reach the folder that contains the file boards.txt.
Open boards.txt in a text editor.
Change line 185 from:
2560.menu.clock.16MHz_external.upload.port=UART0
to:
2560.menu.clock.16MHz_external.upload.port=UART1
(That is for uploading to Serial1. If you prefer a different port then adjust the above instructions accordingly.)
Save the file
Close all Arduino IDE windows
Restart the Arduino IDE
Connect the ISP programmer to your Mega.
Plug the ISP programmer in to your computer.
Tools > Programmer > select the appropriate selection for your programmer
Tools > Burn Bootloader
Note that you will no longer be able to upload to your Mega via the USB serial port (Serial0) after doing this. You can always repeat the above instructions to change the port or just select Tools > Board > Arduino/Genuino Mega or Mega 2560 and then do a Burn Bootloader.
Is any way to programm Arduino through some of his other serial ports like RX1 TX1 or RX2 TX2? If it exists, can someway give me some guidance?
Yes, this is possible but it needs a fair amount of learning and time to do the programming.
You can adjust the bootloader of the Mega2560 to use another serial port than the first one. The bootloader source code can be found in the following subdirectory of your IDE installation:
hardware/arduino/avr/bootloaders/stk500v2/
You might have to adapt some paths in the Makefile to match your installation. Changing the source code to use another serial interface is not too complicated but needs knowledge about the datasheet of the ATmega2560. Adapting the bootloader to listen to more than one serial interface should be possible to but need far more changes to the existing code and indepth knowledge of the AVR startup process as you might have to adapt the bootloader size.
The Optiboot bootloader allows you to easily compile for any serial port without any modifications to the code. There is a fork of the Optiboot bootloader that supports ATmega2560. So if you really want to compile a bootloader to use a different serial port on ATmega2560 for upload it can very easily be done. That is exactly what has already been done for you in MegaCore.
Compiling the stock Mega bootloader will definitely be more challenging, but why bother when optiboot is so much better?