Hi Guys,
Instead of uploading the sketch via FTDI headers, I have successfully uploaded the sketch to Moteino boards using programmer. Which utilises ICSPs pins, like Mosi, Miso, SCK, RESET,VCC and GND.
This is great when you just want to send somebody .hex file instead of sending them .ino file.
Now does this overrides the existing boot loader on the device ? Or there is no harm using this option.
Sure you can do that, any harm? Well if you like playing Russian roulette... imagine the possibilities :D
Harm depends how you use the ICSP programmer, it has the power to wipe and lock the device, so use it very carefully. I would avoid using the ICSP programmer unless you really know what you are doing. IOW know exactly how you invoke it, or else it might delete the bootloader. The genuine Moteinos have the bootloader section protected, this is to prevent Arduino IDE or the code itself to overwrite the bootloader. You also need to ensure the hex is correctly compiled and its for your exact MCU variant, or it will not run or do strange things.
Here's my alternative suggestion for your needs (sending hex instead of code):
I would suggest using avrdude (STK500 protocol) to send the hex file over FTDI, which is "much safer" if you use the suggestions below.
This is what ArduinoIDE does after the .ino plain code is compiled into a hex file, it invokes avrdude and sends the hex when you click UPLOAD - avrdude resets the board, which puts the Moteino in bootloader mode waiting for a sketch upload, then sends the hex via STK500 serial protocol so the bootloader can write it in internal flash.
You still need to ensure the hex is correct - for that you simply compile the code for target="Moteino" in Arduino IDE, with verbose output, and you will see the .hex file location in the bottom of the IDE black message box.
There's a nice UI wrapper for avrdude called avrdudess, which makes it really easy to pick your options and even allows you to do other powerful things like changing fuses and writing eeprom etc:
http://blog.zakkemble.net/avrdudess-a-gui-for-avrdude/
Thank you Felix, as always for detailed reply.
Now couple of things here.
1. So far we been using 'Arduino Uno' as target board to upload the sketches to the Moteino boards, and they seems to work all fine. After your reply I have installed 'Moteino' as target board into my Arduino IDE so going forward we use Moteino as target. Did we miss on something using 'UNO' as target for R4/R6 variants for Moteinos ?
2. This is more interesting one, at time if we had to upload the bootloader again to Moteinos, all we been doing is selecting 'UNO' as target and using 'Tools' 'Burn Bootloader' onto Moteino's again, they seems to work all fine.
So question on bootloaders, if we select Moteino as target and burn the Bootloader exactly the same as described in step2 above, would that be all we need to do ? we don't need to set the fuse settings or anything else manually ?
To your questions:
1) Nothing wrong there, the DualOptiboot used on Moteinos is based on and compatible with the Optiboot bootloader. The difference is that it is 1KB in size vs just 512bytes, that is because it has extra functionality to allow OTA ("over the air", wireless programming), actually rewriting the Moteino flash from external 4MBIT chip where the OTA transfer puts the new "sketch".
The atmega 328p flash is 32k so with Dualoptiboot you have 31kb left, you can achieve this maximum space by using the correct Moteino target.
So no harm done in using Optiboot, as long as your sketches are less than 31kb in size.
2) Depends on the programmer used, if you rewrite the bootloader with Optiboot, then you lose the ability to do OTA but gain another 512bytes of available program space.
Either way, on 328p Moteinos (Moteino, MoteinoUSB), using UNO or Moteino as target will work the same in most cases.
I still recommend using the Moteino core since it contains the correct bootloaders and possibly changes/fixes in future releases.