Getting Start with Arduino Yun

From Wiki for Dragino Project

Jump to: navigation, search

Contents

Introduction

Dragino ms14 is able to run Arduino Yun software and provide great features what Arduino Yun provides. The firmware can be downloaded from This Link

This page provides necessary info of how to use ms14 for Arduino 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

Difference between Dragino ms14 and Arduino Yun hardware

Diagram Difference between Arduino Yun and Dragino MS14
Connect Dragino MS14 with a Lenoardo

The official Arduino Yun hardware MS14 runs the same Yun software. The main differences between them is:

  • Arudino Yun hardware combine the Linux CPU and avr into the same piece hardware.
  • Dragino ms14 only includes the Linux CPU part. user are free to customized the avr side to release different products.

Web GUI

At the first time you boot the ms14 (with Yun firmware loaded), there will be an unsecure wifi network start with Arduino Yun - xxxxxxxxxxxx show in wifi connection.

Yun act as a wifi AP by default


Use a computer to connect to this wifi network. The PC will get an ip at this network 192.168.240.xxx. The ms14 has a default ip address 192.168.240.1. So we can enter 192.168.240.1 into the broswer and see the configure page of ms14.

Yun web log in page


After log in, the gui will show the WIFI / ETH interface status. Click the Configure button and now we can configure the network parameters.

Yun web configure page 1 -- System Password Config
Yun web configure page 2 -- WiFi Client Config

Detect ms14 Yun

Once the MS14 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 AVR

With Yun software, user can upgrade the AVR remotely in Arduino IDE. We support different kind of Arduino boards now. User can check them in the GUI--> Sensor page

Select the correct boardtype

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



Customized Board Type

If user don't have the default board type, then we have modified the Arduino IDE and the MS14 to support the remote upload feature. Below is an example for how to modify the Arduino IDE to support mrfm12b which has a mega168 mcu.

Customized Board Type in Arduino IDE

To add customized board type, we have to modify the board.txt info of Arduino IDE. In a Windows 7 machine, the boards.txt file is in C:Program Files\Arduino\hardware\arduino\avr. Open this file and copy the Yun definition and append it below Yun definition with a new name. below is definition for mrfm12b as an example.

  1. ##############################################################
  2.  
  3. MRFM12B.name=Dragino MRFM12B
  4. MRFM12B.upload.via_ssh=true
  5. MRFM12B.vid.0=0x2341
  6. MRFM12B.pid.0=0x0041
  7. MRFM12B.vid.1=0x2341
  8. MRFM12B.pid.1=0x8041
  9. MRFM12B.upload.tool=avrdude
  10. MRFM12B.upload.protocol=avr109
  11. MRFM12B.upload.maximum_size=14336
  12. MRFM12B.upload.maximum_data_size=1024
  13. MRFM12B.upload.speed=57600
  14. MRFM12B.upload.disable_flushing=true
  15. MRFM12B.upload.use_1200bps_touch=true
  16. MRFM12B.upload.wait_for_upload_port=true
  17.  
  18. MRFM12B.bootloader.tool=avrdude
  19. MRFM12B.bootloader.low_fuses='''0xff'''
  20. MRFM12B.bootloader.high_fuses=0xdd
  21. MRFM12B.bootloader.extended_fuses=0x00
  22. MRFM12B.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex
  23. MRFM12B.bootloader.unlock_bits=0x3F
  24. MRFM12B.bootloader.lock_bits=0x2F
  25.  
  26. MRFM12B.build.mcu=atmega168
  27. MRFM12B.build.f_cpu=16000000L
  28. MRFM12B.build.vid=0x2341
  29. MRFM12B.build.pid=0x8041
  30. MRFM12B.build.usb_product="Arduino Yun"
  31. MRFM12B.build.board=AVR_YUN
  32. MRFM12B.build.core=arduino
  33. MRFM12B.build.variant=standard
  34. ##MRFM12B.build.extra_flags={build.usb_flags}


After above change, restart the Arduino IDE and the DRAGINO MRFM12B board type will be shown under tools --> board menu.

Add a New Board Type in Arduino IDE




/etc/avrdude.conf, to check how the ar9331 gpio pin connect to the avr. Below example shows

Dragino MS14 AVRs Logic Level
GPIO20 /RESET invert
GPIO18 SCK same
GPIO21 MOSI same
GPIO22 MISO same
  1. #To check if your avrdude build has support for the linuxgpio programmer compiled in,
  2. #use -c?type on the command line and look for linuxgpio in the list. If it's not available
  3. #you need pass the --enable-linuxgpio=yes option to configure and recompile avrdude.
  4. #
  5. programmer
  6.   id    = "linuxgpio";
  7.   desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  8.   type  = "linuxgpio";
  9. # for DS1 board
  10. #  reset = ~18;
  11. # for DS2 board
  12. #  reset = ~7;
  13. # for DS2_B board
  14.   reset = ~20;     
  15.   sck   = 18;
  16. # mosi  = 6;
  17.   mosi = 21;
  18.   miso  = 22;
  19. ;



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 the avr module.

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

Compile and Upload sketch in Arduino IDE



Connect Leonardo to MS14

The Leonardo has two serial interface, 1) hardware serial via digital pin 0 and digital pin 1. 2) virtual serial via the USB port. The USB port can be used to program Leonardo from computer, the hardware serial is used to connect to MS14 and use the bridge feature of Arduino Yun. There are three pins need to be connected, as below:

Lenardo.gnd -- MS14.gnd
Lenardo.digital.0 -- MS14.UART_TX
Lenardo.digital.1 -- 10K ohm -- MS14.UART_RX
Connect Leonardo to MS14

After the connection, we can test with the Console Read example sketch from Arduino IDE.

  1. /*
  2.   Console Read example
  3.  
  4.  Read data coming from bridge using the Console.read() function
  5.  and store it in a string.
  6.   
  7.  To see the Console, pick your Yún's name and IP address in the Port menu
  8.  then open the Port Monitor. You can also see it by opening a terminal window
  9.  and typing: 
  10.  ssh root@ yourYunsName.local 'telnet localhost 6571'
  11.  then pressing enter. When prompted for the password, enter it.
  12.   
  13.  created 13 Jun 2013
  14.  by Angelo Scialabba 
  15.  modified 16 June 2013
  16.  by Tom Igoe
  17.   
  18.  This example code is in the public domain.
  19.   
  20.  http://arduino.cc/en/Tutorial/ConsoleRead
  21.   
  22.  */
  23.  
  24. #include <Console.h>
  25.  
  26. String name;
  27.  
  28. void setup() {
  29.   // Initialize Console and wait for port to open:
  30.   Bridge.begin();
  31.   Console.begin(); 
  32.  
  33.   // Wait for Console port to connect
  34.   while (!Console); 
  35.  
  36.   Console.println("Hi, what's your name?");
  37. } 
  38.  
  39. void loop() {
  40.   if (Console.available() > 0) {
  41.     char c = Console.read(); // read the next char received
  42.     // look for the newline character, this is the last character in the string
  43.     if (c == '\n') {
  44.       //print text with the name received
  45.       Console.print("Hi ");
  46.       Console.print(name);
  47.       Console.println("! Nice to meet you!");
  48.       Console.println();
  49.       // Ask again for name and clear the old name
  50.       Console.println("Hi, what's your name?");
  51.       name = "";  // clear the name string
  52.     } 
  53.     else {       // if the buffer is empty Cosole.read() returns -1
  54.       name += c; // append the read char from Console to the name string
  55.     }
  56.   }
  57. }

This code can be found in the Arduino IDE example --> bridge, compile and upload the code without change. What should notice is that while compile and upload the code. The Arduino IDE --> tools --> port need to set to USB COM port instead of Arduino Yun because the upload will use the USB com port.

After the code is upload, switch the com port to Arduino and use the serial monitor to see the result. If everything is fine, the test result will shown as below:

Console Read Example



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 MS14 Firmware

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 ms14. Then you can upgrade the firmware from WEB GUI. Otherwise, you will have to upgrade the firmware in the u-boot.


Upgrade via WEB GUI

Once you have a Yun firmware, you can upgrade the firmware via WEB GUI.

Access Advance Configuration Page

Open the page System --> Firmware Flash, The upgrade method is well explained in the page as shown below:

Update Firmware via WEB GUI

What should be notice is that the firmware use for Web upgrade is xxx.squashfs-sysupgrade.bin


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 192.168.255.2 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 OpenWrt Mesh firmware without UART

The Yun firmware and the Dragino2 build mesh firmware has different flash layout and boot address. Switch firmware between these two kind of firmware require the access to the u-boot

The new shipped MS14 has the Web-FailSafe U-Boot. User can use the Web-FailSafe u-boot to upgrade from Arduino Yun firmware to the mesh firmware via Web Page.

The instruction of how to use this u-boot is HERE.

After the upgrade, user has to set the proper boot address for mesh firmware as well. This can be done via u-boot netconsole mode. The required command for change the boot address for mesh firmware is:

dr_boot> setenv bootcmd bootm 0x9f040000
dr_boot> saveenv
dr_boot> reset

Once the mesh firmware is uploadded sucessfully and has the proper boot address. The ms14 will boot to mesh firmware.


In case user has a early ms14 and don't have web-failsafe u-boot. They can first upgrade to the Yun firmware to Yun-MiddleWare Firmware Link.

After upgrade, ssh access to the MS14 and run below command to flash the device with Web_FailSafe u-boot.

root@dragino2:~# mtd write /etc/failsafe_u-boot_for_dragino_HE_MS14.bin u-boot
Unlocking u-boot ...
Writing from /etc/failsafe_u-boot_for_dragino_HE_MS14.bin to u-boot ...     
root@dragino2:~# reboot



Examples

CLICK HERE for some detail examples.

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


Trouble Shooting

Update Sketch Error:

Shows below error in Arduino IDE.

avrdude: ERROR: address 0x7010 out of range at line 583 of /tmp/sketch.hex
avrdude: read from file '/tmp/sketch.hex' failed

Check: Check if you have Select the Correct Bootloader


Recover MS14 firmware

User may lost access to the MS14 by accidently change the Linux configure files to in correct setting, lost password or other caused. He or she is still able to recover the MS14 by using the Failsafe u-boot.

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 http://www.dragino.com/downloads/index.php?dir=motherboards/ms14/Firmware/Yun/. 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: 192.168.255.1 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 192.168.255.2 and netmask 255.255.255.0. 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

reset

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