Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

:: Arduino Yún ::


The Arduino Yún is a microcontroller board based on the ATmega32u4 and the Atheros AR9331 processor which runs OpenWrt-Yun, a customized version of a Linux distribution called OpenWrt.

Hardware Features
  • built-in Ethernet and WiFi support
  • one USB host port
  • micro-SD card slot
  • 20 digital input/output pins
  • 7 PWM outputs
  • 12 analog inputs
  • a 16 MHz crystal oscillator
  • micro USB connection
  • ICSP header
  • 3 reset buttons

Basic documentation by the Arduino Team

These documents are a must read for all owners of an Arduino Yún.

important note to yun users: UPGRADE

The version delivered on your yun may not be ready for "production". Yun still comes shipped with the linino version. Many users suffer issues at several levels of this version. To name some:

  • liability ( sketch using bridge run maximum for a week) .
  • WIFI are not usable.
  • DHCP lease not work.
  • fileio library size() function is not developed yet
  • the yun crashes if you read big files from the micro SD card using fileio library
  • ttyACM0 is unstable

These issues have been reported to the Arduino core team and the core team took them at hart and fixed them in the openwrt version. So check to make sure you have the openwrt version or later and if not: UPGRADE.

Interestings topics discussed on the Forum

The Yún has its own section on the Arduino forums. People try new things every day, so there is a lot of useful information to be found in the topics discussed on the forum. But with every new post or question the older topics get pushed down the stack. Once they are on page 5 or so they are actually out-of-sight and people start to ask questions which have already been answered.

So it seems to be a good idea to keep a reference to some of the more important topics.

Topics

Powering Yún: add a regulator!

The Yún board does NOT come with a built-in power regulator (as does the Yún Shield). If you are experiencing instability on the WiFi chip, blue LED going off, strange or sudden resets, etc., adding a good regulator will likely solve these issues. The Atheros chip (the WiFi part) seems especially sensitive to transient spikes, ripples, lead inductance and the like when powered from the vIn pin. For example, if you power high current devices (e.g. a high torque servo) on the same power supply as the Yún (obviously not from the board, but on the same input power line) the inductance pulse, spikes or ripples will likely reset the Atheros chip much like pressing the Yún reset button. Placing a small up/down, adjustable dc-dc regulator such as the Pololu S7V8A accompanied by a 33-100uF Electrolytic Cap just before the regulator will most probably solve most of these instability issues. Pololu has a good article on Understanding Destructive LC Voltage Spikes If you are driving high power stuff, feed them before the regulator, always with common ground, of course.

How to improve reboot/reset stability

Some important information to understand about (re)booting/resetting the Yun 1)When the Yun is powering up both the Leonardo and the Linux part are booting up. This means that at this time both processors start at the same time. 2)When the Leonardo part is rebooted (due to upload, rest button, reset-mcu command,....) the Linux keeps on running. 3)When the Linux part is rebooted (due to reboot command, reset button, upgrade,...) the Leonardo part keeps on running. It is important to understand that those are 3 different situations and the behavior in the 3 situations is different. Why? When the Linux part is booting it sends and reads information on the serial port /dev/ttyATH0. On the Leonardo part that is Serial1 (used by the bridge or your bridge replacement). If the Leonardo responds to the booting information of the Linux; it is very likely (not to say it is guaranteed) that the Linux will not finish its booting process.

 note:As the information Linux is transmitting is your life saver when things go really bad you do not want this behavior to go away. 

Therefore it is important to know the state the other processor is in. However there is currently no way to know that (and frankly if you knew it won't be nice and easy code)

So what are the workarounds?

 Case 1  

is catered by the bridge (and that is why it can take a very long time for the bridge to startup) but if you use serial1 without the bridge you will need the same code in your setup() method

  delay(2500); //The bare minimum needed to be able to reboot both linino and leonardo.
                          // if reboot fails try increasing this number
                          // The more you run on linux the higher this number should be
  Serial1.begin(115200); // Set the baud.
// Wait for U-boot to finish startup.  Consume all bytes until we are done.
  do {
     while (Serial1.available() > 0) {
        Serial1.read();
        }
    delay(1000);
  } while (Serial1.available()>0);

 case2:  

As the problem only happens when the Linux part is rebooting: case 2 is not a problem as Linux is not booting.

 Case 3:  when you use the reboot command on Linux. 

Make a new file called /bin/reboot with following content

reset-mcu
/sbin/reboot

make the file executable

chmod +x /bin/reboot

After this change a reboot command will reboot the Leonardo together with the Linux and case 3 becomes case 1.

But: the reboot of the Linux is delayed. To cope with this situation add at least a delay(2500) to your sketch. There is no way to determine the lowest delay value that will work for all cases. When thinking about a good number keep following in mind: when booting up the delay in the loop (see case one) will likely be more significant. So the number used in the delay is only significant when resetting the leonardo only.

void setup()
{
  delay(2500); //The bare minimum needed to be able to reboot both linino and leonardo.
                          // if reboot fails try increasing this number
                          // The more you run on linux the higher this number should be

 Case 3: When you do a upgrade: 

upload the barebones example sketch to your yun before doing the upgrade. This makes that the leonardo will not interfere with the linux boot.

 Case 3: when you do a reset via the reset button 

Add a reset-mcu on line 21 of the wifi-reset-and-reboot script

 Case 3: when you do a factory reset via the reset button 

Is fixed by "Case 3: when you use the reboot command on Linux".

Note: These actions take away the need to do a reset-mcu in the /etc/rc.local file.

Power consumption of the board

Power consumption in mA
Configurationmintypicalmax
WiFi on, no wired connection, no sd170240300
WiFi on, wired connection, no sd 277 
WiFi on, wired connection, no sd, max. load 315 

Disabling the WiFi on the board saves ~20mA

(original forum topic | last edit : September 26, 2013)

How to disable WiFi

  • Edit file /etc/config/wireless and change line option disabled 0 to option disabled 1
  • Edit file /etc/rc.local and change line wifi-live-or-reset to #wifi-live-or-reset
  • Reboot

(original forum topic | last edit : September 26, 2013)

PoE module for Yun

Yun supports a PoE module, but currently (03/2014), YuN is not available pre-soldered with a PoE module, so you need to buy a PoE module separately and solder it. There is no _nice_ way to solder the PoE module, because the metal shield over the arm cpu and wifi chip is in the way of the PoE module. It either needs to be removed or cut to fit the PoE module.

Here is a picture of a YuN with soldered PoE module and cut shield:

Arduino Ethernet-Shield/Board-Ethernet use a PoE module that outputs 12V which is then converted to 5V by the arduino on-board voltage regulator. This limits the total power output at 5V to what that voltage converter provides (~ 500 mA). There is no such power regulator on YuN, so the PoE module for Yun must directly provide 5V. Silvertel has a lot of alternative PoE boards. The Arduino Ethernet where originally sold with AG9120-S. The 5V equivalent is the AG9050-S. Both of them have dual rectifiers on input, so they work both with normal and crossover ethernet cables. They also have PoE class programming, so with some additional soldering (not tried), you could indicate a different power consumption level to the PoE ethernet switch. Silvertel recommends the AG9700-FL series as a cost reduced drop in replacements. It is available for example here:

This PoE converter provides a total of 9W @5V, leaving ample power for I/O connected to YuN.

Building OpenWrt-Yún

The Yún runs OpenWrt-Yun, a customization of a Linux distribution called openwrt.

Source code and instructions for building the image can be found at https://github.com/arduino/openwrt-yun

Using an µSD card (or any other external storage)

As soon as you plug an µSD card in to the Yún, it becames accessible at folder /mnt/sda1. If you have one µSD card and a pen drive, former will have folder /mnt/sda1 and latter /mnt/sda2.

Creating a folder at the location arduino/www starting from the root of the µSD or a USB drive will let you upload your www folder when using WiFi to upload.

You can find your project's www folder on your µSD under /mnt/sda1/arduino/www or /www/sd.

In its factory setup, Yún supports the following file systems: FAT32 (including vFAT), EXT3/4, HFS(+), Reiser, Fuse, and NTFS. You can extend the number of supported formats by installing additional packages for MSDOS, ISO, BtrFS, MinixFS, UDF, XFS, CiFS, and NFS. Even AutoFS support can be added. FAT64 ist not supported.

(original forum topic | last edit : September 27, 2013)

(original forum topic | last edit : December 3, 2013)

Installing PHP (5 or 4)

In order to install php5 or php4, be sure your Yún can access the internet then, via SSH or via the YunSerialTerminal, issue commands

opkg update
opkg install php5 php5-cgi

Php5-cgi is good for making web sites. If you want to use php as a command line interpreter, install php5-cli

Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file: list interpreter ".php=/usr/bin/php-cgi"

(original forum topic | last edit : September 20, 2013)

Compiling c programs on the Yun

Yes you can actually compile simple c programs on the Yun! To do this you need to have an expanded storage as described in the tutorial at Expanding Yun Disk Space. There are also some issues with using opkg to install which aren't very hard to work around.

Here is what you need to do:
Insert a microSD card and run the Expanding Space sketch
Install binutils so you have a linker, without this gcc is pretty useless

opkg update
opkg install binutils


Install make if you plan on using Makefiles

opkg install make


Install the yun-gcc package using a cached location for the downloaded file, this can take 15 to 20 minutes so be patient:

opkg -t /root install yun-gcc


If you have problems with the checksum not matching you can do this instead:

cd /root
wget  https://downloads.arduino.cc/openwrtyun/1/packages/yun-gcc_4.6.2-2_ar71xx.ipk
opkg install /root/yun-gcc_4.6.2-2_ar71xx.ipk


Now you are ready to compile a c program!

Running multiple websites

If you're into web development, you'd like your Yún to run multiple web sites.

You need to edit uhttpd (the web server) config file, located at /etc/config/uhttpd . Many options are available at openwrt.org web site.

The following is just an example

config uhttpd main
    list listen_http	0.0.0.0:80
    option home		/www
    option cgi_prefix	/cgi-bin

config uhttpd secondary
    list listen_http	0.0.0.0:81
    option home		/mnt/sda1/arduino/www/
    option cgi_prefix	/cgi-bin

(original forum topic | last edit : September 26, 2013)

Sharing data between your python scripts and your sketch

You can user module bridgeclient.py located at /usr/lib/python2.7/bridge to share data between your python script and your Bridge powered sketch.

Take a look at the code snippets on the original forum topic to get inspiration.

(original forum topic | last edit : September 26, 2013)

Get "time" to work in PHP

You need to install the appropriate zoneinfo package. Via SSH or via the YunSerialTerminal, issue commands

opkg update
opkg install zoneinfo-core
opkg install zoneinfo-europe

Type opkg list | grep zoneinfo and look for your timezone

(original forum topic | last edit : September 29, 2013)

Get "json" to work in PHP

Via SSH, issue commands

opkg update
opkg install php5-mod-json

then edit file /etc/php.ini and uncomment the line extension=json.so

(original forum topic | last edit : September 29, 2013)

Unable to connect: is the sketch using the bridge?

Many users find that some examples just don't work: they upload them via wifi then open the serial monitor and read

Unable to connect: retrying (1)...
Unable to connect: retrying (2)...
Unable to connect: retrying (3)...
Unable to connect: retrying (4)...
Unable to connect: is the sketch using the bridge?

Most of the examples sketches EXPECT to be uploaded via USB cable, not via wifi.

Solution: close the serial monitor, select the proper port (COM or /dev/tty...) from the Port menu and reopen the serial monitor.

Sending HTML/XML/other from YunServer/YunClient

By default, when using "/arduino/" prefixed APIs, YunClient generated responses are treated as plain text. So, for example, if you print HTML code, you'll see the HTML code instead of the HTML page, nicely rendered by the browser.

To make things happen the right way, you need to override the default behaviour, setting the appropriate HTTP Headers, like so

client.println("Status: 200");
client.println("Content-type: text/html");
// any other header
client.println(); //mandatory blank line
client.println("<html><body>Hello world!</body></html>") //the response body

(original forum topic | last edit : October 1, 2013)

Guide to Setup Streaming Web Cam on the Yun

(original forum topic | last edit : September 18, 2013)

How to Run Sqlite3 and PHP on Arduino Yun

Install php5-mod-sqlite3 - 5.4.17-1, And of cource the other PHP modules you need

Example php5

     db=new SQLite3("/mnt/sda1/arduino/www/test/ec.db");
     $results = $db->query('SELECT * FROM Navn');
     while ($row = $results->fetchArray()) {
     var_dump($row);
     print $row[1];
     }

How to Run Sqlite3 and Python on Arduino Yun

Install python-sqlite3 - 2.7.3-2, And of cource the other Python modules you need

Example python script

#!/usr/bin/python

import sqlite3 as lite
import sys

con = lite.connect('/mnt/sda1/arduino/www/test/ec.db')

with con:
    cur = con.cursor()
    cur.execute("SELECT * FROM Navn")
    rows = cur.fetchall()
    for row in rows:
        print row

Python module installing

In order to keep used disk space as low as possible, few softwares on the Yún support SSL out-of-the-box. Python SSL support is optional and must be manually installed before attempting to install additional modules via easy_install.

For example, in order to install python module "pygeocode", you need to issue the following commands via YunSerialTerminal or SSH

opkg update #updates the available packages list
opkg install distribute #it contains the easy_install command line tool
opkg install python-openssl #adds ssl support to python
easy_install pip #installs pip
pip install pygeocode #installs pygeocode

(original forum topic | last edit : October 13, 2013)

Fixing the Spacebrew installation on the Yún

If you tried to run the Spacebrew examples, you may have noticed that the connection with the server never happens. This is because the Spacebrew scripts that ship with the Yún need to be patched.
Here is an explanation: http://goo.gl/zh1DtL
Here is how to get the latest version of yunSpacebrew on your Arduino:

  1. Download the archive of that repo:
    https://github.com/julioterra/yunSpacebrew
  2. Go through the installation instructions for python and shell scripts:
    https://github.com/julioterra/yunSpacebrew#installing-linino-python-and-shell-scripts

(Original forum topic | last edit : November 24, 2013)

Yun Bootup process

Several people have asked about what happens when you apply power to the Yun or use the Yun Reset button. This can be confusing mainly because the Leonardo part comes up very quickly and the OpenWrt-Yun part takes around 60 seconds.

You can watch what happens by loading the Yun serial terminal sketch via USB, openning the serial monitor and pressing the Yun Reset button near the LEDs. You can interact with the boot process if bad things happen so you can fix them, without this you could end up "bricked" with no way to "unbrick".

The first opportunity for interaction is to stop uboot when you see "Hit any key to stop autoboot: " so you can flash/boot if the image is bad. It is best to let this go by if your Yun will get to the failsafe prompt, official information on how to restore the image with uboot is here http://arduino.cc/en/Tutorial/YunUBootReflash but as the webpage notes use this a a last resort. Next is the "Press the [f] key and hit [enter] to enter failsafe mode" prompt, failsafe mode allows you to fix things that are messed up in the linux system configuration, if you disabled the console in inittab you can run mount_root in failsafe and then re-enable it here. Once you get thing fixed you can execute reboot -f or just power cycle the Yun to boot up. Next is the console started in inittab which allows you access if you lose network connectivity. This should be available unless you disabled it in inittab and most things can be fixed here.

While you could run for years without needing these things they are nice to have, kinda like airbags in a car, if you need them you are VERY glad you had them.

(Original forum topic | last edit : November 24, 2013)

My Yún doesn't boot anymore! How can I restore it?

If you cannot even reset the Yún with its reset button, you may have filled your flash and linux is not even able to start. In this case, you need to

  • In the Arduino development environment, upload the YunSerialTerminal example (in Bridge menu) via usb
  • Press the "Serial Monitor" button and then select "newline" at the bottom right of the window
  • Reset the AR9331 (white button near the leds)
  • Wait until you read "Press the [f] key and hit [enter] to enter failsafe mode": do that, press f and hit enter (remember to first click inside the textbox at the top of the window)
  • Type cd /usr/bin
  • Type ./reset-to-factory-anyway (this will reset the Yún to factory settings)

Now the Yún should restart and you should be able to configure it like you first got it out of the box.

How can I connect to a shared linux drive? (cifs)

If you have a computer that shares a drive in the cifs (Common Internet File System) format you can access it from your yun.

to do so you need to install some packages:

opkg update 
opkg install  cifsmount
opkg install kmod-fs-cifs

If you have your share encrypted there may be a need for more packages.

Once these packages installed you can mount a drive Make sure you mount on an existing folder. For instance like:

mkdir -p /mnt/local
mount.cifs //192.168.0.20/Shares /mnt/local -o guest,sec=ntlm

If you want to mount password protected drive at boot time you must supply the name and password to avoid a request for it.

mkdir -p /mnt/local
mount.cifs 192.168.1.205:/linksys /mnt/nas -o user=XXXX,pass=YYYY,sec=ntlm

note that you can replace the ip address with a server name when your yun is able to ping to the servername.

(Original forum topic | last edit : October 26, 2013)

I can't connect to my Yún via SSH

Note: The proposed solution is using a Mac/Unix command line

You get scary “POSSIBLE DNS SPOOFING” or "REMOTE HOST IDENTIFICATION HAS CHANGED" warnings when trying to connect via ssh. This can happen when you fiddle a lot with renaming/resetting your Arduino Yún.

In that case, sudo ssh root@arduino won't work, and your correct password won't be accepted: (You'll keep getting the message: Sorry, try again).

The error tells you to Add correct host key in ~/.ssh/known_hosts to get rid of this message. Actually, the solution is to remove the incorrect keys then try to reconnect.

  1. Back up: $ cp ~/.ssh/known_hosts ~/.ssh/known_hosts.bak
  2. Open your known_hosts file in vi (or use your prefered text editor): vi ~/.ssh/known_hosts
  3. Delete the lines that start with "arduino" and any name you once gave to your Yún: In vi, type dd to delete the current line.
  4. Save and quit: :wq
  5. Connect again: ssh root@arduino or ssh root@[name or IP of your Arduino]
  6. You should be told that the authenticity of the host cannot be verified and asked (twice) "Are you sure you want to continue connecting": type yes

Yun https self-signed certificate, problem and workaround

Yun comes with a uhttpd version that offers https secure connection with a self signed certificates system. At yun's every boot, a certificate and a key will be generated and signed for increase security.

If you use a pc's browser for navigate to your Yun's web configuration page (or for other web pages that you created) over https, you will be advised that the yun's https certificate was signed by itself and you can choose if you want to continue or stop the connection. You can also install the https certificate as user trusted certificate so it wont be prompted in future again.

"Now, the problem:"

If you want to connect to your Yun via https on devices like an android tablet / phone, you must choose continue the connection every times... You can't install the certificate as trusted because Android never trust a self signed certificate.

"Bigger problem:"

If you think to build your Android App to connect to your Yun to control it by remotely, your App will stop the connection because the https certificate was self signed and will not be prompted any user choice!

"The solution:"

- If you own a domain and you use it for yun's connection, you can buy a https certificate that will be trusted by your devices because signed from a trusted root Certificate Autority, or you can be your root Certificate Autority and sign your certificate. Android will advise you that the certificate was signed by unknow CA root, but this time, on Android it is possible to install a user trusted CA root ! Once the root CA was installed on your devices, the certificate signed by your CA will be trusted ever.

"How to (via SSH):"

- have a backup of every file that you will edit ;)

- install openssl-util on your Yun:

opkg update
opkg install openssl-util

- edit the config file /etc/ssl/openssl.cnf : in the [ ca ] section assign your CA name (example: default_ca = CA_Yun)

- edit the next section with the CA's name that you choosed (example: [ CA_Yun ] )

- edit in this section the path attribute (example: dir = ./YunCA )

- edit where necessary the attributes like "CommonName", "Country" ecc..so you will do less work after!

- for increasing the expiration time and the security level of your certificate you can edit the followings:

default_days = 3650
default_bits = 2048

- save your config file and sure that the following directories and files exists (if not, creates it):

/etc/ssl/certs (directory)
/etc/ssl/private (directory)
/etc/ssl/YunCA (directory)
/etc/ssl/YunCA/index.txt (blank file)
/etc/ssl/YunCA/serial (a file with: '01' written inside, without the quotes and without extension)

- again from ssh do this for create your CA, your key and certificate files and sign it by the CA (some of this commands can ask to user to insert a passphrase and to confirm some attributes like "CommonName", "Country", ecc..):

openssl genrsa -des3 -out private/ca.key 2048
openssl req -new -x509 -key private/ca.key -out ca.crt -days 3650
openssl genrsa -des3 -out private/server.key 2048

- now create a "unsecure" key file so the uhttpd can starts without ask the password every time

openssl rsa -in private/server.key -out private/server.key.unsecure			
openssl req -new -key private/server.key -out server.csr
openssl ca -policy policy_anything -keyfile private/ca.key -cert ca.crt -in server.csr -out certs/server.crt

- delete uhttpd.crt and uhttpd.key from /etc directory

- edit the uhttpd config file /etc/config/uhttpd :

list listen_https       0.0.0.0:443
option cert             /etc/ssl/certs/server.crt
option key              /etc/ssl/private/server.key.unsecure
#config cert px5g

- remove the delete_uhttpd_cert file from /etc/init.d/ otherwise your https certificate will be deleted at yun's boot

- restart the uhttpd server:

/etc/init.t/uhttpd restart

- Now you can get the CA.crt from /etc/ssl directory and put on your devices to install it as Trusted Root CA. On different Android versions, the way can be different but normally you can go to Security Option in the Configuration menu and select "Install certificate from SD card".

- After select the CA.crt file, you can see it listed in "Trusted Credentials" under the "User" tab.

- Reboot your tablet / phone and enjoy your secure connection!