Sunday, October 18, 2015

How to connect a PC to the Arduino Yun

Introduction


The Arduino Yun board is a relatively new member of the Arduino family.
 

It is similar to a Leonardo board ( i.e. An Arduino board with a Atmega32 processor) except that it has an additional processor (Atheros AR9331) running Linux (OpenWRT) , a microSD disk connector and many additional interfaces.


The Arduino Yun has many interfaces (not counting the usual Arduino connectors). There is a USB device micro type B connector, there is a USB host (Type A Connector). There is a wired Ethernet and there is also a possibility to connect via Wifi.
 

The USB Device Connector

 


This connector is the « standard » connector that we are used to see on every Arduino board except that it is a micro connector (like the one found on a smart phone) instead of a standard Type B connector.

As on an ordinary Arduino UNO you can use this connector to power the Arduino Yun board.
From the PC connected to the Yun board, this USB port appears as a standard COM port



As usual with Arduino boards, you may use this COM port to transfer a compiled sketch to the board and, a running sketch may use it to communicate using the well known serial class www.arduino.cc/en/Reference/Serial
 
 
 
 

The USB Host connector

 
 


This is a full size type A connector for connecting devices like USB keyboards, or mouse to the Yun. I have not yet experimented with it So I cannot say much about it. Just note that this port is connected to the Atheros AR9331 so it is controlled from LINUX. Which does not mean that the Atmega processor cannot acces it indirectly by going through the bridge that connects the 2 processors together.
 

The Wired Ethernet

 
 
 
Note: when using the Ethernet connection, don't forget to power your Yun board (if you don't use PoE) either via the USB micro connector or via the Vin pin (be careful with polarity an voltage).
Once the board is connected you need to know its IP address. The easiest way is to ask to your DHCP server/router the list of connected devices.
But you can also retrieve et IP address with this simple sketch (that you will have to upload via USB).
 

#include <Process.h>
void setup() {
// Initialize Bridge
Bridge.begin();
// Initialize Serial
Serial.begin(9600);
// Wait until a Serial Monitor is connected.
while (!Serial);
Process p; 
p.begin("ifconfig");
p.addParameter("-a"); // -a list all IP ports. Replace it by eth1 if you only
// want the wired Ethernet
p.run(); // Run the process and wait for its termination
while (p.available()>0) {
char c = p.read();
Serial.print(c);
}
Serial.flush();
}
void loop() {
//do nothing
}

The script result lista all the IP adresses used by the Yun board.





Note: Arduino Yun assigns the wired ethernet to eth1 and not eth0.


You can then connect to the Arduino Yun using any web browser



The password is « arduino »

An arduino sketch has no acces direct to the Ethernet port. To get acces to it You need to use the « bridge » object.


You may connect to the Linux terminal running on the Atheros AR9331 by using a ssh connection (on windows, the most popular ssh terminal is Putty (available on http://www.putty.org/)


The login is root and the default password is « arduino »

 
This gives you access to a surprisingly complete and powerful Linux computer.
It is possible to upload the sketch using the Wired Ethernet. To do that you need to install the « Bonjour » service and open the UDP port 5353 in your firewall. I have not tried it because I am happy with the USB transfer and I already have much too many services running on my PC.
 

 The Wifi

The Arduino YUN is by default a Wifi access point (i.e. a hotspot) This means that it creates a network on which you can connect your computer.
This is useful to reach the newly bought Yun board wifi but you will probably want to reconfigure it as a wireless adapter that connects to your Wifi network.
To do that connect your computer or any Wifi capable terminal (even a smartphone is ok) to the Yun Wifi network.

Use a browser to access the Yun board (it's address is 192.168.240.1)
The password is « arduino »
you can then configure the Wifi port so that it connects to your network

Once it is done the Wifi behave as the wired Ethernet (see explanation above)
Note : it is possible to turn off the Wifi. You may want to do that for security reasons. The code to execute to turn off the Wifi is quite complex. It is available is https://gist.github.com/sgk/6641198