Arduino Yun for Intermediate Arduino Users:
Using the Onboard Linux Computer to Communicate with Other Computers and the Internet
Tutorial created for OSCON 2014
1:30pm Sunday, 07/20/2014
Link on OSCON schedule
- 1 Please prepare for this tutorial before you arrive:
- 2 Arduino Yun Overview
- 3 Selected Yun details
- 4 Configuring your Yun over WiFi
- 5 Configuring your Yun over wired ethernet
- 6 Basic examples
- 7 Bidirectional Server Client exercise
Please prepare for this tutorial before you arrive:
- 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
- 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.
- Participants must have a laptop
- Participants must install Arduino 1.6.4 or later from Arduino
Arduino Yun Overview
Selected Yun details
- Linux distribution is OpenWrt, so almost anything that’s true for OpenWrt is true for the Yun. OpenWrt Technical Reference
- Serial1 (pins 0 and 1) of Arduino environment is connected to console of the Linux environment and so can’t be used otherwise
- No built in 5V regulator, so Vin must never be above 5V. 3.3V generated internally
- Best to use microSD card or thumb drive for saving data, scripts, web pages, etc.
- Individual resets for WiFi, Linux, 32U4
- 32U4 reset requires 2 clicks
- WiFi 3 options
- <5 seconds: Restart WiFi
- >5 and <30: Reconfigure WiFi
- >30: Reset OpenWrt-Yun to default state
Configuring your Yun over WiFi
- Yun to laptop with USB cable
- Access the Linux console from the Serial Monitor by uploading the YunSerialTerminal example:
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.
- 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:
- Press and hold the button labelled “WLAN RST” for at least 30 seconds.
- 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.
- Verify that the Yun is now an access point by typing:
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.
- Find your Yun’s MAC address by typing:
- 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
- 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.
- In your web browser, browse to http://arduino.local
- When asked, the password is arduino
- Congratulations! You are connected to your Yun
Configuring your Yun over wired ethernet
- Yun to laptop with USB cable
- Yun to network with Ethernet cable
- Access the Linux console from the Serial Monitor using the YunSerialTerminal example:
- 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:~#
- Get the IP address of the wired Ethernet
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:
Make note of this IP address as it is the way you will access your Yun
- Open a web browser and browse to that IP address. Enter password (arduino), click LOGIN, then click CONFIGURE
- Change YUN NAME to e.g. YunMShiloh. I suggest you leave the password as is.
- Deselect CONFIGURE in CONFIGURE A WIRELESS NETWORK
(Wireless network does not allow peer-to-peer)
- At REST API ACCESS select Open
- Click Configure and Restart (Might take a couple of minutes to reboot)
- Close the browser window
- 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 email@example.com 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. firstname.lastname@example.org'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).
- 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:
To exit ping type <CTRL> C
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.
Execute commands on the Linux side, from a sketch.
File -> Examples -> Bridge -> Process
Create an HTTP client that connects to the internet and downloads content.
File -> Examples -> Bridge -> HttpClient
Create a web server, and serve data from the IO pins
(requires microSD card)
File -> Examples -> Bridge -> TemperatureWebPanel
More on the Bridge library
Bridge library reference
Bridge tutorials: links under Bridge Libraries on the tutorial home page
Bidirectional Server Client exercise
- Get code from github
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
- Create a Temboo account
- Create an application name/key pair on Temboo
- Create unimportant Gmail account
- Open example
File -> Examples -> Bridge -> Temboo -> SendAnEmail
- Enter Gmail account details and destination address in SendAnEmail sketch. Note that GMAIL_USER_NAME must be full email address e.g. email@example.com
- Click on second tab (TembooAccount.h)
- Enter Temboo account and application name/key pair
- Adafruit tutorial
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
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.