Hi @sagarsaini. Thanks for sharing your findings!
https://www.hackster.io/sainisagar7294/arduino-ch340g-troubleshooting-fixing-errors-and-drivers-4f5eaf#toc-solving-troubleshooting-after-installing-drivers--software-troubleshooting-1
So, I tried to upload sketch again and failed. After searching more in datasheets and web pages the same thing is given as before.
After some days, I got an idea to burn Arduino Uno bootloader in NANO. So, I connected Nano with my Arduino UNO using this schematic and burn bootloader. And this thing solved my problem, Here I am using Arduino UNO bootloader in NANO. I am very happy and curious to know why this thing is not work with NANO board directly.
The classic Nano (as well as its 3rd party derivatives) have been manufactured with two different types of bootloader installed. Originally a bootloader named "ATmegaBOOT" was used. There is a bug in this bootloader that causes it to go into an endless reset loop after a watchdog reset. So in 2018 Arduino switched to installing the excellent Optiboot bootloader (which had already been in use on the Uno boards for years) when manufacturing the official Nano boards. The two bootloader have different configurations so the upload parameters that work for one don't work for another. For this reason, Arduino added a ATmega328P (Old Bootloader) item to Arduino IDE's Tools > Processor menu for the Arduino Nano board definition. Those using a board with the "ATmegaBOOT" bootloader must select Tools > Processor > ATmega328P (Old Bootloader) from the menu and those using a board with the Optiboot bootloader must select Tools > Processor > ATmega328P (the default value).
Even though it has now been 6.5 years since the bootloader change, some of the manufacturers of the cheap Chinese derivatives like your "Nano" never bothered to make the change and so still ship boards with the "ATmegaBOOT" bootloader installed. My guess is that you got one of those boards and the upload failed because you had Tools > Processor > ATmega328P selected from the Arduino IDE menus.
So you could have fixed the problem very easily by selecting Tools > Processor > ATmega328P (Old Bootloader).
I wouldn't recommend your solution to the average beginner because they tend to find it very challenging to accomplish a successful "Burn Bootloader" operation, and they often don't have the required hardware on hand.
However, you pulled it off and definitely are better off for it in the end. Optiboot is a superior bootloader. In addition you reaped even greater benefits by selecting Tools > Board > Arduino AVR Boards > Arduino Uno from the Arduino IDE menus before performing the "Burn Bootloader" operation. Unlike "ATmegaBOOT", which requires a 2 kB boot section be reserved in the microcontroller's flash memory, Optiboot fits in a 0.5 kB boot section. The "Arduino Uno" board board definition was correctly configured to only reserve a 0.5 kB section](ArduinoCore-avr/boards.txt at 1.8.6 · arduino/ArduinoCore-avr · GitHub). However, the Nano board definition was configured to unnecessarily reserve 2 kB. This means that using the configuration from the "Arduino Uno" board definition gives you an extra 1.5 kB of precious flash memory for your sketch program!
https://www.hackster.io/sainisagar7294/arduino-ch340g-troubleshooting-fixing-errors-and-drivers-4f5eaf#toc-solving-troubleshooting-after-installing-drivers--software-troubleshooting-1:~:text=limit%20the%20use%20of%202%20analog%20pins%20i.e%20A6%20and%20A7
Using UNO bootloader inside NANO board will limit the use of 2 analog pins i.e A6 and A7. Because smd package of 328P MCU has 2 extra analog pins.
This is false information. The bootloader doesn't have anything to do with the ADC capabilities of the board. In fact you can use A6 and A7 without any problems at all. Please correct this misinformation in your hackster.io project.
There is one difference. When you compile with Tools > Board > Arduino AVR Boards > Arduino Uno selected from the Arduino IDE menus, the NUM_ANALOG_INPUTS
macro is set to 6
:
When you compile with Tools > Board > Arduino AVR Boards > Arduino Nano selected from the Arduino IDE menus, the macro is set to 8
:
However NUM_ANALOG_INPUTS
is not used anywhere in the core or any of the official Arduino libraries and I have found almost no usage of it in 3rd party projects. So it is unlikely you would ever experience any problems caused by it being set to 6
.
https://www.hackster.io/sainisagar7294/arduino-ch340g-troubleshooting-fixing-errors-and-drivers-4f5eaf#toc-my-own-usb-to-serial-programmer-4
I searched for the schematics of ch340 and made my own Usb to serial programmer.
I strongly recommend you redesign your PCB to use the standard "FTDI header" pinout:
- DTR or RTS
- RX
- TX
- VCC
- CTS
- GND
That will allow you to plug the adapter right in to boards that use this standard pinout such as the Arduino Pro Mini:
📷
51eec3b1ce395f4b4b000000.png by SparkFun - CC BY-SA 4.0
Adapters that use non-standard pinout force the users to use a mess of jumper wires to adapt it to the standard pinout.