Has anyone tried this? Raspberry pi gpio pins programming arduino

I came across this tutorial on adafruit. It shows you how to program an arduino with raspberry pi gpio pins.

Are they not worried about damaging the raspberry pi at all?!

Fair warning, don't do this without voltage level converters. Arduino Uno 5V, raspberry pi 3.3V

I haven't used the linuxgpio programmer type recommended by that tutorial, but I have done it with the newer linuxspi programmer type, which has better performance. I documented my findings here:

There is an interesting article on the SparkFun website about how they used the linuxgpio programmer in their production programming system used to program many thousands of AVRs for the products they sell, but then found that the linuxspi programmer was much faster:
https://learn.sparkfun.com/tutorials/raspberry-pi-stand-alone-programmer

I plan to make the linuxspi programmer accessible for use via the Arduino IDE, but this required a patch to avrdude. I submitted that and it was merged, but there has not been a new release of Arduino AVR Boards that uses the version of avrdude that contains that fix yet. So I haven't been able to move forward with the project.

We haven't gotten an official answer from Arduino as to whether they want to add official support for this programmer, as was proposed here:

My suspicion is the answer is no, but if that was a clear-cut answer that issue would have been closed.

The other option is for me to create a custom hardware package that the user can install to add this programmer to the Arduino IDE's Tools > Programmer menu. Arduino is now hosting the patched version of avrdude so that it can be used for beta testing. That could be installed automatically during the Boards Manager installation of my custom hardware package, so the avrdude version would only be an issue for the rare users who want to do a manual installation of the hardware package.

liuzengqiang:
Are they not worried about damaging the raspberry pi at all?!

Is Adafruit worried that people are going to burn up their RPi and have to buy a new one from Adafruit? Really I'm just joking. I'm certain that Adafruit would never intentionally give incorrect advice with the intention of profiting from it. There's nothing unethical about providing a nice tutorial about how to do something with their products. The fact is that we take the chance of paying the magic smoke tax every time we mess with hardware. I don't see that this is any more hazardous than any other project where people are wiring random components to their RPi. I've never thought the RPi was a good platform for learning the basics of electronics when compared to an Arduino board, but certainly a lot of people are doing it.

I do like the concept of being able to use the same SBC you're running the Arduino IDE on as your ISP programmer but to be honest I would just use my USBasp for my everyday programming needs. However, unlike many Arduino users, I already own the USBasp and, unlike SparkFun, a few seconds extra of programming time doesn't matter to me. The RPi as programmer using linuxspi could be a really great option both for people who need to burn a bootloader but only have that one Arduino board and also for people who need the highest level of programmer performance.

Pert,

I agree with you. Destroying a 5 buck RPI zero sometime down the road from this tutorial isn't too bad, as long as you can learn something from your experience. I'll still have a level shifter when I decide to do it. I have plenty of those in hand.

By the way, could you give me a pointer to the spi version avrdude? I'm not familiar with this development and am thankful that you responded.

liuzengqiang:
I agree with you. Destroying a 5 buck RPI zero sometime down the road from this tutorial isn't too bad, as long as you can learn something from your experience. I'll still have a level shifter when I decide to do it. I have plenty of those in hand.

Well, I've never gotten ahold of a Pi Zero for less than $15 once I paid the shipping, but that's still not a huge loss. I'd guess running the Arduino IDE's GUI is painfully slow on the RPi Zero, but I haven't tried it. It's reasonably OK on my RPi 3 B+, but once I get to the price range of that RPi I'm not so happy to have a magic smoke incident.

liuzengqiang:
By the way, could you give me a pointer to the spi version avrdude?

avrdude 6.3.0-arduino17 should have my patch in it. The download URL for the Linux ARM version is:
http://downloads.arduino.cc/tools/avrdude-6.3.0-arduino17-armhf-pc-linux-gnu.tar.bz2

liuzengqiang:
I'm not familiar with this development and am thankful that you responded.

You're welcome. I'm always happy to share my knowledge. In this case, I gained it at the cost of a lot of research and trial and error, since there was very little information available on the linuxspi programmer type.

Although the author of the linuxspi programmer code submitted a patch to mainline avrdude 6 years ago, it has not been merged. So this feature is only available when using Arduino's custom version of avrdude. The same goes for my patch.

Pert,

I'm a bit intimidated when it comes to building a tool with make. My first experience with make was on MS DOS, where it was easy to understand (both TurboC and Assembly). Now it's too much for me. So I just downloaded the already-built arm version of avrdude. That's convenient. Thanks again! I'll give it a try later tonight with my rpi 3B. I'll not compile arduino code on rpi. Just compile on PC and send it to rpi somehow.

By the way, is this the correct command? I hodgepodged it from your .conf and adafruit's tutorial:

sudo avrdude -p atmega328p -C ../etc/avrdude.conf -c linuxspi -v

I just need to use pin 25 for reset. Now to think about my experience, I've almost never used rpi's GPIOs for anything other than some buttons. I always use Arduino for GPIOs, SPI, I2C and leave the networking etc. to RPI.

[Edit] error message no port specified. Port should point to spi interface.
[Update]: correct command:

sudo ./avrdude -p m32u4 -C ../etc/avrdude.conf -c linuxspi -v -P /dev/spidev0.0

liuzengqiang:
I'm a bit intimidated when it comes to building a tool with make.

I've used it a lot to compile various bootloaders and am very comfortable with that, but when I did my patch of avrdude, that was an absolute nightmare. There were so many dependencies I had to install and get the right versions of all of them. There was no official documentation so every time something went wrong I had to go on a fantastic Google journey through all sorts of obscure forum threads to find the solution. Very much not an enjoyable experience, especially because it was a very simple patch and I had no interest in any further development of avrdude. I easily spent 10X as much time setting up the toolchain to compile avrdude than I did writing the patch. And of course there was no hope of ever pulling it off on my Windows machine.

This is the sort of experience that makes me realize what a revolutionary concept Arduino is. We now know that programming doesn't need to be so complex, but most of the time there are these unnecessary barriers to entry that make the learning curve so steep. If I was more conspiracy minded, I'd think the professionals add them intentionally. More likely, it's simply that they're used to this sort of thing as business as usual and they just no empathy for the beginners so they won't bother to make the effort to break down the barriers.

If I had ran into that sort of thing when I tentatively gave Arduino a try simply as a lark, I would have immediately chucked that board in the trash and moved on to other ways to spend my free time.

liuzengqiang:
[Update]: correct command:

I'm glad you got it working!

Thanks very much for sharing your experience with me Pert! I guess making the tool chain work is like harvest potatoes. You thought you’re done and then there’s more. I appreciate your compiled version even more now! Yes, Arduino is a thing that filled much void between professionals and the very beginners. I love it! That’s also why I criticize it from time to time.

Hi Pert,
I'm trying to add some SPI memory to the arduino and I wonder if the rpi spi interface is active even when avrdude or pigpio or other high-level callers are not using it. If rpi's SPI is inactive, I suppose I can just add some SPI memory on the 5V side of the level shifter. Any advice? Thanks.

Hi. Sorry, I'm not at all knowledgeable on that subject.

Thanks. I'll do some investigation on my own and post my conclusion here. My multimeter measurements on the 3.3V side of the level shifter yields 0V for SCK, and 2.7V for the other pins including GPIO25 for resetting arduino. I think that makes some sense. avrdude set GPIO25 to HIGH and exits. The SPI bus is probably still active, controlled by rpi. I'll ask on rpi forum and get back.