blob: 0a186cfe6a74969d6f3ef64f2c1144d6157d789f [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- This is broken by doc revisioning.
-->
<link rel="shortcut icon" href="../../../img/favicon.ico">
<title>Wi fi on arduino - Apache Mynewt</title>
<link href="../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
<link rel="stylesheet" href="../../../css/highlight.css">
<link href="../../../css/base.css" rel="stylesheet">
<link href="../../../css/custom.css" rel="stylesheet">
<link href="../../../css/v2.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<script>
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-72162311-1", "auto");
ga("send", "pageview");
</script>
</head>
<body class="Wi fi on arduino">
<div class="container">
<div class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="/img/logo.png">
</a>
<div class="tagline-cell">
<h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
</div>
<div class="news-cell">
<div class="well">
<h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released (April 4, 2024)
</div>
</div>
</div>
</div>
<nav id="navbar" class="navbar navbar-inverse affix-top" data-spy="affix" data-offset-top="150" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav navbar-right">
<li
class=""
>
<a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
</li>
<li
class="important"
>
<a href="/quick-start/">Quick Start</a>
</li>
<li
class=""
>
<a href="/about/">About</a>
</li>
<li
class=""
>
<a href="/talks/">Talks</a>
</li>
<li
class="active"
>
<a href="/documentation/">Documentation</a>
</li>
<li
class=""
>
<a href="/download/">Download</a>
</li>
<li
class=""
>
<a href="/community/">Community</a>
</li>
<li
class=""
>
<a href="/events/">Events</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 v2-sidebar sidebar-container"><div id="docSidebar" class="hidden-print" role="complementary">
<div class="top">
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search documentation" />
</div>
</form>
</div>
</div>
<ul class="toc-nav">
<li class="doc-version"><select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest">
Version: master
</option>
<option value="/v1_12_0/" >
Version: 1.12.0
</option>
<option value="/v1_11_0/" >
Version: 1.11.0
</option>
<option value="/v1_10_0/" >
Version: 1.10.0
</option>
<option value="/v1_9_0/" >
Version: 1.9.0
</option>
<option value="/v1_8_0/" >
Version: 1.8.0
</option>
<option value="/v1_7_0/" >
Version: 1.7.0
</option>
<option value="/v1_6_0/" >
Version: 1.6.0
</option>
<option value="/v1_5_0/" >
Version: 1.5.0
</option>
<option value="/v1_4_0/" >
Version: 1.4.0
</option>
<option value="/v1_3_0/os/introduction" >
Version: 1.3.0
</option>
<option value="/v1_2_0/os/introduction" >
Version: 1.2.0
</option>
<option value="/v1_1_0/os/introduction" >
Version: 1.1.0
</option>
<option value="/v1_0_0/os/introduction" >
Version: 1.0.0
</option>
<option value="/v0_9_0/os/introduction" selected="selected" >
Version: 0.9.0
</option>
</select></li>
<li ><a href="../../introduction/">Mynewt Documentation</a>
</li>
<li><a href="
../../../faq/how_to_edit_docs/
">Appendix</a>
</li>
</ul>
</div></div>
<div class="col-md-9" role="main">
<div class="doc-header">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="/documentation/">Docs</a></li>
<li>&raquo; Wi fi on arduino</li>
</ul>
</div>
</div>
<div class="alert alert-warning">
<p>
Version 0.9.0 is not the most recent version of the Apache Mynewt
documentation. Click <a href="/latest">here</a> to read the latest
version.
</p>
</div>
<h2 id="start-wi-fi-on-arduino-zero">Start Wi-Fi on Arduino Zero</h2>
<p>This tutorial walks you through the steps to get your Arduino board on a Wi-Fi network.</p>
<p><strong>Note:</strong> Wi-Fi support is currently available in the <code>develop</code> branch of Mynewt only. It will be merged into <code>master</code> branch when version 0.10 is released.</p>
<h3 id="prerequisites">Prerequisites</h3>
<p>Before tackling this tutorial, it's best to read about Mynewt in the <a href="../get_started/get_started">Introduction</a> section of this documentation.</p>
<h3 id="equipment">Equipment</h3>
<p>You will need the following equipment</p>
<ul>
<li>An Arduino Zero, Zero Pro or M0 Pro.<br />
<strong>Note:</strong> Mynewt has not been tested on Arduino M0 which has no internal debugger support.</li>
<li>An <a href="https://www.adafruit.com/product/2891">Arduino Wi-Fi Shield 101</a></li>
<li>A computer that can connect to the Arduino board over USB</li>
<li>A local Wi-Fi network that the computer is connected to and which the Arduino board can join.</li>
<li>A USB cable (Type A to micro B) that can connect the computer to the Arduino (or a USB hub between the computer and the Arduino board)</li>
<li>The Mynewt Release</li>
</ul>
<h3 id="install-mynewt-and-newt">Install Mynewt and Newt</h3>
<ul>
<li>If you have not already done so, install Newt as shown in the <a href="../../../newt/install/newt_mac/">Newt install tutorial</a>.</li>
<li>If you installed Newt previously but need to update it, go to the newt git repo directory, pull the latest code from <code>develop</code> branch, and install the updated code.</li>
</ul>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code> user@~/dev$ cd $GOPATH/src/mynewt.apache.org/newt
user@~/dev/go/src/mynewt.apache.org/newt$ git remote -v
origin https://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt.git (fetch)
origin https://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt.git (push)
user@~/dev/go/src/mynewt.apache.org/newt$ git pull origin develop
remote: Counting objects: 59, done.
&lt;snip&gt;
user@~/dev/go/src/mynewt.apache.org/newt$ cd newt
user@~/dev/go/src/mynewt.apache.org/newt/newt$ go install
user@~/dev$ cd ~/dev
</code></pre></div>
<ul>
<li>If you have not already done so, create a project as shown in the Quick Start guide on how to <a href="../../get_started/project_create/">Create Your First Project</a>. Skip the testing and building the project steps in that tutorial since you will be defining a target for your Arduino board in this tutorial.</li>
</ul>
<p>Let's say your new project is named <code>arduinowifi</code>. You will henceforth be working in that project directory.</p>
<p><br></p>
<h3 id="fetch-external-packages-set-correct-version-to-download">Fetch External Packages, Set correct version to download</h3>
<p>Mynewt uses source code provided directly from the chip manufacturer for
low level operations. Sometimes this code is licensed only for the specific manufacturer of the chipset and cannot live in the Apache Mynewt repository. That happens to be the case for the Arduino Zero board which uses Atmel SAMD21. Runtime's github repository hosts such external third-party packages and the Newt tool can fetch them.</p>
<p>To fetch the package with MCU support for Atmel SAMD21 for Arduino Zero from the Runtime git repository, you need to add
the repository to the <code>project.yml</code> file in your base project directory (<code>arduinowifi</code>).</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>user@~/dev/arduinowifi$ vi project.yml
</code></pre></div>
<p>Here is an example <code>project.yml</code> file with the Arduino Zero repository
added. The sections with <code>mynewt_arduino_zero</code> that need to be added to
your project file are highlighted.</p>
<p>Also highlighted is the <code>0-dev</code> version for both the repositories to ensure code is downloaded from the <code>develop</code> branch.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ more project.yml
project.name: &quot;my_project&quot;
project.repositories:
- apache-mynewt-core
<span style="background-color: #ffffcc"> - mynewt_arduino_zero
</span>
repository.apache-mynewt-core:
type: github
<span style="background-color: #ffffcc"> vers: 0-dev
</span> user: apache
repo: incubator-mynewt-core
<span style="background-color: #ffffcc">repository.mynewt_arduino_zero:
</span><span style="background-color: #ffffcc"> type: github
</span><span style="background-color: #ffffcc"> vers: 0-dev
</span><span style="background-color: #ffffcc"> user: runtimeinc
</span><span style="background-color: #ffffcc"> repo: mynewt_arduino_zero
</span>$
</code></pre></div>
<p><br></p>
<p>Once you've edited your <code>project.yml</code> file, the next step is to install the
project dependencies, this can be done with the <code>newt install</code> command
(to see more output, provide the <code>-v</code> verbose option.):</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt install
apache-mynewt-core
mynewt_arduino_zero
$
</code></pre></div>
<p><br></p>
<h3 id="create-your-bootloader-target">Create your bootloader target</h3>
<p>Next, you need to tell Newt what to build. For the Arduino Zero, we are going to
generate both a bootloader, and an image target.</p>
<p>To generate the bootloader target, you need to specify the following options. The output of the commands (indicating success) have been suppressed for easier readability.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt target create arduino_boot
$ newt target set arduino_boot bsp=@mynewt_arduino_zero/hw/bsp/arduino_zero
$ newt target set arduino_boot app=@apache-mynewt-core/apps/boot
$ newt target set arduino_boot build_profile=optimized
</code></pre></div>
<p><br></p>
<p>If you have an Arduino Zero Pro or M0 Pro, you have to set the following next:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt target set arduino_boot features=arduino_zero_pro
</code></pre></div>
<p>If you have an Arduino Zero, you have to set the following instead:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt target set arduino_boot features=arduino_zero
</code></pre></div>
<p><br></p>
<h3 id="build-your-bootloader">Build your bootloader</h3>
<p>Once you've configured the bootloader target, the next step is to build the bootloader for your Arduino. You can do this by using the <code>newt build</code> command:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt build arduino_boot
Compiling boot.c
Archiving boot.a
Compiling fs_cli.c
Compiling fs_dirent.c
Compiling fs_file.c
Compiling fs_mkdir.c
&lt;snip&gt;
App successfully built: ~/dev/arduinowifi/bin/arduino_boot/apps/boot/boot.elf
</code></pre></div>
<p>If this command finishes successfully, you have successfully built the Arduino
bootloader, and the next step is to build your application for the Arduino
board.</p>
<p><br></p>
<h3 id="build-your-blinky-app">Build your blinky app</h3>
<p>To create and download your application, you create another target, this one pointing to the application you want to download to the Arduino board. In this tutorial, we will use the Wi-Fi application that comes in the arduino repository, <code>apps/winc1500_wifi</code>:</p>
<p><strong>Note</strong>: Remember to set features to <code>arduino_zero</code> if your board is Arduino Zero and not a Pro!</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt target create arduino_wifi
$ newt target set arduino_wifi app=@mynewt_arduino_zero/apps/winc1500_wifi
$ newt target set arduino_wifi bsp=@mynewt_arduino_zero/hw/bsp/arduino_zero
$ newt target set arduino_wifi build_profile=debug
<span style="background-color: #ffffcc">$ newt target set arduino_wifi features=arduino_zero_pro
</span></code></pre></div>
<p><br></p>
<p>You can now build the target, with <code>newt build</code>:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt build arduino_wifi
Building target targets/arduino_wifi
Compiling main.c
Archiving winc1500_wifi.a
Compiling fs_cli.c
Compiling fs_dirent.c
Compiling fs_file.c
Compiling fs_mkdir.c
&lt;snip&gt;
Linking winc1500_wifi.elf
App successfully built: ~/dev/arduinowifi/bin/arduino_wifi/apps/winc1500_wifi/winc1500_wifi.elf
</code></pre></div>
<p><font color="#FF0000"> Congratulations! </font> You have successfully built your Wi-Fi application. Now it's time to load both the bootloader and application onto the target.</p>
<p><br></p>
<h3 id="connect-the-target">Connect the Target</h3>
<p>Place the Wi-Fi shield on top of the Arduino board and push it in place, making sure the pins and pinholes are properly aligned. Connect your computer to the Arduino board with the Micro-USB cable through the Programming Port as shown below. Mynewt will download and debug the target through this port. You should see a little green LED come on. That means the board has power.</p>
<p>No external debugger is required. The Arduino boards listed in this tutorial come with an internal debugger that can be accessed by Mynewt.</p>
<p>The picture below shows the setup.</p>
<p><img alt="Arduino with Wi-Fi shield" src="pics/arduino_wifi.png" title="WifiShield" /></p>
<p><br></p>
<h3 id="download-the-bootloader">Download the Bootloader</h3>
<p>Execute the command to download the bootloader.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code> <span style="color: #000000">$</span> <span style="color: #000000">newt</span> <span style="color: #000000">load</span> <span style="color: #000000">arduino_boot</span>
</code></pre></div>
<p>If the newt tool finishes without error, that means the bootloader has been
successfully loaded onto the target.</p>
<p><br></p>
<p><font color="#FF0000"> Reminder if you are using Docker: </font> When working with actual hardware, remember that each board has an ID. If you swap boards and do not refresh the USB Device Filter on the VirtualBox UI, the ID might be stale and the Docker instance may not be able to see the board correctly. For example, you may see an error message like <code>Error: unable to find CMSIS-DAP device</code> when you try to load or run an image on the board. In that case, you need to click on the USB link in VirtualBox UI, remove the existing USB Device Filter (e.g. "Atmel Corp. EDBG CMSIS-DAP[0101]") by clicking on the "Removes selected USB filter" button, and add a new filter by clicking on the "Adds new USB filter" button.</p>
<p><br></p>
<h3 id="load-the-application-image">Load the Application Image</h3>
<p>Now that the bootloader is downloaded to the target, the next steps are to create an image and load it onto the target device.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ newt create-image arduino_wifi 1.0.0
App image succesfully generated: ~/dev/arduinowifi/bin/arduino_wifi/apps/winc1500_wifi/winc1500_wifi.img
Build manifest: ~/dev/arduinowifi/bin/arduino_wifi/apps/winc1500_wifi/manifest.json
$ newt load arduino_wifi
Loading image
$
</code></pre></div>
<p><br></p>
<h3 id="start-wi-fi-via-console">Start Wi-Fi via console</h3>
<p>Use a terminal emulation program to communicate with the board over the serial port. This tutorial shows a Minicom set up. You will have to find out what the usbserial port number is on your computer/laptop (<code>ls /dev</code>) and specify it as the -D flag value. Type <code>wifi start</code> to start Wi-Fi.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ minicom -D /dev/tty.usbmodem141122 -b 115200
Welcome to minicom 2.7
OPTIONS:
Compiled on Nov 24 2015, 16:14:21.
Port /dev/tty.usbmodem141122, 10:11:40
Press Meta-Z for help on special keys
<span style="background-color: #ffffcc">wifi start
</span>119470:(APP)(INFO)Chip ID 1502b1
(APP)(INFO)Firmware ver : 19.4.4
(APP)(INFO)Min driver ver : 19.3.0
(APP)(INFO)Curr driver ver: 19.3.0
wifi_init : 0
</code></pre></div>
<p>Connect to the local Wi-Fi network. Then start network services. The commands to be issued are highlighted below. In the example below, the network interface on the Arduino board gets an IP address of <code>192.168.0.117</code>.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="background-color: #ffffcc">wifi connect &lt;Wi-Fi network name&gt; &lt;password&gt;
</span>16906:wifi_request_scan : 0
17805:scan_results 16: 0
17816:wifi_connect : 0
18813:connect_done : 0
18821:dhcp done 192.168.0.117
18932:get sys time response 2016.8.2-18.4.43
<span style="background-color: #ffffcc">net service
</span></code></pre></div>
<h3 id="establish-tcp-connection-and-talk">Establish TCP connection and talk!</h3>
<p>From a terminal on your computer/laptop, try telneting to ports 7, 9, or 19 using the IP address your board has been assigned. Type something on this terminal and see the console output (on minicom). Can you see the difference in the behaviors?</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>$ telnet 192.168.0.117 7
Trying 192.168.0.117...
Connected to 192.168.0.117.
Escape character is &#39;^]&#39;.
hello
hello
^]
telnet&gt; q
$
</code></pre></div>
<p>One port echoes whatever is typed, one discards everything it gets, and the third spews out bits constantly. Type <code>wifi stop</code> to disable WiFi on the Arduino board.</p>
<p>Hope you had fun!</p>
<div class="row">
<ul class="nav nav-pills" style="margin-bottom: 10px">
<li>
</li>
<li class="pull-right">
</li>
</ul>
</div>
<footer class="row">
<div class="col-xs-12">
<p class="copyright">Apache Mynewt (incubating) is available under Apache License, version 2.0.</p>
</div>
<div class="col-xs-12">
<div class="logos">
<a href="https://www.apache.org/">
<img src="/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
</a>
<p>
Copyright © 2015-2021 The Apache Software Foundation.<br>
<small class="footnote">
Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt
project logo are either registered trademarks or trademarks of the Apache
Software Foundation in the United States and other countries.
</small>
</p>
<a href="">
<img src="https://www.countit.com/images/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
<a href="https://www.apache.org/licenses/">
<button class="button-footer-asf">
License
</button>
</a>
<a href="https://www.apache.org/foundation/sponsorship.html">
<button class="button-footer-asf">
Sponsorship
</button>
</a>
<a href="https://www.apache.org/foundation/thanks.html">
<button class="button-footer-asf">
Thanks
</button>
</a>
<a href="https://www.apache.org/security/">
<button class="button-footer-asf">
Security
</button>
</a>
<a href="https://apache.org/events/current-event">
<button class="button-footer-asf">
ASF Events
</button>
</a>
</footer>
</div>
</div>
</div>
<script src="../../../js/jquery-1.10.2.min.js"></script>
<script src="../../../js/bootstrap-3.0.3.min.js"></script>
<script src="../../../js/highlight.pack.js"></script>
<script src="../../../js/base.js"></script>
<script src="../../../js/custom.js"></script>
<script src="search/main.js"></script>
</body>
</html>