Arduino Tutorial: Networking with the Arduino Yun (deprecated)

Arduino Yun for Intermediate Arduino Users:
Using the Onboard Linux Computer to Communicate with Other Computers and the Internet

Arduino Tutorial: Networking with the Arduino Yun (deprecated)

Michael Shiloh
Arduino
m.shiloh@arduino.cc

Tutorial created for OSCON 2014
1:30pm Sunday, 07/20/2014
Link on OSCON schedule

Please prepare for this tutorial before you arrive:

  1. Participants must be comfortable with the Arduino hardware and software, know how to attach sensors and LEDs to an Arduino, and know how to write programs for Arduino
  2. An Arduino Yun, and an Arduino component kit (breadboard, wires, assorted sensors, LEDs, motors, speakers, etc.) is required in order to participate. We have sourced the kit and parts for you, and the cost of this kit is $93. There will be an additional charge of $93 when you register for this tutorial. You will be provided with the kit onsite at the conference with proof of registration.
  3. Participants must have a laptop
  4. Participants must install Arduino 1.6.4 or later from Arduino  

Arduino Yun Overview

BridgeBlockDiag

Selected Yun details

  1. Linux distribution is OpenWrt, so almost anything that’s true for OpenWrt is true for the Yun. OpenWrt Technical Reference
  2. Serial1 (pins 0 and 1) of Arduino environment is connected to console of the Linux environment and so can’t be used otherwise
  3. No built in 5V regulator, so Vin must never be above 5V. 3.3V generated internally
  4. Best to use microSD card or thumb drive for saving data, scripts, web pages, etc.
  5. Individual resets for WiFi, Linux, 32U4
    1. 32U4 reset requires 2 clicks
    2. WiFi 3 options
      1. <5 seconds: Restart WiFi
      2. >5 and <30: Reconfigure WiFi
      3. >30: Reset OpenWrt-Yun to default state
  6. Resources
    1. Arduino Yun product page
    2. Arduino Yun Getting Started Guide
    3. Excellent set of community curated Yun notes
    4. The Bridge library reference

Configuring your Yun over WiFi

  1. Connect:
    1. Yun to laptop with USB cable
  2. Access the Linux console from the Serial Monitor by uploading the YunSerialTerminal example:
     File->Examples->Bridge->YunSerialTerminal

    Remember to select “Yun” in “Tools->Board”.

    In the following steps, all the lines you type are in the top line of the serial monitor.

  3. Open your Serial Monitor and select New line line ending and 57600 baud (down near the bottom right corner). Put your cursor in the top line and press your <ENTER> key and you should see a prompt, and possibly a banner:
    BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
     _______ ________ __
     | |.-----.-----.-----.| | | |.----.| |_
     | - || _ | -__| || | | || _|| _|
     |_______|| __|_____|__|__||________||__| |____|
     |__| W I R E L E S S F R E E D O M
     -----------------------------------------------------
    
    
    root@Arduino:/#

    Wait until you see the prompt:

    root@Arduino:/#
    
  4. Press and hold the button labelled “WLAN RST” for at least 30 seconds.
  5. Watch the messages in the console and wait until it finishes booting. You will have to put your cursor in the top line and press enter again to see the prompt and  the banner.
  6. Verify that the Yun is now an access point by typing:
    iwconfig <ENTER>

    You should see something like this:

    o        no wireless extensions.
    
    eth1      no wireless extensions.
    
    wlan0     IEEE 802.11bgn  Mode:Master  Tx-Power=16 dBm   
              RTS thr:off   Fragment thr:off
              Power Management:off
              
    eth0      no wireless extensions.
    

    The important thing is that wlan0 is in “Master” mode.

  7. Find your Yun’s MAC address by typing:
    1.  ifconfig <ENTER>
    2. Look for the line that says:
       wlan0 Link encap:Ethernet HWaddr 90:A2:DA:F3:02:19

      the code following HWaddr is your Yun’s MAC address. In this case it’s

      90A2DAF30219
  8. Using your laptop’s network manager, connect to the network with a name like Arduino Yun-90A2DAF30219. If you see more than one Arduino Yun, look for the one with your Yun’s MAC address.
  9. In your web browser, browse to http://arduino.local
  10. When asked, the password is arduino
  11. Congratulations! You are connected to your Yun

Configuring your Yun over wired ethernet

  1. Connect:
    1. Yun to laptop with USB cable
    2. Yun to network with Ethernet cable
  2. Access the Linux console from the Serial Monitor using the YunSerialTerminal example:
     File->Examples->Bridge->YunSerialTerminal
  3. Open your Serial Monitor and select New line line ending. Press enter and you should see a prompt, and possibly a banner:
    BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
     _______ ________ __
     | |.-----.-----.-----.| | | |.----.| |_
     | - || _ | -__| || | | || _|| _|
     |_______|| __|_____|__|__||________||__| |____|
     |__| W I R E L E S S F R E E D O M
     -----------------------------------------------------
    
    
    root@MShilohServer:~#
  4. Get the IP address of the wired Ethernet
    ifconfig

    Look for the section that is NOT lo (loopback) and NOT wlan (wireless). It’s most likely eth1. Look for the line that starts with:

    inet addr:192.168.1.145

    Make note of this IP address as it is the way you will access your Yun

  5. Open a web browser and browse to that IP address. Enter password (arduino), click LOGIN, then click CONFIGURE
    1. Change YUN NAME to e.g. YunMShiloh. I suggest you leave the password as is.
    2. Deselect CONFIGURE in CONFIGURE A WIRELESS NETWORK
      (Wireless network does not allow peer-to-peer)
    3. At REST API ACCESS select Open
    4. Click Configure and Restart (Might take a couple of minutes to reboot)
    5. Close the browser window
  6. Test by logging in to your Yun via ssh. (Linux: Terminal Mac: Applications -> Utilities -> Terminal. Windows: Download putty). Your user name is root. Accept key and enter your password:
    $ ssh root@192.168.1.145
    The authenticity of host '192.168.1.145 (192.168.1.145)' can't be established.
    RSA key fingerprint is 55:32:43:18:a6:99:99:55:96:74:dc:b5:3e:24:e2:14.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.1.145' (RSA) to the list of known hosts.
    root@192.168.1.145's password: 
    
    
    BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    
     _______ ________ __
     | |.-----.-----.-----.| | | |.----.| |_
     | - || _ | -__| || | | || _|| _|
     |_______|| __|_____|__|__||________||__| |____|
     |__| W I R E L E S S F R E E D O M
     -----------------------------------------------------
    
    
    root@MShilohServer:~#
    
    

    Verify that the computer name is the one you set (in my case MShilohServer).

  7. Test that you can see your neighbor’s Yun. Ask your neighbor for the IP address of their Yun, and then use ping to verify that you can see it:
     ping 192.168.1.107

    To exit ping type <CTRL> C

Basic examples

Bridge class

Read inputs and control outputs from a web browser. Upload this sketch:

 File -> Examples -> Bridge -> Bridge

Control your pin 13 LED by visiting, with your browser, (replace IP address with yours):

http://192.168.1.145/arduino/digital/13/0
or
arduino.local/arduino/digital/13/0

Read an analog input by visiting:

http://192.168.1.145/arduino/analog/0
or
arduino.local/arduino/analog/0

More details in the bridge tutorial

Optional exercise: Add some LEDs and sensors, then read and control them from a web browser.

Process class

Execute commands on the Linux side, from a sketch.

File -> Examples -> Bridge -> Process

Process tutorial

HttpClient class

Create an HTTP client that connects to the internet and downloads content.

File -> Examples -> Bridge -> HttpClient

HttpClient tutorial

Create a web server, and serve data from the IO pins

(requires microSD card)

File -> Examples -> Bridge -> TemperatureWebPanel

TemperatureWebPanel tutorial

More on the Bridge library

Bridge library reference

Bridge tutorials: links under Bridge Libraries on the tutorial home page

Bidirectional Server Client exercise

  1. Get code from github 

Practical application

Either client or server can be replaced by process written in any other language, as long as it can open a connection to an arbitrary IP address and port

Temboo

  1. Create a Temboo account
  2. Create an application name/key pair on Temboo
  3. Create unimportant Gmail account
  4. Open example
    File -> Examples -> Bridge -> Temboo -> SendAnEmail
  5. Enter Gmail account details and destination address in SendAnEmail sketch. Note that GMAIL_USER_NAME must be full email address e.g. bob@gmail.com
  6. Click on second tab (TembooAccount.h)
  7. Enter Temboo account and application name/key pair
  8. Upload

Time Permitting

  1. Adafruit tutorial
  2. Spacebrew

Arduino Yun Kit of Parts

Cost: $93 (tax included)

  • 1 Arduino Yun
  • 1 USB cable
  • 1 400 point breadboard
  • 30 Jumper wires M-M
  • LED pack (3R, 3G, 3Y at 3mm and 3R, 3G at 5mm)
  • 2 x 10K ohm trimmer potentiometers with knobs (breadboard mount)
  • 10 x 470 ohm resistors
  • 10 x 10K resistors
  • 1 Light dependent resistor (CdS cell)
  • 1 Thermistor
  • 1 DHT11 temperature/humidity sensor (example)
  • 1 Passive piezo element

 

Print Friendly
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

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