Showing posts with label Yún’s. Show all posts
Showing posts with label Yún’s. Show all posts

Hands on: the Arduino Yún’s Bridge

on Friday, September 6, 2013

arduino yun - handson

The other day, we gave you an overview of the Yún’s hardware. Today, we are going to talk about the Bridge library, describing how it facilitates communication between the two processors. The Arduino Yún has two different processors on-board: an Atheros AR9331 running Linino (a customized OpenWRT GNU/Linux distribution maintained by Dog Hunter) linked through its serial port with an Atmel ATMega32U4 (the same processor as the Leonardo).
The Bridge concerns itself with communication between these two parts of the Yún.

The Bridge is made of two different parts
One part, written in Python, runs on the GNU/Linux processor and has three functions:

  1. it executes programs on the GNU/Linux side, when asked by Arduino.
  2. it provides a shared storage space, useful for sharing data like sensor readings between the Arduino and the Internet
  3. it receives commands coming from the Internet and passes them directly to the Arduino

The other part of Bridge is the library that runs on the 32U4. The library allows you to access the Linino parts of Bridge through your sketches.

The awesomeness of the Bridge
With the Bridge you can do some awesome things by communicating between the 32U4 and the AR9331 processors. Some examples could be commanding and controlling your sketch over the internet from a remote location, accessing remote APIs to get data for your sketch to process, or executing programs or scripts too complex to write in an Arduino sketch.

For example, if your shop is on the other side of the house, and you wanted to know if it was comfortable enough to work in there, you can connect a LDR sensor and thermistor to your Yún, which is also connected to your home wireless network. Your sketch can access the board’s shared storage to publish the readings every second to a webpage running on the AR9331. By accessing the URL http://arduino.local/data/get you can call up those readings, letting you know if it’s bright enough but not too hot to get to work on your next project.

Your sketch could also store the sensor readings on a Google Drive spreadsheet or publish them on Facebook. The Temboo library relies on the Bridge to access all the internet based services and APIs provided by Temboo.

Using Bridge, you would no longer need to upload a new version of a sketch to change text on an LCD screen: your sketch can use the shared storage to read the text to display, changing it remotely from a browser using REST based calls. If the text to be displayed is identified by the label “lcd_text”, accessing the URL http://arduino.local/data/put/lcd_text/Hello%20World will show “Hello World” on the LCD.

Finally, you can send your own command to your sketch remotely. You can create a firmata-like access to every single pin of the board, so that calling URL http://arduino.local/arduino/digital/13 will report the current state of pin 13, while http://arduino.local/arduino/digital/13/1 will turn it on. We’ve actually made such a sketch as part of the examples: you’ll find it in the upcoming Arduino IDE release.

Here’s one of the examples that come with the library, the TemperatureWebPanel. It gets the current reading of a temperature sensor and displays it on a web page in your browser. It demonstrates a number of Bridge’s more advanced features like Process (for executing Linux processes), the YunServer and YunClient (for server and client communication), and the ability to upload additional files for serving up to connected clients.

Setup
In “setup()”, start the Bridge with “Bridge.begin()”. This ensures the Python part of the Bridge on the GNU/Linux processor is up & running. Next, toggle pins to use a TMP36 temperature sensor so that it can be plugged directly into the board’s headers. YunServer is part of Bridge that enables Linino to pass URLS formatted with “/arduino/” to the 32U4. To listen to commands from connected clients, you need to start the server by calling “server.begin()”. “server.listenOnLocalhost()” forwards all local server communication to port 5555. Process allows you to call Linux commands through your sketch. Here, you’ll execute the shell command “date” by calling “startTime.runShellCommand(“date”)”, which will report the date and time the sketch started running.

Loop
In “loop()”, the sketch listens for incoming client connections (requests from the Internet) by creating an instance of YunClient. You can read incoming commands with “client.readString()”. If a connected client sends the command “temperature”, the Bridge executes the “date” command on GNU/Linux to report the time of the reading, then reads the sensor on A1 and calculates the temperature. The date and temperature information is combined into a HTML formatted string and sent back as a response.

Browser
Sketches for the Yún can now contain all the files needed to create a web application that can talk to your sketches through a browser. In the TemperatureWebPanel directory on your computer, there is another folder named “www”. This folder contains a basic webpage and a copy of zepto.js, a minimized version of jQuery.

You need a micro SD card plugged in to your Yún with a folder named “arduino” at the root. Inside the “arduino” folder, there must be a directory called “www”. You need to upload the sketch via WiFi to transfer the contents of the local “www” folder. You cannot transfer files via USB. Once uploaded, you can open your favorite browser and go to http://arduino.local/sd/TemperatureWebPanel. There you’ll see the browser reporting back the sensor readings, with the time information and total number of requests.

The browser calls the url http://arduino.local/arduino/temperature in the background. URLs that start with “/arduino/” are special: everything from the “t” of “temperature” is sent to the sketch via Bridge. You can send any command you like, as long as your sketch understands them.

—————
The next post about the Yún will focus on Temboo and how the Arduino Yún can easily grab all sorts of data and interact with tons of web-based services. Stay tuned!



View the Original article

Let’s explore Arduino Yún’s unique features – Hardware review

on Monday, September 2, 2013

Arduino Yún

As announced a few days ago, the newest addition to the Arduino family, the Arduino Yún, will be available starting September 10. This is the first in a series of posts that will describe some of the Yún’s unique features. Today, we’ll focus on the hardware.

———————–

The Yún is unique in the Arduino lineup, as it has a lightweight Linux distribution to complement the traditional microcontroller interface. It also has WiFi and Ethernet connections on board, enabling it to communicate with networks out of the box. The Yún’s Linux and Arduino processors communicate through the Bridge library, allowing Arduino sketches to send commands to the command line interface of Linux.

Introduction
The Arduino Yún has the same footprint as an Arduino Uno but combines an ATmega32U4 microcontroller (the same as the Leonardo) and a Linux system based on the Atheros AR9331 chipset. Additionally, there are built-in Ethernet and WiFi capabilities. The combination of the classic Arduino programming experience and advanced internet capabilities afforded by a Linux system make the Yún a powerful tool for communicating with the internet of things.

The Yún’s layout keeps the I/O pins the same as the Arduino Leonardo. As such, the Yún is compatible with the most shields designed for Arduino.

With the Yún’s auto-discovery system, your computer can recognize boards connected to the same network. This enables you to upload sketches wirelessly to the Yún. You can still upload sketches to the Yún through the micro-USB connector just as you would with the Leonardo.

Connectivity
The Yún has two separate network interfaces, a 10/100 Mbit/s Fast Ethernet port and a IEEE 802.11 b/g/n standard compliant 2.4GHz WiFi interface, supporting WEP, WPA and WPA2 encryption. The WiFi interface can also operate as an access point (AP). In AP mode any WiFi enabled device can connect directly to the network created on the Yún. While a Yún in this mode can’t connect to the internet, it could act as a hub for a group of WiFi enabled sensors.

Historically, interfacing Arduino with web services has been challenging due to memory restrictions. The Yun’s Linux environment simplifies the means to access internet services by using many if the same tools you would use on your computer. You can run several applications as complex as you need, without stressing the ATmega microcontroller.

To help you develop applications that can connect to popular web services, we have partnered with Temboo, a service that simplifies accessing hundreds of the web’s most popular APIs. A Temboo library comes with the Yún, making it easy to connect to a large variety of online tools. Check out their website for the full list of services they offer.

Connection between the two processors
The Yún’s Bridge library enables communication between the two processors, connecting the hardware serial port of the AR9331 to Serial1 on the 32U4 (digital pins 0 & 1). Another post will describe the library in greater depth. The serial port of the AR9331 exposes the Linux console (aka, the command line interface, or CLI) for communication with the 32U4. The console is a means for the Linux kernel and other processes to output messages to the user and receive input from the user. File and system management tools are installed by default. It’s also possible to install and run your own applications using Bridge.

The ATmega32U4 can be programmed from the AR9331 by uploading a sketch through the Yún’s WiFi interface. When connected to the same WiFi network as your computer, the board will appear under the “Port” menu of the Arduino IDE. The sketch will be transferred to the AR9331, and the Linux distribution will program the ATmega32U4 through the SPI bus, emulating an AVR ISP programmer.

Power consideration
The Yún can be powered through the micro-USB connector, the Vin pin, or the optional Power Over Ethernet (POE) module. When powering the board though the Vin pin, you must supply a regulated 5VDC. There is no on-board voltage regulator for higher voltages.

Linux OS specifications
The Yún runs a version of the OpenWRT Linux distribution called Linino. The on-board 16MB flash memory that contains the Linux image has a full python installation and package manager you can use to install additional software.
The AR9331 has 64 MB of DDR2 RAM available, providing the resources to perform complex tasks like running a web server or streaming video from a webcam.
You can expand the storage memory by adding a micro-SD card or a USB pen drive. By including a directory named “arduino” at the root level of the storage device, it will be automatically recognized by the Yún.

USB Host
The Yún has a USB host port connected to the AR9331. You can connect USB peripherals like webcams, memory sticks, or joypads to this input. Generally, Linux has drivers included for the more common devices like mass storage or mice and keyboards. For more specific devices like webcams, you will need to refer to the device specifications to find the appropriate driver. As the USB port is connected to the Linux processor, it’s not directly accessible from sketches on the 32U4.

—————-

The next post about the Yún will focus on the Bridge library, describing how it facilitates communication between the two processors. Stay tuned!



View the Original article