"AVR device is not responding" when shield is present

I have a stack consisting of RPi 2, Arduberry, Arduino Motor Shield R3. The only way I can upload new code to the Arduberry is to remove the motor shield. Otherwise I get:

avrdude: The AVR device is not responding avrdude: initialization failed rc=-1 Double check connections and try again, or use -F to override this check.

I did some experimenting and if anything is plugged into pin 13, I get this error. Is there any way to update the code on an Arduberry without removing a shield?

Hey,
From the specifications for the Arduino motor shield, it looks like it uses some of the SPI pins (D13 and D11) which are used to upload the code to the Arduberry. The pins must be interfering with the code upload so I don;t think it would be possible to upload code to Arduberry without removing the motor shield.

-Karan

The same thing happens when I have an LED plugged into port 13. So is it expected behavior that you can’t upload to the Arduberry if anything is plugged into D11 or D13?

Hey Mark,
Yes, the LED might be causing a problem with the code upload if the LED is connected on ports D11,D12 or D13 during code upload.

-Karan

Mark,
Just a little more information: those are the SPI lines that the Pi uses to program the atmega chip. Sometimes if those lines are in use, they can generate errors for the programmer. It sounds like that’s what you’re seeing when the shield is on there.
John

I’m trying to use it in education. I think the life expectancy of the components will go down dramatically if we have a bunch of teenagers pulling a shield off it every time they need to update the atemega chip with new code.

Is there any way to set those pins to NOT be in use programmatically so I can use them to upload? Or are there any other ways to get it to a point where we can upload from the pi without physically removing a shield that is plugged into the Arduberry? I just want to make sure that there isn’t something we can script that would let us to a successful upload without taking the stack apart.

Hey Mark,
There is one way which is possible. You can burn the arduino bootloader using SPI and then just upload the code using serial port. This way instead of the SPI pins being unusable, the serial pins become unusable.

The problem with this method is that we have not yet figured a way to integrate it with the Arduino Ide. This only works from the terminal. Do let us know if this works for you.

-Karan

Hey Mark,
Just hopping in at the last minute here. Karan and I talked about this yesterday as a possible solution, what he describes above. The Arduino typically uses the SPI lines, and programming it through those is how the Arduino program is setup on the Pi. If you change the bootloader on the Arduino, you can do this programming with the serial lines (leaving the spi lines free for our shield). We have to write a specific howto on this because as Karan mentions, you’ll need to program the Arduino chip a different way (probably through the command line).

We’re going to discuss it a little more and try to figure it out. If there’s anyone smarter out there listening, please hop in!

Best,

John

Thanks Karan and John - It is helpful to know that there is a way, even if it isn’t easy to do right now.

Karan or John,

You don’t by chance have a HOWTO on programming the Arduino using serial lines rather than SPI (even if it is through the command line rather than the IDE)? I am interested in freeing up my SPI lines since I just hosed my ATMega328P trying to use pins 11 & 13. Thanks for any pointers, you guys rock!

-Mike

@miesch1: In theory there is a way to upload the code without serial. You can write the Arduino bootloader to the Arduberry via SPI and then use serial to upload code to it. This would render pins 0 and 1 unusable but would let you use the SPI lines. We have not tried this with the Arduberry before, so not really sure if it would work or not. Let me know if this is something that would help, I can try it out in the next few days and let you know if there is an easy way to use this.

There is also a 6 pin FTDI connector on the Arduberry that you can use to upload the program with an FTDI adapter without using SPI.

@karan,

You are seriously an amazing moderator! Thanks for the support. I want to remotely flash my Arduberry, so I access my Pi via noVNC (which I love having by default in your Dexter Jessie build!). So the FTDI connector would probably work for me to recover my locked up ATMega328P, but that wouldn’t help for remotely flashing, right? In any case, I already replaced my MCU and I don’t mind losing my Tx/Rx lines. I would rather free up my SPI lines, so if you could offer some pointers on how to flash via Tx/Rx, I would be extremely grateful! Thanks again man and have a great weekend.

-Mike

@miesch1,
Thanks for the kind words.

We still haven;t got to trying it out at our end, however I understood what you want to do. SPI is usually way more reliable and hence we usually recommend it.

You can use the FTDI code to remotely upload the code too, however in that case it would be connected to the USB port on the Pi instead of your computer. Not an ideal way to do it but it would work.

The other was is to use the Arduino Bootloader and use the Serial pins on the Arduberry. There are a lot of different settings to try out to get this way to works, if it works at all. We will try it out this week and let you know if it would work or not.

Also, can you tell me a little more about the project you are building. I might be able to help you find alternative ways that might be better/easier.

-Karan