Custom Arduino board - how to load code? - Page 1
Forum section: electronics / beginners

author: Saimoun
author_rank: Frequent Contributor
timestamp: December 13, 2023, 12:50:52 pm
content: HiI'm looking to make a custom arduino board - i.e. a PCB with an atmega328p on it (same as arduino nano).The MCU will come raw without anything on it, is there a way to install the arduino bootloader (or an arduino sketch) simply using a USB cable and a computer*?Thank youEDIT:*ideally without a programmer or another arduino

author: themadhippy
author_rank: Super Contributor
timestamp: December 13, 2023, 01:07:55 pm
content: Easiest way of ive found for getting the bootloader on is to use another arduino,and for loading a sketch a ftdi cable as your bare chip dosnt have a usb input.Take a look athttp://www.gammon.com.au/forum/?id=11637for an easy to follow guide.

author: coromonadalix
author_rank: Super Contributor
timestamp: December 13, 2023, 01:13:14 pm
content: arduino ide can select many programming interfaces ie stk500 avrisp etc ....

author: Saimoun
author_rank: Frequent Contributor
timestamp: December 13, 2023, 01:17:21 pm
content: Understood, and thanks for the replies.Quote from: coromonadalix on December 13, 2023, 01:13:14 pmI'm not familiar with these, are they physical programmers?I guess my question is: is there a way to have a chip on the board which could do the work of a programmer (without programming that chip), so that the end-user can simply use a USB cable between the computer and the board?

author: pcprogrammer
author_rank: Super Contributor
timestamp: December 13, 2023, 01:40:23 pm
content: Take a look at this site:https://www.fischl.de/usbasp/They use another ATmega mcu to do the programming of the target. The USB is bit banged so only low speed can be reached.The programming of the target is done via the SPI port. No boot loader needed in the target.

author: bingo600
author_rank: Super Contributor
timestamp: December 13, 2023, 02:36:03 pm
content: Quote from: Saimoun on December 13, 2023, 12:50:52 pmNOUnless you buy a KAZILLION devices, and can get the factory to install a bootloader for you.A RAW M328 would need to be ISP programmed, in order to install the boot loader.And even then, the end user would need a USB->TTL serial adapter, in order to "talk serial TTL" to the installed boot loader.Doing the USBASP trick, could be feasible but would require another avr on the board as programmer.If you switched to a MEGA32U4 (Arduino leonardo) with builtin USB , it seems like you could use DFU (USB) programming directly on a RAW chiphttps://ww1.microchip.com/downloads/en/DeviceDoc/doc7618.pdfSee the DS for info./Bingo

author: themadhippy
author_rank: Super Contributor
timestamp: December 13, 2023, 03:07:20 pm
content: Quoteno need to buy a kazillion,plenty of places will sell you a single 328 off the shelf with the bootloader already burnt.

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2023, 03:32:26 pm
content: Not strictly true - Many FTDI USB serial bridge ICs can be used in bitbang mode as AVR ISP programmers. e.g.https://learn.adafruit.com/ftdi-friend/programming-blank-avrs. However its as slow as treacle due to limitations of the USB protocol, but adequate for getting a bootloader onto the MCU.

author: Saimoun
author_rank: Frequent Contributor
timestamp: December 13, 2023, 10:33:48 pm
content: Quote from: bingo600 on December 13, 2023, 02:36:03 pmOh nice, this sounds exactly like what I am after! Thank youCan these chip be programmed straight from the factory (no pre-programming done) using the Arduino software or will I need to use AVRdude and similar?And I guess there are a few pins to pull up/down at startup to get it to start in DFU?

author: Shay
author_rank: Regular Contributor
timestamp: December 13, 2023, 10:46:39 pm
content: Personally I just ordered ATmega328P with Arduino bootloader already flashed. They cost next to nothing and work great in my experience. I got them from eBay.You can plug one into Arduino uno, flash, and insert it into your PCB. Or you can use additional Arduino or buy an ICP programmer off AliExpress to flash .hex file.

author: Saimoun
author_rank: Frequent Contributor
timestamp: December 14, 2023, 12:41:11 pm
content: Thank you Shay for the ideaBut honestly I have never liked the AVR world, I also know very little about it, and the only reason I would consider an atmega is to make an Arduino-compatible board.I tried looking up how to program the atmega32u4 over the USB and it does not seem simple, I could not find any simple tutorial on the net (something like "here is how you upload the first code onto a clear atmega32u4 over USB"). In fact I'm not even sure it is possible since it seems to set the fuse which will get the chip to boot on the USB bootloader, you need an ISP anyways(then what's the point of having the USB bootloader if you need an ISP to use it... Maybe I missed something there?)Anyways - I might go for an ESP32 instead, they're actually cheaper, so much more powerful, and I think they are compatible with the Arduino IDE / code as well?

author: darkspr1te
author_rank: Frequent Contributor
timestamp: December 14, 2023, 02:12:14 pm
content: Quote from: Saimoun onTodayat 02:41:11 pmYou short out the dfu boot pin, plug into USB , run dfu-programmer with your compiled hex file from what ever ide you choose, in arduino ide you choose dfu mode to flash your code.https://dfu-programmer.github.io/]http://https://dfu-programmer.github.io/There are many other Arduino boards that are not atmel btw, I personally use a lot of stm32 myself and also really enjoy the Pi Pico rp2040 for it's flexability, but if i want 5v compatibility i reach for a atmel chip as i have a fewdarkspr1te

author: Saimoun
author_rank: Frequent Contributor
timestamp: December 18, 2023, 08:12:40 am
content: Quote from: darkspr1te on December 14, 2023, 02:12:14 pmAmazing!!Thank you!Have I understood correctly that the Arduino IDE can upload straight to the USB bootloader (dfu-mode)? Or is that only after having loaded the Arduino bootloader?And is there a pre-compiled hex file of the arduino bootloader somewhere?