Dragino Yun Shield. Симбиоз Linux OpenWRT и Arduino. Видео.
Всем привет. Этот пост посвящен тому, как можно существенно расширить возможности платформы Arduino за счет соединения с платформой Linux. В принципе, такая платформа уже придумана – это Arduino Yún. Однако есть альтернатива – Dragino Yun Shield. Особенность данной платформы в том, что шилд можно соединять с разными платформами Arduino, например с Arduino Mega. Таким образом мы получаем огромный функционал. С помощью карты флешпамяти можно значитель расширить память Dragino Yun Shield. Полноценный SSH клиент и сервер, FTP, базы данных, почтовый клиент или целый сервер, не сложный в изучении язык Python для скриптов и многое другое становится возможным.
В данном посте я буду публиковать свои видео на эту тему. Внизу вы найдете полезные ссылки.
Варианты электропитания Dragino Yun Shield
Как подключить Dragino Yun Shield к Arduino Mega, как загружать скетч через сетевые порты (по сети), а также работа простейшего скетча который создает файл в системе Linux с помощью команд Arduino Mega при помощи библиотеки Bridge.
Здесь вы можете скачать скетч для проверки работы Dragino Yun shield, описанный в видео: Подключение Dragino Yun Shield к Arduino Mega
Адрес для поля Дополнительные ссылки для Менеджера плат:
http://www.dragino.com/downloads/downloads/YunShield/package_dragino_yun_test_index.json
Установка сервера MySQL на Dragino Yun Shield или ARDUINO Yun (openWRT) и внесение данных в базу с помощью ARDUINO.
Yun Shield
Contents
INTRODUCTION
What is the Yun Shield
The Yun Shield is one of the most powerful shields for Arduino Boards. The Yun Shield is designed to solve the Internet connectivity and storage issue for Arduino Board.
The Yun Shield runs the Open Source OpenWrt system (Same system as runs in Arduino Yun) and it is fully compatible with the Arduino IDE v1.5.4 or later. The Yun Shield is the ideal choice for Arduino Projects which require various internet connections and more storage.
Basically, a Yun Shield + Leonardo equal the official Arduino Yun, but the Yun Shield is more flexible because it can work with other Arduino board such as Uno, Duemilanove, Mega etc. The Yun Shield uses external an wifi antenna which provides stability and the possibility for various configurations and environments.
Hardware version info
Difference between v1.x and v2.x
v1.x and v2.x are both provided , they difference between them are:
- v1.x can be powered by DC or USB port from Arduino, while v2.x can only be powered by DC port.
- v2.x support Micro SD card
- v2.x support two USB host ports, while v1.x only support 1 USB host Port.
For v1.x series
- Yun Shield v1.0 : The first hardware release for the Yun Shield.
- Yun Shield v1.1 : Minor change from v1.0 according to feedback from customers.
- Yun Shield v1.1.6 :
- Add Passive PoE port,Yun Shield can be powered by PoE Injector now
- Change the design to auto works with 3.3v or 5v Arduino. no need to manually select jumper.
- Level Shift is now can output more current. this increase the compatibility with different Arduino boards.
For v2.x series
- Yun Shield v2.3 :
- Add an extra USB port,
- Add Micro SD card slot.
- v2.3 needs more power than the v1.1 in the USB part, so modified the power supply section to let it be powered by a DC adapter only.
- Yun Shield v2.4 :
- Add Passive PoE port, Yun Shield can be powered by PoE Injector now.
- Change the design to auto works with 3.3v or 5v Arduino. no need to manually select jumper.
- Level Shift is now can output more current. this increase the compatibility with different Arduino boards.
Specifications
- Processor : 400MHz, 24K MIPS
- Flash : 16MBytes
- RAM : 64MBytes
- Power Input : 4.75v
23v via Arduino VIN pin
Features
- Open source Linux (OpenWrt) onboard
- Low power consumption
- Compatible with Arduino IDE 1.5.4 or later, user can program, debug or upload sketches to the Arduino board via the Arduino IDE.
- Managed by Web GUI, SSH via LAN or WiFi
- Software upgradable via network
- Built-in web server
- Supports internet connection via LAN port, WiFi or 3G dongle.
- Supports USB flash to provide storage for Arduino projects.
- Failsafe design provides robust system.
- Compatible with Arduino Leonardo, Uno , Duemilanove, Diecimila, Mega
There are four LEDs on the Yun Shield. The functions of these LEDs are:
- PWR: Power Indicate LED. Turns on once there is power.
- LAN: Indicates there is a LAN connection when it is on or blinking.
- WLAN: Indicate WiFi status.
- SYS: LED for USB storage. It is on if the USB flash is linked to the Arduino Yun default SD directory /mnt/sd and /www/sd
System Structure
The RJ45, WiFi, USB Host and Failsafe are connected to the Dragino HE module directly. And the Dragino HE module uses SPI and the UART to communicate with the Arduino Board. The Yun Shield is compatible with 3.3v and 5v Arduino boards. The on board jumper SV1 is used to set the SPI and UART to 3.3v or 5v level.
The SPI interface is used to upload the sketches from the Arduino IDE. The SPI interface only connects to Dragino HE during uploading so the Arduino SPI can still be used to connect to other SPI slave devices.
The UART interface is used for the Bridge class in Arduino: there are lots of examples explaining how to use the bridge class in the Arduino IDE. It is the core of the Yun solution. We must make sure the serial Interface of the Arduino is not used by other hardware.
Power Requirement
via Arduino DC port
The Dragino HE is the core module of the Yun Shield. The HE module requires around 200mA current when at full load, so it is powered by the Arduino VIN pins to avoid overheating in the Arduino onboard 5v LDO. So when the Yun shield is used, the Arduino board should be powered by DC port instead of USB port. The DC input can be 9v
The USB Host on the Yun Shield gets power from the Arduino +5v pin, since the +5v from Arduino comes from the +5V LDO, to avoid overheating on the Arduino Board, when the USB host is in use, it is recommended to use +9v DC .
via Arduino USB port ( Caution )
The User can power the Yun Shield if the overall current (arduino + Yun Shield + other shields) is under the limitation of the Arduino 5V LDO. In the Yun Shield v1.1, there is a jumper (on the bottom) to define whether to power the Yun Shield from VIN or 5V USB. So the User can put the jumper to 5V position and power the Yun Shield via the Arduino USB.
If the overall current exceeds the LDO limitation, strange issue like: disconnect, reboot may happen in the Yun Shield.
via Ethernet Port Passive PoE
Yun Shield version v1.1.6 and v2.4 support Passive POE. User can power the Yun Shield and Arduino via a 8 core RJ45 cable and PoE Injector. The Yun Shield use the pinout of 802.3af mode B — with DC plus on pins 4 and 5 and DC minus on 7 and 8, . Data is then on 1-2 and 3-6 Passive PoE
The PWR from the RJ45 port is connected to the VIN pin of Yun Shield. so it can also power the Arduino. the Input of POE power is 9v
CONFIGURE YUN SHIELD
Find the ip addresses
The Yun Shield has a WiFi interface and a LAN port. Each of them has an IP address and can be used for internet connection and device management.
Factory IP of WiFi port
At the first boot of the Yun Shield, it will auto generate an unsecure WiFi network called Dragino2-xxxxxx
The User can use their laptop to connect to this WiFi network. The laptop will get an IP 192.168.240.xxx and the Yun Shield has the default IP 192.168.240.1
A fall back IP 172.31.255.254/255.255.255.252 is assigned to the Yun Shield’s LAN port so the user can always access the Yun Shield with this ip if their laptop has the IP 172.31.255.253/255.255.255.252 .
Detect IP from Arduino IDE
If the Yun Shield’s Ethernet port is connected to the uplink router or the WiFi interface is associated to the WiFi router, a PC in the same network can use the Arduino IDE to detect the Yun Shield’s IP address as described in Detected Yun Shield.
Configuration Method
The Yun Shield runs an Open Source Linux system. If the user has a PC on the same network as the Yun Shield, the user can access its system via either a Web Interface or Secure Shell (SSH) .
Access via web interface
The recommended browsers to configure Yun Shield are Firefox and Chrome . Simply type the IP address into your browser and you will see the log in page of Yun Shield.
Default User name and Password for the Yun Shield is root/dragino.
Access via SSH
Via SSH, the user can access the Linux system directly and customize the system to support more features and applications.
IP address: IP Address of the Yun Shield
Password: dragino (default)
Web Configure Pages
General Set Up for Internet Access
After log in, the GUI will show the WIFI / ETH interface status. Click the Configure button and now the user can configure the device password and network parameters.
Arduino related set up
Auto Detect AVR : Yun Shield will auto detect the Arduino AVR part and use related info to update.
Upload Profile : Auto detect.
Upload Bootloader : If checked, the Yun Shield will add the Arduino bootloader when upgrading sketch. User will be not be able to upload a sketch to Arduino if there is no bootloader in it.
Upgrade Linux Firmware
The Yun Shield firmware can be upgraded via the GUI for bug fixes / system improvement or new features. The firmware version info can be checked from this link: Yun Firmware Change log
Go to the GUI → Upgrade page and select the correct firmware to upgrade. The firmware used for web upgrade should be a sysupgrade type firmware: the user can choose if keep settings or not after an upgrade.
Normally it will take about 2 minutes to flash the new firmware. Then all the LEDS will blink together which indicates that the system is rebooting with the new firmware.
USE WITH ARDUINO BOARDS
The Yun Shield uses SPI for uploading sketches and uses the UART port for the Bridge class to talk to the AVR. While connecting the Yun Shield to Arduino Board, below points should be checked:
- Whether the Arduino Board is power by DC jack
- If the board type setting is correct in Yun Shield.()
- If the board type setting is correct in Arduino IDE
- Whether the Arduino SPI and UART is not influenced by other hardware.
- Make sure the UART mode is in Arduino Bridge .
Connect to Arduino Boards
General How To
To use the Arduino IDE to upgrade the Arduino / AVR via local area network: the User should Add Correct Board Type in Arduino IDE.
The User may also have to do hardware modification for different boards as showed below.
Connect to a Leonardo
Simply plug the Yun Shield on top of the Leonardo, and power the Leonardo via the DC jack. In the Arduino IDE, the board type should select Arduino Yun .
Connect to Arduino Uno
In a UNO the uart connection between the mega328P and mega16u2 will influence the bridge feature of the Yun Shield. Therefore we have to disconnect it by setting the mega16u2 into reset mode, as below:
Note: No need to put the jumper anymore in Yun Shield v1.1.6 and Yun Shield v2.4
Note: USB upgrade/debug won’t work after this change: the User will have to upgrade sketches and debug via the Arduino IDE via WiFi (see examples)
Put the Yun Shield on top of Uno and power it via DC jack.
Connect to Arduino Duemilanove/Diecimila
1)In Duemilanove/Diecimila, the mega avr uart interface is connected to the FTDI chip, we have to disconnect them as shown in picture below:
Note: No need to remove these components in Yun Shield v1.1.6 and Yun Shield v2.4
2)Use the same Board Profile as UNO in the Arduino IDE
3)Put the Yun Shield on top of Duemilanove and power it via DC jack.
Connect to Arduino Mega2560
1)In the Mega2560, the uart connection between mega2560 and mega16u2 will influence the bridge feature of the Yun Shield. Therefore we have to disconnect it by setting the mega16u2 into reset mode. As below:
Note: No need to put the jumper anymore in Yun Shield v1.1.6 and Yun Shield v2.4
2)Put the Yun Shield on top of Mega2560 and power it via the DC jack.
Connect to Freetronics «Eleven»
While connecting to a Freetronic «Eleven», the user can use the same profile as connecting to a UNO, but will need to do the hardware modification below, which is a little different from the Arduino Uno.
Note: No need to put the jumper anymore and remove the component in Yun Shield v1.1.6 and Yun Shield v2.4
Connect to Dccduino UNO R3
Note: No need to remove these components in Yun Shield v1.1.6 and Yun Shield v2.4
Connect to Helvetino Kit
Connect to Teensy
The Teensy is a complete USB-based microcontroller development system and is as versatile as it is powerful. A custom Teensy installer and bridge application will easily allow you to write sketches for the Teensy and load them on to the Teensy. All programming is done via the USB port just like the Arduino — no special programmer is needed.
Connect to Arduino DUE
The Arduino Due is a 3.3v Arduino base on ATSAM MCU. When connecting the Yun Shield to Arduino Due, user should notice:
- When using Yun Shield version Detect Yun Shield
Make sure your laptop and Yun Shield are on the same network. The Yun Shield will broadcast data on this network and the Arduino IDE will receive this data and show the Yun Shield in Tools →Port .
Upload Sketch
Upload via WiFi/ LAN from IDE
- In the Arduino IDE, choose the correct board type for the AVR module.
- In the Arduino IDE → port, choose the correct port. (Should be Arduino Yun port with an ip address)
- In the Yun Shield GUI → Sensor page, choose the correct board type for upload.
- Compile the sketch and upload it to the Arduino Board. During upload, the Yun Shield will ask you to key in the password, by default, the password is dragino .
Upload via Web
Auto Update Sketch
For sketch auto update in the field please refer to: Manual for Auto update Sketch.
Bridge Library
The Bridge Library simplifies communication between the Arduino Board and the Yun Shield.
Bridge commands from the AVR (Arduino Board) are interpreted by Python on the Yun Shield. Its role is to execute programs on the GNU/Linux side when asked by Arduino, provide a shared storage space for sharing data like sensor readings between the Arduino and the Internet, and receiving commands from the Internet and passing them directly to the Arduino.
There are detail explanations and lots of examples to show how to use Bridge on the Arduino Official Website. Reference link is:Yun Bridge Library
Quick Start
EXAMPLES
Example 1: Say hello to Linux
Detect IP address from the Arduino IDE :
This example is a hello test between the Arduino and the Yun Shield. The example can be found at Arduino IDE—> File —> Examples —> Bridge —> ConsoleRead . A tutorial for this example can be found on http://arduino.cc/en/Tutorial/ConsoleRead. The listing of the code below includes some detail to understand it working with the Yun Shield:
Example 2: Upload data to IoT Server
This example shows how to log data to the public IoT server “ Xively ”. The example is a modified version (changed Serial to Console to suit different Arduino Board and debug over WiFi) from Arduino IDE—> File —> Examples —> Bridge —> XivelyClient . The tutorial for this example can be found at http://arduino.cc/en/Tutorial/YunXivelyClient
Before uploading the sketch, make sure:
- The Yun Shield already has internet access
- Input your FEED ID and API KEY according to the tutorial. Note, the FEED ID should be within double quotation marks “”.
- Change the Serial Class to Console class to suit different AVRs.
The code listing below includes some detail to understand it working with the Yun Shield:
Example 3: Log Data to USB flash
This example shows how to log data to a USB flash. The sketch used in this example is the same as Log Data to USB Flash. The source code is in this link .
The Yun Shield will auto mount the USB flash to directory /mnt/sda1. The sketch will append the sensor data to the file /mnt/sda1/data/datalog.csv. Make sure there is such file in the USB flash before running the sketch.
Example 4: Use MQTT
MQTT is a machine-to-machine (M2M)/»Internet of Things» connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers.
This example shows how to use the Yun Shield with the SSL MQTT protocol.
Install required packages
Install below packages for MQTT:
Test with public MQTT test server :
test.mosquitto.org hosts a publicly available Mosquitto MQTT server/broker. The User can post and subscribe to this MQTT server for testing. To test this server with an SSL connection, the user has to download the certificate authority file mosquitto.org.crt to verify the server connection.
Open two SSH windows. In the first window, we subscribe to a topic with the command below:
This command will listen to this topic and display any change on the server.
In the other window, we publish the change with another command:
Once the publish command is issued, we can see the result display in the subscribe command.
Example 5: Use the 3G dongle
This is the introduction for how to use a 3G USB dongle to connect to the Yun Shield and establish the 3G connection. The firmware tested in the demo below is Dragino-v2 common-2.0.3 and the 3G USB dongle model is a HuaWei E303 using UMTS for 3G connection. The service provider is China Unicom.
Install required packages
Configure the Yun Shield to connect Internet via WiFi and install the below packages:luci-proto-3g,kmod-usb-serial-option, kmod-usb-serial-wwan usb-modeswitch-data, usb-modeswitch. The output should be as below:
Open the page System —> advanced configuration panel —> Network —> Interfaces . Click Add New Interface
Notice About the configuration
When configure 3G info, we have to choose the right ttyUSB port for dial up. If it possible you can’t see the ttyUSB port , especially in the Yun Shield v2.x version, becasue there is more than one USB device there. We can use the lsusb command to get the usb info. as below, we can see the 3G module we have here has the info 05c6:9090.
then put this line in the file /etc/module.d/60-usb-serial
reboot the device, and the ttyUSB port will appear.
Example 6: Save Data to Google SpreadSheet
Example inlcude lots content, please refer this link
Example 7: Save Data to MySQL
Example inlcude lots content, please refer this link
What is the difference between the official Arduino Yun and the Yun Shield?
The Arduino Yun and the Yun Shield have the same CPU, Memory size and RAM size for the Linux system. The Arduino Yun is an integrated Linux and MCU part. The Yun Shield is designed as a shield which can be used with existing Arduino boards.
Basically, a Yun Shield + Arduino Leonardo equal an Arduino Yun, but the Yun Shield is more flexible because it can be used with other Arduino boards such as Arduino Uno, Duemilanove, Diecimila etc.
The Yun Shield can be duplicated and is producible: The design of the Yun Shield is open and the most complicated and difficult parts are done in the Dragino HE module. The User can purchase the Dragino HE module separately to customize their IoT project and release their variant Yun Solution.
Stable and Flexible WiFi performance: The Arduino Yun uses a chip antenna design. If there is a shield on top of the Arduino Yun, the wifi will be greatly shielded and lead to a poor wifi performance. Instead, the Yun Shield uses a external antenna design. the user can connect different types of antennas to the i-pex connector of the Yun Shield: this makes the installation more flexible and possible to transfer the signal to several km distance.
The Yun Shield software is derived from the Arduino Yun with some bugs fixed; features added and support more board types.
Is Yun Shield compatible with a variant Arduino Board?
If the Arduino board is a variant from the boards described in Support Board Type , then it should be compatible. Below is the check list for the compatibility.
15v power in the VIN pin to power the Yun Shield.
The system structure section well explains the working principle of the Yun Shield. If the user is still not sure whether the Yun Shield is compatible with their board or having trouble in compatibility, then they can send the board info to support@dragino.com and our support team will review and check it.
How to set up /www/sd and /mnt/sd?
To use the /www/sd and /mnt/sd as the same as a Arduino Yun, the user can prepare a USB flash and create directories /arduino and /arduino/www at the root of USB flash. Then plug the USB flash into the Yun Shield and it will automatically create /www/sd and /mnt/sd and link to /arduino and /arduino/www.
Where can I find the source code of Yun Shield?
The Yun Shield source can be found at: https://github.com/dragino/linino
How to Upload, Download or Edit files in the Yun Shield
The Yun Shield has a built-in Linux system and supports the SCP protocol. The user can upload, download or edit the Linux files using SCP tools.
In a windows OS, the scp tool is winscp. Install it and log into the Yun Shield as below:
- Host Name : Yun Shield IP address
- User Name : root
- Password : arduino (default)
- Protocol : SCP
The log in process will cause two warnings: just ignore them. After log in, a management panel will appear. The left part of this panel is your PC’s directories and the right part shows the directories of the Yun Shield, you can upload/download files by dragging , or double click the files to modify its content.
How to reset the Yun Shield
The Yun Shield has a toggle button which can be used for reset. When the system of the Yun Shield is running, the user can press the toggle button to reset the device. Pressing this button will cause the WLAN LED will blink.
- Pressing the toggle button and release after 5 seconds , will reset the WiFi setting and other settings will be kept.
- Pressing the toggle button and release after 30 seconds , will reset ALL the setting to factory default .
How to recover the Yun Shield in case of a firmware crash
There are some cases that the Yun Shield fails to boot, for example upgrade improper firmware or lost power during upgrade. The user is still able to recover the Yun Shield system by using the Failsafe u-boot of the Yun Shield
An instruction in Windows is as below:
Set up TFTP server
Download the tftp server (recommend tftp32d.exe) and download the latest Yun firmware from Yun Firmware . The firmware we need is the kernel and rootfs-squashfs files. Put these firmware files and tftp32d in the same directory. Start the tftp server.
Download Hercules utility
Download Hercules . This is the tool we use to transfer commands to the Yun Shield in Failsafe mode. Run Hercules and input the correct parameters as below:
Module IP: 192.168.255.1
Connect your PC to the Yun Shield
Connect the PC and Yun Shield via an Ethernet cable. Set up the PC with the below LAN IP 192.168.255.2 and netmask 255.255.255.0 . Disable the PC’s firewall.
Power up Yun Shield to Failsafe mode
Press the Failsafe button and power up the Yun Shield; the user will see all the LEDs blink together. Release the button after 10 seconds and some messages will pop up in the Hercules panel which means the Yun Shield has been in Failsafe Netconsole mode and is ready to access commands.
The user can type the commands in Hercules to transfer and upgrade the Yun Shield to the latest firmware with factory settings.
The update commands are as below, replace the xxx with the actually version.
Note when typing command in Hercules : The user must add at the end of each command. $ is a special char in Hercules: the user should double it (key in 2, $$) when typing.
Reset to the new firmware
Warning : The user should use exactly the address numbers shown in the erase and cp.b lines shown: wrong address numbers may destroy the boot-loader of the Yun Shield and the device won’t boot anymore, or destroy the radio data of the Yun Shield which may lead to a poor wifi performance or incorrect MAC addresses.
Recover in Linux is similar with Windows, the main difference is that the tool use in Linux is nc and runs with nc -kul 6666 . Below shows that the Yun Shield has been in Failsafe Netconsole mode and detected by nc.