Adding Internet connectivity to Arduino boards and apps with the YUN Shield

By on December 15, 2015
Pin It

What if we have already developed an Arduino application and we want internet connectivity for it?
Yun shield is the answer.

 

Yun shield provides Internet connectivity for all Arduino boards. It features the same connectivity functions implemented on Arduino Yun. Yun shield runs the OpenWrt GNU / Linux operating system, specially designed to manage internet connectivity. It’s the same on Arduino Yun and is commonly used by open source software equipped Access Points. Well, why Yun shield and not Arduino Yun itself? Simple, the shield can be connected to different Arduino boards, giving the opportunity to connect online our already developed applications, offering them new interoperability and remote applications. 

 

Fig1

 

Obviously it is possible to use it in new applications for which you want to adopt a different module than Arduino Leonardo. Among the Arduino boards compatible with Yun shield, we have Arduino Uno, Duemilanove / DIECIMILA, Arduino Mega and, of course, Arduino Leonardo, as well as several others. Another pleasant surprise is the ability to adapt both to 5V and 3.3V port voltage levels according to the different modules it is matching to. Among other peculiarities, a WiFi antenna is included in the package, helping you to establish particularly stable WiFi connections in various conditions.

 

System Architecture

In the block diagram, you can see how Yun shield connects to hosting boards. The host board powers the Yun shield through the VIN pin. It uses both the UART connection (Bridge library) to communicate with the module it is inserted on and the SPI connection to program Arduino, with its IDE connected via TCP / IP.

The “heart” of Yun shield is based on Atheros AR9331 processor, widely used in WiFi connectivity solutions (also in Arduino Yun). It has various interfaces such as Ethernet, USB, UART, and various GPIO peripheral devices. Supports 802.11b / g / n 2.4 GHz WiFi standard up to 150Mb. As said before, the operating system is OpenWrt, a GNU / Linux open distribution especially dedicated to WiFi connectivity and routing. RJ45, WiFi, USB Host and Failsafe are connected directly to the Dragino HE module. Dragino HE uses UART and SPI ports to communicate with Arduino. Yun shield is compatible with 3,3V and 5V powered Arduino boards. 

To set the right port working voltage, you need to act on SV1 jumper. The SPI interface is used only to load a sketch from the IDE to the board. Once you finished loading the sketch, the SPI interface is released and can be used to connect to other devices. The UART interface is locked by the Bridge library. As for Arduino Yun, even on Yun shield the Bridge lib is the heart of the communication link between the Atheros AR9331 processor (running OpenWRT) and Arduino microcontroller, so the UART interface can not be used by other applications. 

The working principle of the Yun shield – Arduino microcontroller link is fully described in the book “Discovering Arduino Yun”.  

 

Specifications

  • CPU: ATHEROS AR9331 processor, 24K MIPS@400MHz;
  • RAM: 64MB;
  • Flash Memory: 16MB;
  • Operating System: customized Open Source OpenWrt;
  • Power supply: 5V from VIN Arduino pin;
  • An RJ45 Ethernet 10M / 100M;
  • WiFi: 2.4Ghz, 802.11 b / g / n, 150M;
  • I-PEX connector to connect the internal antenna included in the package;
  • A USB 2.0 host connector, used to connect a USB stick or a 3G dongle;
  • A multifunction button (labeled Failsafe);
  • Compatible with the UART and SPI 3.3V and 5V voltage levels.

 

LEDs

On the shield, there are four LEDs with the following functions:

  • PWR: Power LED. It lights up when the shield is on;
  • LAN: is on or flashing to indicate the presence of a network connection;
  • WLAN: Indicates a working WiFi connection;
  • SYS: Indicates the presence of an USB memory. When lit, it indicates that the folders on the USB mass storage device are mounted on / mnt, /mnt/sd and /www/sd respectively.

 

Fig2 

 

Multifunction button

On Yun shield there is only one button, labeled “Failsafe”, to manage the reset and restore operations, which may be necessary sometimes. When the shield is on, after the boot process is over, holding pressed the failsafe button for 5 seconds resets to factory settings the WiFi chip configuration. 

Holding it for 30 seconds sets the whole shield to factory setting. The third use of the failsafe button is to initiate the board recovery function in case of wrong firmware upgrade. This process is very complex and too long to describe it in this article. The recommendation that we can give is to upgrade the firmware carefully to avoid being with the shield unusable. In any case the “rescue” instructions can be found at http://www.geeetech.com/wiki/index.php/YUN_SHIELD.

 

Power modes

A major issue when using Yun shield is how the power it. The shield is powered through GND and VIN pins. The recommended way is to use these pins. The Dragino HE module, which is the heart of this shield, requires a 200 mA current at full load, so it is a best practice to connect it to the pins said before rather than overheating the 5V LDO (low drop out) power supply module. In this configuration, it is better to power Arduino through its DC connector and not by the USB port. Be careful to use an external power supply providing more than 7V input voltage.

 

 1213_Schema

 

Using the Yun shield with Arduino modules

To take advantage of all the opportunities offered by Yun shield we need to do a preparatory work both for the boards that we want to connect and to adapt the Arduino IDE to work with different combinations of modules. 

The Yun shield uses the SPI port to load sketches and the UART serial port to communicate, using the Bridge library, with the microcontroller it is linked to. For further information on Bridge lib refer, once again, to the quoted paper. In order to establish the communication link between shield and module you must check the following:

  • The Arduino module must be powered by the DC connector and not by the USB connector;
  • The jumper of SPI and UART voltage levels must be set properly;
  • The right “shield – Arduino module” coupling must be properly configured in IDE settings (we’ll see later on how to do it).
  • The UART and SPI ports must not be used by other programs;
  • Make sure that the “Linux Console / Arduino Bridge” mode is set (in “Sensor >> PowerUART” menu on the configuration tool)

 

 

Connect the shield to Arduino UNO

On Arduino UNO the UART serial connection between mega328P and mega16u2 microcontrollers interferes with the Bridge library functions used to communicate with Yun shield. 

You must disable the UART connection by configuring the microcontroller mega16u2 in “reset”. In practice short-circuit the pins shown in figure with the yellow jumper included in Yun shield package and power the two boards using the DC plug on Arduino UNO. 

 

Fig3

 

Note that with this configuration you can no longer connect Arduino to a pc via the USB port. For programming and debugging, you need to use the WiFi connection by choosing the “Arduino UNO – Dragino Yun” board on the IDE boards list.

 

Connect the shield to Arduino Mega2560

Even in Arduino Mega2560 the UART serial connection between the mega16u2 and Mega2560 microcontroller interferes with the Bridge library. You must disable that connection by configuring the microcontroller mega16u2 in “reset”. 

In practice short-circuit the pins shown in figure  with the yellow jumper included in Yun shield package and power the two boards using the DC plug on Arduino Mega2560. 

 

Fig4

 

Note that with this configuration you can no longer connect Arduino to a pc via the USB port. For programming and debugging, you need to use the WiFi connection by choosing the “Arduino Mega2560 – Dragino Yun” board on the IDE boards list.

 

Configuring Yun SHIELD

The Yun shield has both the WiFi module and the Ethernet LAN interface onboard, which can be used either for an internet connection or for system administration. The Yun shield can operate autonomously: just plug it in to have a network access point. For the first test we chose to mount it on an Arduino Uno, connecting the small antenna included in the kit, setting the Dragino HE jumper configuration to accept a 5V supply voltage and powering it by the Arduino Uno DC “barrel” connector. A 7.5V input voltage is recommended.

 

Fig5

 

At boot time the Yun shield, as default configuration, shows off as an access point with a SSID named “Dragino-xxxxxx”, where “x” stands for the shield MAC address. The first time connection procedure is similar to that required for Arduino Yun. Using a PC with WiFi, connect to the shield WiFi SSID (password not required) then open a browser and type the address 192.168.240.1. This method works perfectly if the PC network card is set to DHCP mode, receiving its address from Yun.

If everything went smooth, the configuration tool LuCI will be open in the browser page (we recommend using HTML5 compliant browsers, like Firefox and Chrome). You can alternatively connect via SSH using tools as Putty, WinSCP or MobaXterm, all instruments whose use has been extensively described in previous posts. Or you can type the shield host name “dragino.local” in browser URL bar: if this does not work, type the shield IP in address as told before (if YUN is our default access point it’s 192.168.240.1). If, instead, we are connected to Yun via a wired network, we must know the IP address assigned by DHCP. 

Failing that, the system has a pre-configured fallback address, 172.31.255.253 with network mask 255.255.255.252 (pay attention to the final 252). This way you can connect the shield with a network cable, setting on your PC the IP address 172.31.255.253 (always with network mask 255.255.255.252). 

 

Fig6

 

Whichever way we connect, we will open the login page of the configuration tool. You access the configuration tool by entering “dragino” that is the password of the only (default) user, “root”. We get the active network interfaces configuration page. This page tells us that the network interfaces are preconfigured and a web server is already installed with an application that allows you to configure those parameters.

 

Fig7

 

Always in the page we see the board WAN IP address (if connected through the network cable), and the WiFi section configuration (by default active and pre-configured as an access point with its own static IP). 

 

Fig8

 

On page top right, we have the buttons to access the three main system configuration sections: “SYSTEM”, “SENSORS” and “UPGRADE”. Click on “SYSTEM”, which will open the SYSTEM configuration section, similar to Arduino Yun and Linino one. On this page we configure the correct Time Zone (Europe / Rome), and select the “Open” check box in the “Rest API Access”. We confirm the settings by clicking the big “CONFIGURE & RESTART” button and wait for the system reconfiguration, which takes a few minutes.

 

Fig9

 

We reconnect to the shield, then click on the “advanced configuration panel” button and enter the administration panel. From the top menu pages, we can access all the different sections.

 

Fig10

 

If we go to “Network” and “WIFI”, click on “Edit” button and scroll down the page we find the section to configure the interface in different modes (Access Point, Client, Ad Hoc, etc.). Other configuration sections allow us to set access security (Firewall), static routing, DHCP and DNS.

 

Fig11

 

So, we have a powerful device that allow us to solve any connectivity demand from a wide range of applications. 

One last thing, let’s try to connect to the board by using the SSH clients PuTTY and WinSCP (for those wishing to learn more about what has been said so far, including most of the configuration pages, refer to the introductory Raspberry Pi articles and the book “My first Linux embedded”). 

 

Fig12

 

We connect to Yun shield IP address, login with “root” user (password “dragino”). So we are sure that SSH server is up and running “just out of the box”.

 

Fig13

 

Firmware Upgrade

We anticipate this section since it is better to update the shield firmware release before starting with our application. The reason is mainly the many changes made ​​to the “SENSORS” section, which had many design changes over the releases. Initially designed to facilitate sensors data collection and processing through dedicated services as Xively, it was then modified to configure the Arduino board type the shield is housed in. 

Firmware versions can be checked at:

http://wiki.dragino.com/index.php?title=Yun_Firmware_Change_Log

The different firmware releases can be downloaded at:

http://www.dragino.com/downloads/index.php?dir=motherboards/ms14/Firmware/Yun/

Before continuing, we recommend to perform the firmware update process very carefully, double-checking every step. Take all the necessary time, the operation takes a long time so be sure to have a stable network connection and a reliable power source.

As a first step, you need to download the firmware. Go to “Download”, click on “Newest Firmware” and finally on “common-build-xxxxxxxx”. Attention: depending on the release, these guidelines may not be completely accurate. In the online folder, we see some firmware images. You have to download the “sysupgrade” (with .bin suffix) version. Download and save it on your PC. 

After, go to shield configuration page and click on “UPGRADE”. On this page, you can select the firmware to use for the update. A recommendation: remove the check mark on “Keep Settings”. 

 

Fig14

 

By doing so, the update has the disadvantage of resetting any pre-existing system configurations, but guarantees from misalignments between the existing configuration and the new version setting files. A misalignment coud “block” the shield after a firmware update. 

With the “Browse” button, select the file you just downloaded. Is it all OK? Recheck. Then click on “Upload Firmware”.

 

Fig15

 

Now let the system completing the update operation, which takes several minutes. Without touching anything, just watch the yellow LEDs on the shield.

They are flashing in various ways. Before trying to reconnect, wait for the LEDs to be turned back stable on. Pay particular attention to the WiFi chip activity led, since this chip is the last to boot up. Done? Is it all OK? Connect back to the shield.

 

Fig16

 

Sensors

The “Sensors” section presents different features depending on the firmware release installed. If you have installed the latest release, opening the page you can select the Arduino model you are connecting to (typically, it is automatically recognized). This is a configuration step not needed on Arduino Yun and Linino, but for the shield it is necessary to correctly configure the settings to be used when uploading the sketch (as MCU type, bootloader, fuse).

 

Fig17

 

A nice feature on this page allows you to upload directly a .hex file. This avoids every time the sketches compilation process and also doesn’t force you to open the IDE just for the uploading. A function in the “SYSTEM >> advanced configuration panel >> Sensor >> Microcontroller” menu allows you to automate the sketch upgrade at every boot. The presence of this setting in different sections of the configuration tool and the frequent release of firmware updates tells us that YUN shield is a growing product, wanting to a proper place in the Internet of Things. Now we can only judge positively this condition.

 

Fig18

 

Programming

The Yun shield, or rather the “shield and Arduino” group is programmed by using the Arduino IDE. First, you need to customize the IDE to have it recognizing and managing the various combinations of modules and shields. 

We have already mentioned that we can download the Arduino Yun IDE from Arduino official site. For our tests, we decided to use the latest version (1.6.3). This release is particularly suitable to be customized through third-party components, making it easy to be used with “compatible” boards and modules. We chose the portable version that requires no installation (.zip file). Just unzip it in a dedicated folder. We create a desktop shortcut to “arduino.exe”. To customize the Arduino IDE we have to download the necessary software from the GitHub repository https://github.com/dragino/modules (where you can download the full .zip library, then unzip it in a folder). Inside the folder, find the “modules-master \ hardware \ YunShield \ sketchbook \ hardware \ YunShield” subfolder and copy it to “Arduino_1_6_3 \ arduino-1.6.3 \ hardware”. 

Connect the PC to the shield by using the WiFi connection, as said before. Run the Arduino IDE. In “Tools >> Listing” menu choose the right configuration, “Arduino Uno – Dragino Yun” in our case. 

 

Fig19

 

Then, under “Tools >> Port”, select the TCP / IP connection that shows the right shield IP address.

 

Fig20

 

If you do not see the connection between shield and PC, open an SSH connection with PuTTY and run the command:

/etc/init.d/avahi-daemon restart

Thus forcing OpenWrt to broadcast its network service availability. If the shield is not detected yet, repeat the command. It may happen that, despite everything, you still do not see the board. In this case, we have to know that the connection daemon uses the 5353 UDP port. The cause of the issue may be a firewall, for example, or the antivirus, or a wrong router configuration, which blocks that port. For those wishing to further deepen this topic, always refer to the book mentioned above. 

 

Fig21

 

Fig22

 

Now, to prove that everything is working properly, we can try to load a sketch. We chose the “Console Read” sketch that allows us to test the “bridge” between Arduino and Yun shield. The sketch is accessible from File >> Examples >> Bridge >> Read Console. Compile and load it as usual, then at the Upload password prompt enter “dragino”. Open the Arduino IDE serial monitor “Tools >> Serial Monitor”. Set the communication speed to 115200 baud. A simple interactive application will be displayed.

 

Fig23

 

From openstore

YUN Shield for Arduino Uno and Arduino Mega

Arduino UNO R3

ARDUINO MEGA2560 REV3

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.

One Comment

  1. Pingback: Adding Internet connectivity to Arduino boards and apps with the YUN Shield – NewsDeck

Leave a Reply

Your email address will not be published. Required fields are marked *