User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Using RPi to flash Arduino bootloader

Sat Mar 11, 2017 4:15 pm

I have been greatly enjoying the expanded capabilities the RPi gets when paired off with a microcontroller or two, but I have hit something of a wall.

I set up a pi with the Arduino IDE and promptly forgot it existed as I compiled programs from the command line and then uploaded them with AVRdude by means of the GPIO pins of the pi and that was fine for chips like the Atmega328p which came with the Arduino boot loader installed.
The problem came when I tried to expand to using the Atmega32a microelectronics that didn't come with a boot loader.
I know there is an Arduino compatible boot loader for the 32a. The issue I have is that I don't have an actual Arduino board, or a usb-serial adaptor and every approach I find to get the boot loader onto a chip requires one or the other. I see frequent vague mention that it can be done entirely with rpi GPIO, but no actual examples of how to do it.

So Can anyone tell me if it is possible, with nothing more than an RPi, some wires, a bread board, and a few resistors to actually flash an Arduino boot loader onto a suitable microcontroller?

Right now I will settle for a yes or no answer just so I can decide whether or not to keep trying or look more into how to program these things without the boot loader at all, which i was going to have to do when I started tinkering with the PIC controllers anyway.
Or maybe I can use a 328 to act as a programmer in place of a full Arduino board <.<
I have made my statement and I stand by it but I could be wrong.

User avatar
DougieLawson
Posts: 35517
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Using RPi to flash Arduino bootloader

Sat Mar 11, 2017 5:32 pm

Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sat Mar 11, 2017 6:25 pm

Not to answer the question of whether the Pi can do this no. It was an interesting read none the less.
It was what I expected to see on the Arduino forums and exactly why I asked here.
Any mention of what was used to load the bootloader was one or another version of Arduino (because that is what the majority there are familiar with and have to hand) and one mention of a specific tool for programming the microcontrollers, (because that is the easy straight forward approach) and both options I was aware of and hoping to avoid, though it would be nice to have an actual Arduino... It could free up a breadboard when putting things together can't say it would be terribly bad to have a dedicated avr programmer either.
I may just have to give up on looking for extra utility in the Pi and get a new tool. Not like it will kill me.


You know, maybe I am looking at this wrong.... I'm not sure I even need a bootloader... isn't it mainly tied to programming through the usb interface?
Since I'm going through the ICSP connection maybe the issue is to do with the fuses not being set. I am fairly sure loading the boot loader is when that usually happens.
Maybe I have been overly specific in my searches. there may be a simpler way to get this working.
I have made my statement and I stand by it but I could be wrong.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sat Mar 11, 2017 9:22 pm

Yup. I'm an idiot.
The bootloader does nothing I need.
a few minutes look about and I have started to divorce myself from arduino entirely.
I got a blink program running without any of the arduous trappings.
I got so fixated on doing what I thought would solve my problem I lost track of what it was I was actually trying to do.
It is amazing how much pleasure I can still get out of seeing a single LED turn on and off again after wasting an entire day trying to figure out how to make it do so the wrong way.
Sadly I wont be using the 32a in place of the 329p any time soon... Kind of depended on a fair few arduino libraries X.x
Now I just need to forget everything I know about Arduino programming and focus on AVR programming <.<
I'm sure I will have I2C and SPI up and running again in no time... ^.^;
I have made my statement and I stand by it but I could be wrong.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Using RPi to flash Arduino bootloader

Sat Mar 11, 2017 10:15 pm

Lost Cause wrote: The problem came when I tried to expand to using the Atmega32a microelectronics that didn't come with a boot loader.
I know there is an Arduino compatible boot loader for the 32a. The issue I have is that I don't have an actual Arduino board, or a usb-serial adaptor and every approach I find to get the boot loader onto a chip requires one or the other. I see frequent vague mention that it can be done entirely with rpi GPIO, but no actual examples of how to do it.

So Can anyone tell me if it is possible, with nothing more than an RPi, some wires, a bread board, and a few resistors to actually flash an Arduino boot loader onto a suitable microcontroller?
It should be possible, you might need a special version of avrdude with the right options (this might mean compiling it from source).

I used a Pi several years ago to program atmega chips with no bootloader, putting a bootloader on should only be a variation on that process. I don't think I have any notes on what I did for that now - I've got a variety of programmers which are usually much easier to use.
Lost Cause wrote: Or maybe I can use a 328 to act as a programmer in place of a full Arduino board <.<
It should be possible to use a 328 as a programmer for other 328s (and other atmegas). AIUI the arduino hardware is just a 328 with a bit of supporting circuitry (dc regulator etc) on a nice pcb.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 8:40 am

Yes, I knew it had to be possible. The bootloader isn't special in any way. it sits in the same non-volatile memory as the rest of the AVR program. What puzzles me though is that in so far as I am aware the bootloader controls programming the rest of the memory when it is used to program the chip, but that isn't the case when the ICSP pins are used. Those bypass the bootloader entirely, but as far as I can see that must mean they also overwrite the bootloader. so the process of using AVRdude must also incorporate a reinstallation of the bootloader too, or some part of the instructions must have it avoid the right bit of memory... or maybe I am wrong. wouldn't be the first time.
Since AVRdude can be used to program non-Arduino chips, there must be options related to this somewhere. likely related to the bit where you ID the chip in question. I'll just have to take some time to look into the details of how it works and maybe get the bootloader or... or just learn what I need not to need it.

And before I even hit submit I have found the AVRdude instruction to preserve the bootloader....
I have made my statement and I stand by it but I could be wrong.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 8:52 am

Lost Cause wrote:Yes, I knew it had to be possible. The bootloader isn't special in any way. it sits in the same non-volatile memory as the rest of the AVR program. What puzzles me though is that in so far as I am aware the bootloader controls programming the rest of the memory when it is used to program the chip, but that isn't the case when the ICSP pins are used. Those bypass the bootloader entirely, but as far as I can see that must mean they also overwrite the bootloader. so the process of using AVRdude must also incorporate a reinstallation of the bootloader too, or some part of the instructions must have it avoid the right bit of memory... or maybe I am wrong. wouldn't be the first time.
Since AVRdude can be used to program non-Arduino chips, there must be options related to this somewhere. likely related to the bit where you ID the chip in question. I'll just have to take some time to look into the details of how it works and maybe get the bootloader or... or just learn what I need not to need it.

And before I even hit submit I have found the AVRdude instruction to preserve the bootloader....
From memory I think the bootloader sits at the other end of the program flash space, you then set some fuses to tell the chip to use it first. there are also some lock bits to protect that space from normal flashing.

The relevant atmega datasheet has some detail of this, possibly in the programming and fuses sections. There's probably some appnotes. If you've got the ICSP programming setup then you might not need the bootloader, although having the bootloader means you can program the chip over serial rather than needing the ICSP setup all the time.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 9:01 am

Already started programming the chip without the bootloader. I'm tinkering with the fuses too, though very carefully since apparently you can kill a chip and need to go with high voltage programming if you set those wrong.
I have made my statement and I stand by it but I could be wrong.

dave j
Posts: 116
Joined: Mon Mar 05, 2012 2:19 pm

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 10:23 am

If anyone does need to flash an Arduino bootloader you can find instructions at Using Raspberry Pi as an Arduino (AVR) programmer and from Adafruit at Program an AVR or Arduino Using Raspberry Pi GPIO.

The current Raspbian version of avrdude seems to already have support for using GPIO pins so you shouldn't need to follow the compilation steps.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 10:51 am

Hmm. that could work.
I don't know yet as I didn't have a dektop enviornment on this pi and if I run the arduino IDE remotly it fails because it doesn't have permission to use the gpio despite AVRdude having that permission, but if I tun the Arduinop IDE as superuser it fails to connect to Xming server outputting a wonderfuly familiar error message that makes me pine for the time I spent programing java.
These are likely issues with the peculiarity of my particular setup. I think I can fix them.
I have made my statement and I stand by it but I could be wrong.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 1:04 pm

Lost Cause wrote:I have been greatly enjoying the expanded capabilities the RPi gets when paired off with a microcontroller or two, but I have hit something of a wall.

I set up a pi with the Arduino IDE and promptly forgot it existed as I compiled programs from the command line and then uploaded them with AVRdude by means of the GPIO pins of the pi and that was fine for chips like the Atmega328p which came with the Arduino boot loader installed.
The problem came when I tried to expand to using the Atmega32a microelectronics that didn't come with a boot loader.
I know there is an Arduino compatible boot loader for the 32a. The issue I have is that I don't have an actual Arduino board, or a usb-serial adaptor and every approach I find to get the boot loader onto a chip requires one or the other. I see frequent vague mention that it can be done entirely with rpi GPIO, but no actual examples of how to do it.

So Can anyone tell me if it is possible, with nothing more than an RPi, some wires, a bread board, and a few resistors to actually flash an Arduino boot loader onto a suitable microcontroller?

Right now I will settle for a yes or no answer just so I can decide whether or not to keep trying or look more into how to program these things without the boot loader at all, which i was going to have to do when I started tinkering with the PIC controllers anyway.
Or maybe I can use a 328 to act as a programmer in place of a full Arduino board <.<
Yes it is.

It is no different from flashing any other AVR program (NOT Arduino) using the Raspberry Pi, as the Arduino loader is nothing more than another AVR Program.

You do know that the Arduino loader is NOT needed to use an AVR?
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 1:11 pm

Lost Cause wrote:Hmm. that could work.
I don't know yet as I didn't have a dektop enviornment on this pi and if I run the arduino IDE remotly it fails because it doesn't have permission to use the gpio despite AVRdude having that permission, but if I tun the Arduinop IDE as superuser it fails to connect to Xming server outputting a wonderfuly familiar error message that makes me pine for the time I spent programing java.
These are likely issues with the peculiarity of my particular setup. I think I can fix them.
Well the AVR is a simple device to program, and does its job well. I do not know why you want to use the IDE if you are doing without it now, though you should be able to tell the IDE to just use AVRdude for talking to the AVR.

Do you work in assembly or an HLL (like C)? I ask as you have mentioned Arduino a few times.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 2:31 pm

Actually, I didn't want to use the IDE, it sort of gets in the way but it has the flash boot loader command.
I typically have no idea what I am doing I just keep trying until something happens so I got slightly confused between what I thought I needed and what I actually needed.
Right now without the bootloader or arduino IDE I can get the atmega32a to do things. Not everything I need it to, but slowly figuring that out. If I can get I2C and SPI up and running again I think that would cover most of what I actually need and don't know how to do. Since I have a habit of using as much of my own code as I can just to be sure I know how things work, once I can get a nice little interface set up to use the same signatures as the arduino's Wire lib everything I have should start working again.
Had I been able to set up the 32a with the bootloader it should have worked /almost/ like a drop in replacement for the 328ps I have been using and I would have been able to carry on without change just using the same arduino libs.
Right now I'll just need to work out the basics of the atmega chips that were hidden behind arduino.h
I have made my statement and I stand by it but I could be wrong.

dave j
Posts: 116
Joined: Mon Mar 05, 2012 2:19 pm

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 4:24 pm

Lost Cause wrote:Actually, I didn't want to use the IDE, it sort of gets in the way but it has the flash boot loader command.
I typically have no idea what I am doing I just keep trying until something happens so I got slightly confused between what I thought I needed and what I actually needed.
Right now without the bootloader or arduino IDE I can get the atmega32a to do things. Not everything I need it to, but slowly figuring that out. If I can get I2C and SPI up and running again I think that would cover most of what I actually need and don't know how to do. Since I have a habit of using as much of my own code as I can just to be sure I know how things work, once I can get a nice little interface set up to use the same signatures as the arduino's Wire lib everything I have should start working again.
Had I been able to set up the 32a with the bootloader it should have worked /almost/ like a drop in replacement for the 328ps I have been using and I would have been able to carry on without change just using the same arduino libs.
Right now I'll just need to work out the basics of the atmega chips that were hidden behind arduino.h
It sounds like what you really need is some sort of in circuit programmer you can plug into a computer and insert an AVR into for programming. This is easy enough to do with a Pi, breadboard and leads but something more permanent might be preferable if only to save you having to remember which wire goes where. Unless you particularly want to develop on the Pi, you might as well get a USB based solution so you can use it with any computer.

User avatar
Lost Cause
Posts: 30
Joined: Sat Aug 02, 2014 2:44 pm
Location: Ireland

Re: Using RPi to flash Arduino bootloader

Sun Mar 12, 2017 4:49 pm

I would really like to carry on working with the Pi. Building a board or drop on shield for the pi to make programing these things easy has been on my todo list for ages XD
I get distracted by the other fun things I could be doing and some jumper wires and a breadboard is "good enough" in 99% of cases.
Heck I got a pi zero explicitly for the purpose of making a small portable AVR programer and right now it is the only Pi I haven't done anything with >.>

If I am not mistaken the pi zero can act as a usb slave. Options to look into, something that can work stand alone, or controled from another device ^.^
I have made my statement and I stand by it but I could be wrong.

Return to “General discussion”