Getting Start with Arduino Yun

From Wiki for Dragino Project

Jump to: navigation, search



What is Dragino Yun Firmware

The Dragino Yun firmware is designed to provide the easy communication between Linux and Atmel AVR mcu. In Dragino Yun firmware, developer can remote upgrade the AVR sketch via Arduino IDE, call Linux command . access Linux system in MCU.

Dragino Yun Firmware is derived from the official Arduino Yun firmware with some bugs fixed and support more avrs. The firmware source follows the development on OpenWrt Yun. The firmware can be downloaded from downloaded from This Link

This page provides necessary info of how to use Dragino Yun, how to design a plug-in module for Arduino Yun. For detail of how to use generic Arduino Yun software please consult to Arduino Yun Offical Link

What devices can run Dragino Yun firmware

Requirement to get Arduino Yun alike feature

Yun firmware provide great feature such as program the AVR via Arduino IDE and easy communication between Linux and MCU. If developer want to design their customized hardware module for Dragino boards to use Yun feature, developer should make sure the correct hardware connection between dragino boards (MS14, HE , Yun Shield) and the AVR boards (Arduino UNO etc) . Features include:

  • Remote upgrade sketch to AVR: Make sure the SPI connection is fine between AVR and Dragino boards.
  • Communication between avr and linux:Make sure the UART connection is fine between AVR and Dragino boards.

Reference hardware connection design of the SPI/ UART connection can check Yun Shield and Arduino UNO

Configure Dragino Yun

Find the ip addresses

The Dragino Yun has a WiFi interface and a LAN port. Either of them has IP address, can be used for internet connection and device management.

Factory IP of WiFi interface

Dragino Yun acts as an AP at the first boot

At the first boot of Dragino Yun, it will auto generate an unsecure WiFi network call Dragino2-xxxxxx

User can use their laptop to connect to this WiFi network. The laptop will get an IP and the Dragino Yun has the default IP

Fall Back IP

PC setting to use FallBack IP

A fall back IP is assigned to Dragino Yun's LAN port so user can always access Dragino Yun with this ip if their laptop has: IP IP: and Netmask:

Detect IP from Arduino IDE

If Dragino Yun’s Ethernet port is connected to the uplink router or the WiFi interface is associated to the WiFi router. The PC in the same network can use Arduino IDE to detect Dragino’s IP address as described in Detected Dragino Yun.

Configure Method

The Dragino Yun runs Open Source Linux system. If user has a PC at the same network as Dragino Yun, user can access its system via either Web Interface or Secure Shell (SSH).

Access via web interface

The recommended browsers to configure Dragino Yun are Firefox and Chrome. Simply type the IP address into your browser and you will see the log in page of Dragino Yun.

Dragino Yun Log In Page

Default User name and Password for Dragino Yun is root/dragino.

Access via SSH

Via SSH access, user can access to the Linux system directly and customized the system to support more features and applications.

Access Dragino Yun via SSH

SSH Access:

IP address: IP Address of Yun Shield

Port: 22

User Name: root

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 user can configure the device password and network parameters.

Configure WiFi for internet Access

Arduino related set up

Select the correct boardtype

Arduino Board Type: Define the bootloarder/mcu type/ fuse setting during Sketch upload.

Operation Mode: make sure it is in Arduino Bridge mode so the Bridge class for Arduino Yun works.

Upgrade Firmware

Detail please see Upgrade firmware via web UI

Detect Dragino Yun

Once the device running Dragino Yun firmware is configured and get IP address from WiFi router. It will send broadcast data in the network and if you run the latest Arduino IDE. It will auto detect Yun service and show in the port menu .

Arduino Detect Yun in the same network

Upload Sketch to Arduino / AVR

In Dragino Yun software, user can upgrade the Arduino / AVR remotely in Arduino IDE. The Dragino Yun GUI supports different kind of Arduino/AVR boards includes:

  • Arduino Leonardo or Mega32u4
  • Arduino Uno or Mega328p
  • Arduino Duemilanove/Diecimila or Mega168
  • Arduino Mega2560 or Mega2560

User can check them in the GUI--> Sensor page. The Dragino Yun use avrdude to program so it can program more AVRs via SSH access.

Select the correct boardtype

Arduino Board Type: Define the bootloarder/mcu type/ fuse setting during Sketch upload.

Configure Board Type in Arduino IDE

To use Arduino IDE to upgrade the Arduino / AVR via local area network. User should configure the correct board type. To do this, user can download the related hardware info from Dragino Yun SketchBook Hardware Folder and place it into the Arduino SketchBook Directory.

Then restart the Arduino IDE, the new hardware info should be found as below:

Dragino Yun hardware Info

Compile and Upload via Arduino IDE

After we have correctly configure board info. We can use the Arduino IDE to compile and upload the firmware to Arduino or AVR mcu.

During upload, Arduino IDE will ask for a password. This is the password we configure in the Web GUI. By default, it is dragino.

Compile and Upload sketch in Arduino IDE

Arduino Bridge Library

The bridge library is the most important part of Arduino Yun. Bridge library defines a mechanisms how the AVR talk to the CPU (ar9331). With the bridge library, the avr can send data to CPU, get commands from CPU or call commands in CPU.

The bridge Library use UART port to communicate between avr and ar9331. Below is the block diagram which shows the difference between ms14 and the official Arduino Yun device. With Dragino ms14, we can use different types of avr , even use other brand mcu (PIC) with the Bridge Library.

Bridge Diagram Difference between Arduino Yun and Dragino MS14

Detail instruction of how to use the bridge library can be found in Arduino Official Website. There are several points we should consider while writing the avr software:

  • In the default bridge examples from Arudino IDE, it uses Serial class to print debug info. This is ok if you connect ar9331 to ATmega32u4 because it will call USB Virtule COM Port to print the debug info, but it will have problem if you use it mcu such as ATmega168,328 because they don't have Virtual USB Com port. The serial will call mega168, 328's hardware serial port , it will be conflict with the Bridge Library.
  • Arduino use ledPin 13 to show LED, user can also control SYS led on Dragino ms14, but the pin may be different depends on how user connect the avr to the ms14 sys led.

The examples sketch codes for ms14 can be found at This Link.

UART Operation Mode

The Operation Mode has been introduced to the WEB GUI since firmware Dragino-Yun-Beta1.3.1. With the Operation mode setting, user is able to control the UART behaviour in a easy way. This setting is under Sensor--> Operation Mode . Currently it supports below mode. Note: Switching between UART mode nequire a reboot on the system.

UART Operation Mode

Arduino Bridge Mode

The Bridge Mode is the default setting in the Yun firmware in earlier than Dragino-Yun-Beta1.3.1, while MS14 is in this mode, the UART interface is using Arduino Bridge feature, the AVR sketch can use Arduino Bridge library to communicate with the MS14 like a Arduino Yun.

Control Mode

While MS14 is under this mode, the OpenWrt UART console is disable and no longer support Arduino Bridge feature, user can write a custom script in MS14 to communicate with other devices use the UART interface.

PassThrough Mode

The PassThrough Mode is derived from Control Mode. This mode will auto start a script which will match the UART incoming data and then send to the remote server. This script now support: Xively and Yeelink service.

BEE Console Mode

BEE Console mode is designed for m32w module. In this mode, User can configure the XBee module or Bluetooth Bee module on the Bee Socket. Reference Link

Upgrade Firmware to devices

The Yun firmware from Arduino official website won't work at ms14 because of different pin mapping. We have maitained a Dragino version Yun firmware for MS14. They can be downloaded from firmware download link. Firmware release note is HERE.

If you already have a Yun firmware running in the dragino devices. Then you can upgrade the firmware from WEB GUI. Otherwise, you will have to upgrade the firmware according to below instruction.

Upgrade via WEB GUI

Go to GUI → Upgrade page and select the correct firmware to upgrade. The firmware used for web upgrade should be a xxx.squashfs-sysupgrade.bin type firmware, user can choose if keep settings or not after upgrade.

Upload Firmware
Upload Firmware

Normally it will take about 2 minutes to flash the new firmware. Then all the LEDS will blink together which indicates that the system reboot with the new firmware.

Upgrade via U-Boot

If the ms14 doesn't have a Yun firmware, you need to upgrade a Yun firmware into it first.

Set up your tftp server with ip and put the firmware on tftp server root.

In u-boot, both kernel and rootfs need to be upgraded. The commands is as below, replace the xxx with the exactly version you have on the firmware.

Upgrade Commands in U-Boot

Upgrade Kernel

  1. dr_boot>tftpboot 0x81000000 ms14-arduino-yun-kernel-xxx.bin
  2. dr_boot>erase 0x9fea0000 +0x140000 
  3. dr_boot>cp.b 0x81000000 0x9fea0000 $filesize

Upgrade rootfs

  1. dr_boot>tftpboot 0x81000000 ms14-arduino-yun--rootfs-squashfs-xxx.bin
  2. dr_boot>erase 0x9f050000 +0xe50000    
  3. dr_boot>cp.b 0x81000000 0x9f050000 $filesize

Change boot address for Yun firmware

  1. dr_boot> setenv bootcmd bootm 0x9fea0000
  2. dr_boot> saveenv
  3. dr_boot> reset

Then you will have Yun firmware after reboot.

Upgrade to the IoT Mesh firmware

The Yun firmware and IoT mesh firmware has different flash layout and boot address. Switch between these firmware can't be complete via Web UI.

Below is the instruction of how to upgrade the device from Dragino Yun firmware to IoT Mesh Firmware:

  1. Upgrade the device to the middleware(download) via the Web UI (don't check keep settings).
  2. Access to the linux system and run: switch_firmware_from_Yun_to_IoT . Device will upgrade and reboot to Version: Dragino-v2 IoT-1.3.4. After that, user can continue to use other IoT Mesh Firmware by upgrade in Web UI.

output of this command is as below:

root@dragino:~# switch_firmware_from_Yun_to_IoT 
Start Flashing, Don't power off the device until it finish !!!
Unlocking u-boot-env ...

Writing from /var/IoT_firmware_part1 to u-boot-env ...     
Unlocking rootfs ...

Writing from /var/IoT_firmware_part2 to rootfs ...     
Flashing finish. Reboot the device to boot to IoT firmware.


CLICK HERE for some detail examples.

Or consult Arduino Yun Example Git Source for more examples source.

Trouble Shooting

Bridge examples doesn't work

The bridge examples from Arduino IDE are tested base on MEGA32u4 mcu. Mega32u4 has a hardware serial (serial1) which use for Bridge library, and has a USB port use as serial to print out debug info. In the bridge examples such as bridge --> httpclient, it use both bridge (serial1) and serial (usb serial). It is ok for Mega32u4, but if user use the same with other MCU such as mega328p, it won't work, because the bridge and serial are now use the same TXD/RXD from Mega328P. If user want to see debug info, they can use the console method in Bridge.

Update Sketch Fail

Arduino IDE shows signature mismatch

an example output from Arduino IDE as below:

Programmer Type : linuxgpio
Description : Use the Linux sysfs interface to bitbang GPIO lines

avrdude: Calibrating delay loop... calibrated to 49 cycles per us
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9801
avrdude: Expected signature for ATmega32U4 is 1E 95 87
Double check chip, or use -F to override this check.

Above result shows that Dragino try to program the Arduino with mega32u4 mcu type but actaully the Arduino is mega2560 which has signature 0x1e9801. So it fails. To solve this issue, user can choose the mcu/board type to the correct one in the Dragino Web Interface --> Sensor --> Arduino Board Type.

AVR device not responding

Typical output in Arduino IDE for this issue is as below:

        Programmer Type : linuxgpio
        Description     : Use the Linux sysfs interface to bitbang GPIO lines
avrdude: Calibrating delay loop... calibrated to 48 cycles per us
avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
        Double check connections and try again, or use -F to override
        this check.
avrdude done.  Thank you.

This means that there is something wrong on the SPI interface between Dragino devices and AVR(Arduino Board). So please check if the SPI connection between dragino and avr is ok.

See wrong strings in serial during booting

The Arduino Bridge Library use Baud Rate 250000 for UART communication. So in Arduino Yun Firmware, the kernel will switch the baud rate to 250000 during the booting process. Because u-boot used runs Baud Rate 115200, if use serial monitor to see the boot up process in 115200 baud rate mode, you can see messy code in UART after kernel chande the baud rate.

A typical output as below:

  1. U-Boot 1.1.4 (Aug 12 2012 - 20:14:51)
  3. AP121-2MB (ar9330) U-boot
  4. DRAM: #### TAP VALUE 1 = f, 2 = 10
  5. 64 MB
  6. Top of RAM usable for U-Boot at: 84000000
  7. Reserving 212k for U-Boot at: 83fc8000
  8. Reserving 192k for malloc() at: 83f98000
  9. Reserving 44 Bytes for Board Info at: 83f97fd4
  10. Reserving 36 Bytes for Global Data at: 83f97fb0
  11. Reserving 128k for boot params() at: 83f77fb0
  12. Stack Pointer at: 83f77f98
  13. Now running in RAM - U-Boot at: 83fc8000
  14. id read 0x100000ff
  15. flash size 16777216, sector count = 256
  16. Flash: 16 MB
  17. In: serial
  18. Out: serial
  19. Err: serial
  20. Net: ag7240_enet_initialize...
  21. No valid address in Flash. Using fixed address
  22. No valid address in Flash. Using fixed address
  23. : cfg1 0x5 cfg2 0x7114
  24. eth0: 00:03:7f:09:0b:ad
  25. eth0 up
  26. : cfg1 0xf cfg2 0x7214
  27. eth1: 00:03:7f:09:0b:ad
  28. athrs26_reg_init_lan
  29. ATHRS26: resetting s26
  30. ATHRS26: s26 reset done
  31. eth1 up
  32. eth0, eth1
  33. Hit any key to stop autoboot: 4     3     2     1     0 
  34. ## Booting image at 9fea0000 ...
  35. Image Name: MIPS OpenWrt Linux-3.8.3
  36. Created: 2014-02-12 3:16:34 UTC
  37. Image Type: MIPS Linux Kernel Image (lzma compressed)
  38. Data Size: 1172210 Bytes = 1.1 MB
  39. Load Address: 80060000
  40. Entry Point: 80060000
  41. Verifying Checksum at 0x9fea0040 ...OK
  42. Uncompressing Kernel Image ... OK
  43. No initrd
  44. ## Transferring control to Linux (at address 80060000) ...
  45. ## Giving linux memsize in bytes, 67108864
  47. Starting kernel ...
  49. [ 0.000000] Linux version 3.8.3 (edwin@edwin-test) (gcc version 4.6.4 20121210 (prerelease) (Linaro GCC 4.6-2012.12) ) #17 Wed Feb 12 11:15:36 CST 2014
  50. [ 0.000000] bootconsole [early0] enabled
  51. [ 0.000000] CPU revision is: 00019374 (MIPS 24Kc)
  52. [ 0.000000] SoC: Atheros AR9330 rev 1
  53. [ 0.000000] Clocks: CPU:400.000MHz, DDR:400.000MHz, AHB:200.000MHz, Ref:25.000MHz
  54. [ 0.000000] Determined physical RAM map:
  55. [ 0.000000] memory: 04000000 @ 00000000 (usable)
  56. [ 0.000000] Initrd not found or empty - disabling initrd
  57. [ 0.000000] Zone ranges:
  58. [ 0.000000] Normal [mem 0x00000000-0x03ffffff]
  59. [ 0.000000] Movable zone start for each node
  60. [ 0.000000] Early memory node ranges
  61. [ 0.000000] node 0: [mem 0x00000000-0x03ffffff]
  62. [ 0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
  63. [ 0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
  64. [ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
  65. [ 0.000000] Kernel command line: board=Linino console=ttyATH0,250000 mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,14656k(rootfs),1280k(kernel),64k(nvram),64k(art),15936k@0x50000(firmware) rootfstype=squashfs,jffs2 noinitrd
  66. [ 0.000000] PID hash table entries: 256 (order: -2, 1024 bytes)
  67. [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
  68. [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
  69. [ 0.000000] __ex_table already sorted, skipping sort
  70. [ 0.000000] Writing ErrCtl register=00000000
  71. [ 0.000000] Readback ErrCtl register=00000000
  72. [ 0.000000] Memory: 60900k/65536k available (2569k kernel code, 4636k reserved, 651k data, 232k init, 0k highmem)
  73. [ 0.000000] SLUB: Genslabs=9, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
  74. [ 0.000000] NR_IRQS:51
  75. [ 0.000000] Calibrating delay loop... 265.42 BogoMIPS (lpj=1327104)
  76. [ 0.080000] pid_max: default: 32768 minimum: 301
  77. [ 0.080000] Mount-cache hash table entries: 512
  78. [ 0.090000] NET: Registered protocol family 16
  79. [ 0.090000] MIPS: machine is Arduino Yun
  80. [ 0.540000] Setting DogStick2 GPIO
  81. [ 0.560000] bio: create slab at 0
  82. [ 0.560000] SCSI subsystem initialized
  83. [ 0.570000] usbcore: registered new interface driver usbfs
  84. [ 0.570000] usbcore: registered new interface driver hub
  85. [ 0.570000] usbcore: registered new device driver usb
  86. [ 0.580000] Switching to clocksource MIPS
  87. [ 0.580000] NET: Registered protocol family 2
  88. [ 0.590000] TCP established hash table entries: 512 (order: 0, 4096 bytes)
  89. [ 0.590000] TCP bind hash table entries: 512 (order: -1, 2048 bytes)
  90. [ 0.590000] TCP: Hash tables configured (established 512 bind 512)
  91. [ 0.600000] TCP: reno registered
  92. [ 0.600000] UDP hash table entries: 256 (order: 0, 4096 bytes)
  93. [ 0.610000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
  94. [ 0.620000] NET: Registered protocol family 1
  95. [ 0.640000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
  96. [ 0.640000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
  97. [ 0.650000] msgmni has been set to 118
  98. [ 0.660000] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
  99. [ 0.660000] io scheduler noop registered
  100. [ 0.670000] io scheduler deadline registered (default)
  101. [ 0.670000] Serial: 8250/16550 driver, 16 ports, IRQ sharing enabled
  102. [ 0.680000] ar933x-uart: ttyATH0 at MMIO 0x18020000 (irq = 11) is  
  103. -q  
  104. 侤塈%堃| 8c ?M? 鸮\贛嚬]? H篔劝my o7^:H筣
  105. J泑艉h.靥O j ?雀z酨辿,鵻.NA衜 .岺摶&
  106. 霳 j  @L圝 
  107. &癐¬?(Q蠳 泋AJ侤塝圝ba擷&坸釘J菿僼瀇   j ?
  108. }+~淣(渓> }7?
  109.  沑凕j ' j
  110. ??僪 )N6?Q﨨 j ?垟JH欽孨圸圝圚& 蘋 j ?垟J圝圛擩H汮圚嚮L 霴 j ?,L8  屆>a~a怇N j ? @L圝 
  111. &癐¬?(' 5i?萀a MH i?駤Hq榅?' ja?萀醥?A塏6堷J坖寽kL? ? j%?I塏>媬Io%k} h (菻¬?鵜? 
  112. ¬萂℉z黓埜 桄O j%? 鴒a?H j?a E'bMy鳱 O j=?J竘b榐 踍 篘x樭|良籡a埞L ` j=?K\&cn?X &閮t搸H塝 壜?J岌綹凁餗摴Mj淿z9 H麶?
  113. 8瀄j贜&
  114. l  k=?f? 擬~訫?j8 H8圝 q X&¬m6??-x H 圝'圸怞? P¬麿狪吿厅O k-?B?d達?h?tX67? ¬8OH 舭%凫O j-?偤l 歗儤歁¬烗H閄淢呣jb躭懈~

Recover Dragino Yun firmware

User may lost access to the Dragino Yun by accidently change the Linux configure files to in correct setting, lost password or other caused. There are different methods to recover.

Reset to factory default

Dragino Yun has a toggle button (GPIO11) which can be used for reset. When the Dragino Yun is running in OpenWrt System, user can press the toggle button to reset the device. When press this button, the WLAN LED will blink.

  • If pressing the toggle button and release after 5 seconds, it will reset the WiFi setting and other settings will be kept.
  • If pressing the toggle button and release after 30 seconds, it will reset ALL the setting to factory default .

Recover via RJ45 port in Failsafe u-boot

This mehod LAN connection direclty between Dragino and PC.

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 The firmware we need is the kernel and rootfs-squashfs files. Put these firmware files and tftp32d at the same directory. Start the tftp server.

Download Hercules utility

Download Hercules, this is the tool we use to transfer commands to Yun Shield in Failsafe mode. Run Hercules and input correct parameters as below:

Hercules Configure

Protocol: UDP Module IP: Port: 6666 Local port: 6666

Connect your PC to MS14

Connect the PC and MS14 LAN port via an Ethernet cable. Set up PC with below LAN IP and netmask Disable PC’s firewall.

Power up MS14 to Web Failsafe mode

Press the Failsafe button and power up MS14; user will see all the LEDs blink together, release the button after 10 seconds and there are some messages will pop up in the Hercules panel, which means the MS14 has been in Web Failsafe Netconsole mode and ready to access commands.

User can type the commands in Hercules to transfer and upgrade 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: user must add <CR> at the end of each command; $ is a special char in Hercules, user should double it (key two $$) when typing.

Upgrade Kernel

tftpboot 0x81000000 ms14-arduino-yun-kernel-xxx.bin
erase 0x9fea0000 +0x140000 
cp.b 0x81000000 0x9fea0000 $filesize

Upgrade rootfs

tftpboot 0x81000000 ms14-arduino-yun--rootfs-squashfs-xxx.bin
erase 0x9f050000 +0xe50000    
cp.b 0x81000000 0x9f050000 $filesize

Reset to the new firmware


Warning: User should use exactly address number in the erase and cp.b shows, wrong address number may properly destroy the boot-loader of MS14 and the device won’t boot anymore. Or destroy the radio data of MS14 which may lead to a poor wifi performance or incorrect MAC addresses.

Recover in Linux is similar with Windows, the mail different is that the tool use in Linux is nc and runs with nc -kul 6666. Below shows that the MS14 has been in Failsafe Netconsole mode and detected by nc.

Ubuntu to access netconsole
Personal tools