I usually use Aliexpress as my first choice for DIY parts and I bought there Arduino Mega 2560 clone. My plan was to use it with the RFlink software to receive 433 MHz signals (and who knows - maybe send them). It was mostly for temperature and humidity sensors which readings then would be fed to OpenHab. Unfortunately I missed the information that this particular clone was equipped with CH341 serial to USB chip instead of the usual Atmega 16u2. And that was bad news because it is known for its issues with drivers and quality in general. For me it was disconnecting the serial port all the time and when I tried flashing it I was got following error message:
avrdude: stk500v2_ReceiveMessage(): timeout avrdude: safemode: Verify error - unable to read hfuse properly. Programmer may not be reliable. avrdude: safemode: To protect your AVR the programming will be aborted avrdude: stk500v2_ReceiveMessage(): timeout
It was still misbehaving even if I changed USB ports or boooted into Windows. Thankfuly I had USB TTL serial converter based on PL2303 lying around. So I hooked it up this way (I created Fritzing diagram but a table seems to be much more readable):
|USB TTL||Arduino Mega 2560|
Now I had stable serial connection and tried flashing again and it worked flawlessly. Here is how to do it using Ubuntu 17.10 environment which has
avrdude in official repositories. Start by installing it:
apt-get install avrdude
Then download the latest RFlink software, unpack it somewhere and change to the directory containing RFLink.cpp.hex file. After that you can flash your device (please note that you might need to change
/dev/ttyUSB0 to something used on your system, you can use
dmesg to find out):
avrdude -v -p atmega2560 -c stk500 -P /dev/ttyUSB0 -b 115200 -D -U flash:w:RFLink.cpp.hex:i -F
Because we are using TX/RX lines directly there is nothing that could reset the Arduino to put into the flashing mode when required. You need to do it manually at some point after starting the process. I usually push the reset button after avrdude prints the message
Overriding Baud Rate but YMMV.
Please note that I added
-F switch at the end of
avrdude command. It was because my Mega came with incorrect Device Signature set to some random hex (
0x303030 if I remember correctly). Using
-F forces it to flash it anyway and after that device should have the proper ID -
0x1e9801. On the next flashing the
-F should be no longer necessary.
And next time - do buy Atmega 16u2 based Arduino Mega 2560. It is just two bucks more. It can be recognized by additional set of ICSP pins in the top left corner (near the USB port). It is clearly visible on a picture in Official Arduino Store. If n doubt always ask the seller.