Go Down

Topic: Flashing other Arduinos with a Yun (Read 6608 times) previous topic - next topic

noblepepper

Oct 04, 2013, 03:15 pm Last Edit: Oct 04, 2013, 03:17 pm by noblepepper Reason: 1
I was pretty amazed at how easy this was, surprised no one else has commented on it. Here's how I am doing it:
Update opkg repository - ssh into the Yun and run
Code: [Select]
opkg update
Install pure-ftpd on the Yun
Code: [Select]
opkg install pure-ftpd
Start pure-ftp in daemon mode:
Code: [Select]
pure-ftpd -B
Now you can ftp into the Yun to transfer sketches
Install the usb/acm module on the Yun
Code: [Select]
opkg install kmod-tty-acm
Plug your other Arduino into the USB A connector on the Yun, you will now have /dev/ttyACM0 just like on a big linux box.
Make some scripts to flash the second Arduino I named mine flashUno and flashMega, you can do this on on your computer and ftp to the Yun or use Vim on the Yun, either way here are the contents you need for a Uno:
Code: [Select]
#!/bin/ash
arguments=$#
if [ $arguments -eq 1 ]
then
   avrdude -C/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:$1:i
elif [ $arguments -eq 2 ]
then
   avrdude -C/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P$2 -b115200 -D -Uflash:w:$1:i
else
   echo "Usage: flashUno <file> <port>"
fi

Here is a script for a Mega2560:
Code: [Select]
#!/bin/ash
arguments=$#
if [ $arguments -eq 1 ]
then
   avrdude -C/etc/avrdude.conf -v -v -v -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:$1:i
elif [ $arguments -eq 2 ]
then
   avrdude -C/etc/avrdude.conf -v -v -v -v -patmega2560 -cwiring -P$2 -b115200 -D -Uflash:w:$1:i
else
   echo "Usage: flashMega <file> <port>"
fi

Make the scripts executable
Code: [Select]
chmod a+x flashUno
chmod a+x flashMega

Now all you need to do is verify the sketch on your computer, find where it is, ftp it over to the Yun and run the script like this:
Code: [Select]
./flashUno Blink.cpp.hex
or if the Arduino shows up somewhere besides /dev/ttyACM0
Code: [Select]
./flashUno Blink.cpp.hex /dev/ttyACM1

Priscilla

The bootloader is missed during this upgrade. so you won't be able to upgrade it again via Arduino after you doing this.

noblepepper

I don't think I understand your response, all this does is flash a sketch to another Arduino that is connected to the Yun instead of the computer using the same avrdude command as the Arduino IDE. It shouldn't touch the bootloader.

I intend to use this to debug my Uno or Mega when they are attached to something in a different part of the house where my USB cable won't reach but the Yun can get a WiFi signal. Avoids needing to have the second Arduino _physically_ attached to the development box.
The next step is to put together a way to run a serial monitor over the WiFi too, more later...

Priscilla


I don't think I understand your response, all this does is flash a sketch to another Arduino that is connected to the Yun instead of the computer using the same avrdude command as the Arduino IDE. It shouldn't touch the bootloader.

I intend to use this to debug my Uno or Mega when they are attached to something in a different part of the house where my USB cable won't reach but the Yun can get a WiFi signal. Avoids needing to have the second Arduino _physically_ attached to the development box.
The next step is to put together a way to run a serial monitor over the WiFi too, more later...


Your method only upgrade the .hex file for your program. but it doesn't upgrade the bootloarder. if you use Arduino IDE to upgrade, it will first combine Blink.cpp.hex and the bootloader.hex together into a single hex file , then upgrade it to the avr.  Miss the bootlarder will cause the avr is not Arduino compatible, means you can't upload scketch again by directly connect to Arduino IDE via USB cable.

Anyway, for your case, it works because you upgrade it via linux enviroment, not Arduino IDE enviroment. so bootloader is not required.

noblepepper

Please make some effort to check your statements that something will cause damage before posting them.

I certainly don't want to damage anyone else's toys so I went to the trouble of downloading Arduino for my Windows7 laptop (I normally only use windows when I am getting paid, not having fun!) and checking the Uno after I had flashed it with the Yun. Everything works exactly as expected, sketches flash just fine. In fact the windows version of the IDE uses the same avrdude command as the Linux version except for the file locations.

Yes, this is done in an Linux environment, specifically Linino, which is what the AR9331 in the Yun runs. You may want to learn some Linux so you understand posts in this forum.

Jantje

I did this with the yun and indeed the uploader is gone.
Actually the sketch didn't even run properly.
Note that I did something similar on openwrt which worked fine. It is just that the avrdude installed on the yun by default is a special one.
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

noblepepper

Hi Jantje, thanks for trying this, I am not having any problems. Would you help me understand yours?

What do you mean by "the uploader is gone" ? Do you mean avrdude?

I have just been testing using the Blink example, changing the delay(1000) to delay(100) so I can verify the sketch was uploaded when the led blinks at a different rate. What sketch did you use that fails to run properly?

Thanks, Noble


Erni

Maybe the problem is the same as i once had

http://forum.arduino.cc/index.php?PHPSESSID=sk1fcn1domejm4uirlm4n3ci91&topic=189570.0

The bootloader got erased when i uploaded over LAN

noblepepper

Erni - Now I really need some help understanding, I have tried to duplicate what you reported in your post Sept 23 and my Yun keeps working fine. Here is what I did:

1. Upload blink sketch via USB to the Yun, the led blinks
2. Change blink sketch timing to 100 milliseconds , upload via USB to the Yun, the led blinks fast.
3. Change the blink sketch back to original 1000 mS, upload via WiFi to the Yun, the led blinks slowly
4. Change the blink sketch timing to 100 mS, upload via Wifi to the Yun, the led blinks fast.
5. Change the blink sketch back to original 1000 mS, upload sketch via USB to the Yun, the led blinks slowly
6. Change blink sketch timing to 100 milliseconds, upload via USB to the Yun, the led blinks fast.
7. Change the blink sketch back to original 1000 mS, upload via WiFi to the Yun, the led blinks slowly
8. Change the blink sketch timing to 100 mS, upload via Wifi to the Yun, the led blinks fast.

It seems like I can do this forever with no ill effect.

What really confuses me is the situation Federico describes exists for me too. The script run-avrdude has an efuse setting of FB and boards.txt  has a efuse setting of cb for the Yun. Don't the fuses only get set when you burn the bootloader?

In any case I am just flashing sketches here, using the avrdude settings copied out of the bottom of the IDE when you push the upload button . I have flashed a Uno, Mega, and Due from the Yun and they still work fine with the IDE when I plug them back into the computer instead of the Yun. I don't call the run-avrdude script, the scripts I am using call avrdude directly.

I only have one Yun so I can't flash a Yun from a Yun (that would be pointless anyway wouldn't it?)

Thanks for your help, Noble

Jantje

Erni
The problem you had was with uploads to the yun. This thread is about uploads to a mega or uno attached to the yun via the usb port.
The config file may have the same problem for USB connected devices; I have not yet dived into the details.

noblepepper
I have tried this a while ago and I still need to fix the broken boards. I have not done decent investigation in how what where when.
This link tells you how arduino IDE uploads a sketch http://forum.arduino.cc/index.php?topic=188802.msg1396988#msg1396988

What I tried what
Connect Arduino to yun
Upload sketch from yun (as you do)
Run a serial monitor on the yun to connect to Arduino.

What I Learned
1) When you connect a arduino to the yun the com port ttyACM0 is not found. You need to install kmod-usb-acm to get it to work. See http://blog.baeyens.it/#post11 for more info
2) once the problem 1 is fixed a serial monitor can connect to the Arduino and you can communicate. It didn't look stable but it works.
3) Uploading a sketch with the commands as you used them seems to work. However when connecting again to the board with a serial monitor it fails.
I assumed that was caused by the bootloader that was not attached. I planned to try with a avrdude I use on my openwrt box but I have not had the energy/time to do so.

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

noblepepper


1) When you connect a arduino to the yun the com port ttyACM0 is not found. You need to install kmod-usb-acm to get it to work. See http://blog.baeyens.it/#post11 for more info

Yes, I figured that out with some help from Google, it missed your blog somehow


2) once the problem 1 is fixed a serial monitor can connect to the Arduino and you can communicate. It didn't look stable but it works.

I took a look at your blog and now have minicom installed on the Yun. It has been years (decades?) since I used minicom so it took a bit to get it configured. Finding a terminal was my next step, THANKS!

I now have a modified blink sketch running on the Uno, and reporting to minicom on the Yun when the led is on or off. Looks good so far.

All this makes my hair hurt, which terminal is ftp running in?, which one is compiling Linino?, which one has ssh running?, did I remember to shut down minicom before I unplugged the Uno? did I remember to do Serial.begin()? I'm going to have a BEER!

Thanks again, Noble


noblepepper

Jantje - The minicom <->  sketch communications ran for 12 hours without problems. Sending On Off On Off at 9600 baud isn't very demanding though, what kind of stability issues did you see?

On the second part of your point 3, I don't see problems, can you give some details?
When I flash a sketch to the Uno from the Yun I can use minicom on the Yun to connect to the serial through the USB on /dev/ttyACM0. When I move the Uno's USB connection from the Yun to my desktop machine, I can connect to the Uno through the Serial Monitor of the Arduino IDE on /dev/ttyACM1 (the Yun is still using /dev/ttyACM0).

Jantje

noblepepper
It didn't work from me. My bet would be that you are not running the avrdude delivered with the yun.
I won't have time to investigate soon.
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

noblepepper

Thanks for your help so far. When/if you get back around to playing with this, I am using the stock Yun avrdude (but not the run-avrdude script). I did the Wifi button 30 second reset before following the original procedure in this thread to be sure I didn't forget any steps.


Jantje

I tested my Yun uploaded Mega with the com port of my pc to upload a sketch and it looks as if it works but I get following error.
Code: [Select]
verification error, first mismatch at byte 0x0000
         0x0c != 0x14

A quick search on the internet indicates this may be a missing bootloader. This sounds like a consistent story.
Burning a new bootloader also gave a verification error but fixed the issue.
Now I can again upload sketches to the board
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Go Up