atmosteam
Posts: 68
Joined: Mon Jun 22, 2015 7:22 am

Programming Arduino via GPIO

Mon Jul 06, 2015 8:29 pm

Hello, I am trying to program an Arduino via GPIO but I get some errors. I looked for information about errors doing the same but there are different errors.
I use the Arduino IDE 1.5.6 and the port is in /dev/ttyAMA0
I connect the Arduino to a voltage supply of 15V and is connected to the Raspberry with Rx to Tx and Tx to Rx and the GND to GND as expected.
the error says:

Code: Select all

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
and repeats the same with 2 of 10, 3 of 10, etc....
this error is shown in the Aduino 1.5.6 program.
I was able to create a serial communication between them, but what I want is to program the Arduino as well.
Thank you.

Heater
Posts: 13271
Joined: Tue Jul 17, 2012 3:02 pm

Re: Programming Arduino via GPIO

Mon Jul 06, 2015 8:35 pm

Have you remembered to disable kernel and system messages coming to /dev/ttyAMA0 ?

This can be disabled with the raspi-config program.

If I remember correctly the Arduino is a 5 volt device. The Pi is a 3.3 volt device. Have you taken care of that?

How does the Arduino know when it is being programmed as opposed to just receiving serial data? Presumably it needs to receive some kind of reset signal to make it enter it's boot loader and be ready for programming.

I have done this with the Parallax Propeller chip using GPIO 17 as the reset signal. But that required modifying the Propeller loader software to use GPIO 17 as reset rather than the usual serial port's DTR signal or whatever.

adlambert

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 9:15 am

I am not sure if this is any use, but a 3.3V arduino clone which mounts on a Raspberry Pi:

http://rasp.io/

I have no connection with these people, apart from owning one myself.

atmosteam
Posts: 68
Joined: Mon Jun 22, 2015 7:22 am

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 1:21 pm

Heater wrote:Have you remembered to disable kernel and system messages coming to /dev/ttyAMA0 ?

This can be disabled with the raspi-config program.
okay, will it do any effect or something by disabling it? I mean, what will it do?
Heater wrote:If I remember correctly the Arduino is a 5 volt device. The Pi is a 3.3 volt device. Have you taken care of that?
yes, I did the appropiate voltage divider.
Heater wrote:How does the Arduino know when it is being programmed as opposed to just receiving serial data? Presumably it needs to receive some kind of reset signal to make it enter it's boot loader and be ready for programming.
you mean to erase the arduino code that it contains with a signal?

Thank you

Kevin2341
Posts: 22
Joined: Tue Feb 24, 2015 5:39 pm

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 3:35 pm

I don't have a lot to contribute here, but I can't help but notice you said you're using a voltage divider to bring 12 (or was it 15) volts down to 5? Are you doing this just through a resistor network? I'd be cautious with that, if your Arduino is pulling a decent load (via LEDs or anything external), it will cause the network to see a different load and thus the voltage divider will change. 5V regulator would be a much more reliable voltage source.

atmosteam
Posts: 68
Joined: Mon Jun 22, 2015 7:22 am

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 4:25 pm

Kevin2341 wrote:I don't have a lot to contribute here, but I can't help but notice you said you're using a voltage divider to bring 12 (or was it 15) volts down to 5? Are you doing this just through a resistor network? I'd be cautious with that, if your Arduino is pulling a decent load (via LEDs or anything external), it will cause the network to see a different load and thus the voltage divider will change. 5V regulator would be a much more reliable voltage source.
sorry, I explained bad.. the Arduino is feed with 15V (specification says between 6 and 20V as limits). And it works with 5V in the pins, then, this voltage of 5 is what I divide to bring it to the Raspberry.
I already did a communication successfuly between them, but I want to not only communicate them, I aso want to program arduino with Raspberry, BUT with GPIO and not with the USB port.

Heater
Posts: 13271
Joined: Tue Jul 17, 2012 3:02 pm

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 5:03 pm

I'm not sure but get the feeling that if the Ardino IDE wants to program the Arduino it needs to send it a reset signal so that it reboots and runs it bootloader, thus allowing a new program to be downloaded to it.

This is normally done with the DTR or CTS or whatever signal it is on the serial port connection. Even if over USB adapter.

At least that is how it works with the Propeller MCU.

Now, if you connect tx and rx between Pi and Arduino and tell the IDE to use /dev/ttyAM0 there is no provision for that reset signal. So it's impossible to reprogram the Arduino.

When doing this with the Propeller I had to modify the downloader to use GPIO17 as a Propeller reset signal.

atmosteam
Posts: 68
Joined: Mon Jun 22, 2015 7:22 am

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 5:21 pm

Heater wrote:When doing this with the Propeller I had to modify the downloader to use GPIO17 as a Propeller reset signal.
okay, I undertand. Then, how can I modify the downloader to use a gpio pin as a reset signal?

Heater
Posts: 13271
Joined: Tue Jul 17, 2012 3:02 pm

Re: Programming Arduino via GPIO

Tue Jul 07, 2015 5:36 pm

I have no idea. In my case I had to checkout the loader code from it' github repository and figure out where it asserts and deasserts that reset signal. Then I had to find out how to wiggle a GPIO pin from the C language and add that code to the loader.

For the Arduino IDE guess the same kind of steps are involved.

My final Propeller loader code is here: https://github.com/ZiCog/pi-propeller-load if that is any help.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Programming Arduino via GPIO

Wed Jul 08, 2015 12:13 pm

Resetting the Arduino and uploading the hex file is handled by a program called avrdude, which has to be patched to make use of the gpio pins.

You have a couple of options. There are some pointers and links in this topic: viewtopic.php?f=96&t=106655

All these options assume Arduino IDE 1.0.1, but in later versions it's pretty much the same. You'll have to tell Arduino IDE to use the other/newer/patched avrdude by editing the files 'programmers.txt' and 'boards.txt'.

Arduino version 1.0.1 is easiest to install and patch. The topic above describes installing everything from a single script file. I suggest you use that, unless you have a very good reason to use a newer version (if you have an Arduino Due for example, but I'm not sure if that's even going to work).

There's also this topic, that discusses Arduino IDE 1.6.5: viewtopic.php?f=66&t=92662 I don't think that version is using the gpio's, but that should be relatively easy to add by patching avrdude and pointing Arduino IDE to it. As it is, you'll have to do that yourself though.

Edit: Note that these methods bypass (and overwrite!) the bootloader. It uses/bitbangs the SPI pins to transfer data, not USART. To make your Arduino work standalone (through USB) again, upload the bootloader back.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Return to “General discussion”