When you design a PCB containing a microcontroller you should break out the SPI and Serial pins for bootloader flashing, programming and debugging.
However most of the solutions I have seen are based around rather bulky 2.54mm pin headers -> not always the best idea for tiny projects. So I thought about designing a more compact solution.
The pins relevant for programming are:
ISP: 5V, GND, RST, MISO, MOSI, SCK
Serial: 5V, GND, RX, TX, DTR
Note: the DTR pin is just connected to the RST pin with a 100nF capacitor in series. So the only pins that have to be broken out are:
The only thing needed for this project is a small but easy to handle 8pin connector. I decided to use a surface-mount male JST connector with 1.25mm pin pitch. They can be found on AliExpress for about 10 cents each. You will also need 2 female connectors with wires for the programming adapters.
How to design your board
I design my PCBs using the online designer EasyEDA. To get the footprint for this connector, search for "JST_1.25MM_8P_HAND" under User contributed PCB Libs.
The connector has to be wired to your processor according to this table (Note: pin numbers are for the ATmega328p, for other microcontrollers please check the datasheet/reference designs).
How to solder the programming adapters
First you will need the ISP adapter. This one is used for flashing the bootloader to your microcontroller.
Things needed: 8pin female 1.25mm JST connector with wires, Arduino Pro Mini
Solder the wires on the connector to the pins of the Arduino according to this table:
Insulate the two remaining wires with tape or heat shrink or use a tiny screwdriver to remove them from the connector. Then solder a 6pin header to the serial programming port of the Arduino. Connect it to your PC with a FTDI adapter, open your Arduino IDE, open File > Examples > ArduinoISP and flash this sketch to your Arduino.
Then make the Serial adapter. That one can be used for programming and serial debugging. Note that it'll need a microcontroller with bootloader on it to function.
Things needed: 8pin female 1.25mm JST connector with wires, 6pin male dupont connector / pin header, 100nF capacitor
Solder (or crimp) the wires on the connector to the pin header according to this table:
|5||1 (DTR), with 100nF capacitor in series|
How to flash to bootloader to an ATmega382p
First you will need to add the barebone ATmega328p to your board definitions. To do this open Documents/Arduino/hardware on your PC (if the hardware folder is no present, create it).
Then download the board definitions and unzip them in this folder. You should see the folder atmega containing a folder named avr. This folder contains the bootloader directory and the boards.txt definition file.
Then restart your Arduino IDE. Now you should see the entries ATmega328p (8 MHz internal clock) and ATmega328p (1 MHz internal clock) in your board menu (Tools > Board).
Select one of them depending on the clock speed you want to use. 8MHz is good for most cases, 1MHz ideal for battery powered projects, since it allows the supply voltage to go down to 1.8V. You also need to set the correct programmer type, to do that select Tools > Programmer > Arduino as ISP (NOT ArduinoISP).
Connect your FTDI board to the ISP adapter and plug the JST connector into your selfmade microcontroller board. Then connect the USB cable to your computer. Double check the selected programmer, board, clock speed and serial port, then click on Tools > Burn Bootloader. This will flash the Arduino bootloader to your processor.
If you dont see any error messages you can unplug your board, power it externally and attach a LED beween pin 13 and GND. If it blinks every half second you were successful! Now you can flash any sketch to your processor using the Serial adapter.
How to program/debug your micro
Once you have a bootloader on your processor you can program it just like you would an Arduino Pro Micro (or any other micro board with serial pins). Just attach the Serial adapter to your FTDI board (be careful: the connector is not fool-proof, the lead with the capacitor needs to be connected to the DTR pin). Then plug the JST connector into your board and connect the FTDI board to your computer.
Set your Arduino IDE to the right processor/clock speed/serial port, open the desired sketch and hit the Upload button. Thats it!