Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
<!DOCTYPE html>
<html lang="en" class="js csstransforms3d">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="generator" content="Hugo 0.42.1" />
<meta name="description" content="All about the NodeConf EU Badge">
<meta name="author" content="NearForm">
<link rel="shortcut icon" href="/images/favicon.png" type="image/x-icon" />
<link rel="icon" href="/images/favicon.png" type="image/x-icon" />
<title> :: NodeConf EU Badge</title>
<link href="/css/nucleus.css?1541954405" rel="stylesheet">
<link href="/css/font-awesome.min.css?1541954405" rel="stylesheet">
<link href="/css/hybrid.css?1541954405" rel="stylesheet">
<link href="/css/featherlight.min.css?1541954405" rel="stylesheet">
<link href="/css/perfect-scrollbar.min.css?1541954405" rel="stylesheet">
<link href="/css/auto-complete.css?1541954405" rel="stylesheet">
<link href="/css/theme.css?1541954405" rel="stylesheet">
<link href="/css/hugo-theme.css?1541954405" rel="stylesheet">
<script src="/js/jquery-2.x.min.js?1541954405"></script>
<style type="text/css">
:root #header + #content > #left > #rlblock_left{
display:none !important;
}
</style>
</head>
<body class="" data-url="/">
<nav id="sidebar" class="">
<div id="header-wrapper">
<div id="header">
<a href="/"><img src="/images/logo.png" /></a>
</div>
<div class="searchbox">
<label for="search-by"><i class="fa fa-search"></i></label>
<input data-search-input id="search-by" type="text" placeholder="Search...">
<span data-search-clear=""><i class="fa fa-close"></i></span>
</div>
<script type="text/javascript" src="/js/lunr.min.js?1541954405"></script>
<script type="text/javascript" src="/js/auto-complete.js?1541954405"></script>
<script type="text/javascript">
var baseurl = "http:\/\/nodeconfeubadge.org";
</script>
<script type="text/javascript" src="/js/search.js?1541954405"></script>
</div>
<div class="highlightable">
<ul class="topics">
<li data-nav-id="/2017badge/" title="2017badges" class="dd-item
">
<a href="/2017badge/">
2017badges
</a>
<ul>
<li data-nav-id="/2017badge/getting-started/" title="Getting Started" class="dd-item
">
<a href="/2017badge/getting-started/">
Getting Started
</a>
<ul>
<li data-nav-id="/2017badge/getting-started/unlocking-your-badge/" title="Unlocking Your Badge" class="dd-item ">
<a href="/2017badge/getting-started/unlocking-your-badge/">
Unlocking Your Badge
</a>
</li>
<li data-nav-id="/2017badge/getting-started/built-in-software/" title="Built-in Software" class="dd-item ">
<a href="/2017badge/getting-started/built-in-software/">
Built-in Software
</a>
</li>
<li data-nav-id="/2017badge/getting-started/connecting-to-the-badge/" title="Connecting to the Badge" class="dd-item ">
<a href="/2017badge/getting-started/connecting-to-the-badge/">
Connecting to the Badge
</a>
</li>
<li data-nav-id="/2017badge/getting-started/hello-world-console/" title="Hello World on the Console" class="dd-item ">
<a href="/2017badge/getting-started/hello-world-console/">
Hello World on the Console
</a>
</li>
<li data-nav-id="/2017badge/getting-started/other-code-samples/" title="Other Code Samples" class="dd-item ">
<a href="/2017badge/getting-started/other-code-samples/">
Other Code Samples
</a>
</li>
<li data-nav-id="/2017badge/getting-started/accessing-hardware-features/" title="Accessing Hardware Features" class="dd-item ">
<a href="/2017badge/getting-started/accessing-hardware-features/">
Accessing Hardware Features
</a>
</li>
<li data-nav-id="/2017badge/getting-started/using-prototyping-area/" title="Using the prototyping area and corners" class="dd-item ">
<a href="/2017badge/getting-started/using-prototyping-area/">
Using the prototyping area and corners
</a>
</li>
<li data-nav-id="/2017badge/getting-started/faq/" title="FAQ" class="dd-item ">
<a href="/2017badge/getting-started/faq/">
FAQ
</a>
</li>
</ul>
</li>
<li data-nav-id="/2017badge/challenges/" title="Challenges" class="dd-item
">
<a href="/2017badge/challenges/">
Challenges
</a>
<ul>
<li data-nav-id="/2017badge/challenges/hello-world-screen/" title="Hello World on screen" class="dd-item ">
<a href="/2017badge/challenges/hello-world-screen/">
Hello World on screen
</a>
</li>
<li data-nav-id="/2017badge/challenges/detect-button-press/" title="Detect Button Press" class="dd-item ">
<a href="/2017badge/challenges/detect-button-press/">
Detect Button Press
</a>
</li>
<li data-nav-id="/2017badge/challenges/detect-capacitive-touch/" title="Detect Capacitive Touch" class="dd-item ">
<a href="/2017badge/challenges/detect-capacitive-touch/">
Detect Capacitive Touch
</a>
</li>
<li data-nav-id="/2017badge/challenges/flash-leds/" title="Flash LEDs" class="dd-item ">
<a href="/2017badge/challenges/flash-leds/">
Flash LEDs
</a>
</li>
<li data-nav-id="/2017badge/challenges/play-music-with-buzzer/" title="Play Music with Buzzer" class="dd-item ">
<a href="/2017badge/challenges/play-music-with-buzzer/">
Play Music with Buzzer
</a>
</li>
<li data-nav-id="/2017badge/challenges/on-screen-menu/" title="On-Screen Menu" class="dd-item ">
<a href="/2017badge/challenges/on-screen-menu/">
On-Screen Menu
</a>
</li>
<li data-nav-id="/2017badge/challenges/broadcast-nfc-url/" title="Broadcast NFC URL" class="dd-item ">
<a href="/2017badge/challenges/broadcast-nfc-url/">
Broadcast NFC URL
</a>
</li>
<li data-nav-id="/2017badge/challenges/broadcast-beacons/" title="Broadcast Beacons" class="dd-item ">
<a href="/2017badge/challenges/broadcast-beacons/">
Broadcast Beacons
</a>
</li>
<li data-nav-id="/2017badge/challenges/use-noble-on-laptop/" title="Use Noble on Laptop" class="dd-item ">
<a href="/2017badge/challenges/use-noble-on-laptop/">
Use Noble on Laptop
</a>
</li>
<li data-nav-id="/2017badge/challenges/use-badge-for-hid/" title="Use the Badge as a HID Button" class="dd-item ">
<a href="/2017badge/challenges/use-badge-for-hid/">
Use the Badge as a HID Button
</a>
</li>
<li data-nav-id="/2017badge/challenges/display-an-image/" title="Display an Image" class="dd-item ">
<a href="/2017badge/challenges/display-an-image/">
Display an Image
</a>
</li>
<li data-nav-id="/2017badge/challenges/create-web-bluetooth-page/" title="Create a Web Bluetooth Page" class="dd-item ">
<a href="/2017badge/challenges/create-web-bluetooth-page/">
Create a Web Bluetooth Page
</a>
</li>
<li data-nav-id="/2017badge/challenges/detect-person-with-pir-sensor/" title="Detect movement with a PIR Sensor" class="dd-item ">
<a href="/2017badge/challenges/detect-person-with-pir-sensor/">
Detect movement with a PIR Sensor
</a>
</li>
<li data-nav-id="/2017badge/challenges/connect-to-ble-lightbulb/" title="Connect to BLE Lightbulb" class="dd-item ">
<a href="/2017badge/challenges/connect-to-ble-lightbulb/">
Connect to BLE Lightbulb
</a>
</li>
<li data-nav-id="/2017badge/challenges/connect-to-ble-led-strip/" title="Connect to BLE LED Strip" class="dd-item ">
<a href="/2017badge/challenges/connect-to-ble-led-strip/">
Connect to BLE LED Strip
</a>
</li>
<li data-nav-id="/2017badge/challenges/communicate-with-another-badge/" title="Communicate with another Badge" class="dd-item ">
<a href="/2017badge/challenges/communicate-with-another-badge/">
Communicate with another Badge
</a>
</li>
<li data-nav-id="/2017badge/challenges/communicate-with-other-ble-device/" title="Communicate with another Device" class="dd-item ">
<a href="/2017badge/challenges/communicate-with-other-ble-device/">
Communicate with another Device
</a>
</li>
<li data-nav-id="/2017badge/challenges/implement-dat-protocol/" title="Implement Dat Protocol" class="dd-item ">
<a href="/2017badge/challenges/implement-dat-protocol/">
Implement Dat Protocol
</a>
</li>
</ul>
</li>
<li data-nav-id="/2017badge/workshop/" title="Workshop" class="dd-item
">
<a href="/2017badge/workshop/">
Workshop
</a>
<ul>
<li data-nav-id="/2017badge/workshop/get-connected/" title="Get Connected" class="dd-item ">
<a href="/2017badge/workshop/get-connected/">
Get Connected
</a>
</li>
<li data-nav-id="/2017badge/workshop/clean-slate/" title="Clean Slate" class="dd-item ">
<a href="/2017badge/workshop/clean-slate/">
Clean Slate
</a>
</li>
<li data-nav-id="/2017badge/workshop/capacitive-sense/" title="Capacitive Sense" class="dd-item ">
<a href="/2017badge/workshop/capacitive-sense/">
Capacitive Sense
</a>
</li>
<li data-nav-id="/2017badge/workshop/graphics/" title="Graphics" class="dd-item ">
<a href="/2017badge/workshop/graphics/">
Graphics
</a>
</li>
<li data-nav-id="/2017badge/workshop/sound/" title="Sound" class="dd-item ">
<a href="/2017badge/workshop/sound/">
Sound
</a>
</li>
<li data-nav-id="/2017badge/workshop/making-a-game/" title="Making a Game" class="dd-item ">
<a href="/2017badge/workshop/making-a-game/">
Making a Game
</a>
</li>
<li data-nav-id="/2017badge/workshop/what-next/" title="What next?" class="dd-item ">
<a href="/2017badge/workshop/what-next/">
What next?
</a>
</li>
<li data-nav-id="/2017badge/workshop/adding-to-the-menu/" title="Adding to your Badge's menu" class="dd-item ">
<a href="/2017badge/workshop/adding-to-the-menu/">
Adding to your Badge's menu
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<section id="footer">
<p>Built using the
<a href="https://github.com/matcornic/hugo-theme-learn">Learn</a> theme on
<a href="http://gohugo.io/">Hugo</a> ported from
<a href="http://getgrav.org">Grav</a>.
</p>
</section>
</div>
</nav>
<section id="body">
<div id="overlay"></div>
<div class="padding highlightable sticky-parent">
<div id="body-inner">
<span id="sidebar-toggle-span">
<a href="#" id="sidebar-toggle" data-sidebar-toggle=""><i class="fa fa-bars"></i> navigation</a>
</span>
<h1 id="the-nodeconf-eu-2018-badge">The NodeConf EU 2018 Badge</h1>
<p>Welcome!</p>
<p>We hope you are as excited as we are about the badge. We’ve spent the past few months designing and preparing it for the event.</p>
<p>The blog post announcing the badge is <a href="https://www.nearform.com/blog/the-nodeconf-eu-2018-digital-badge-is-here-and-its-fabulous/">here</a>.</p>
<h2 id="the-badge">The Badge</h2>
<p>The badge contains a small but powerful Bluetooth LE module running <a href="https://www.espruino.com">Espruino</a> software, which is a JavaScript interpreter optimised for low-power devices. On this site, we’ll explain the basics of using and programming the badge and even how to add hardware to it.</p>
<p>Note that all of the software and hardware for this year’s badge will be Open Sourced shortly after NodeConf EU 2018 is over.</p>
<h2 id="changing-your-name-on-the-badge">Changing your name on the badge</h2>
<p>This was the top request during NodeConf EU so we’ve made it as easy as possible. Just <a href="https://nearform.github.io/nceubadge2018/namechanger.html">go here</a> and follow the simple instructions.</p>
<h2 id="quick-links">Quick Links</h2>
<ul>
<li><a href="https://github.com/nearform/nceubadge2018">GitHub Repo</a></li>
<li><a href="http://www.espruino.com/Quick+Start+BLE#pixljs">Espruino Bluetooth Getting Started</a></li>
<li><a href="http://www.espruino.com/Pixl.js">Espruino Pixl.js info</a></li>
<li><a href="https://gfwilliams.github.io/workshop-nodeconfeu2018/">Monday’s Bluetooth Workshop</a></li>
<li><a href="#returning-to-standard">Returning your badge to normal</a></li>
<li><a href="https://github.com/nearform/nceubadge2018/blob/master/js/badge.js">The Badge’s default firmare</a></li>
</ul>
<p>Please submit PRs for any apps or backlight patterns you created in:</p>
<ul>
<li><a href="https://github.com/nearform/nceubadge2018/tree/master/apps">Apps</a></li>
<li><a href="https://github.com/nearform/nceubadge2018/tree/master/patterns">Patterns</a></li>
</ul>
<p>To add them to your badge, connect with the IDE then copy and paste
them into the left-hand side of the IDE.</p>
<h2 id="getting-started">Getting Started</h2>
<p>The badge is based on a <a href="http://www.espruino.com/Pixl.js">Pixl.js</a>, so a
lot of the tutorials and information there still apply.</p>
<p>The button names can be hard to read because of the badge surround, but they
are as follows:</p>
<pre><code> ...... ......
___________________________
BTN1 | | BTN2
| |
| |
| |
BTN4 |___________________________| BTN3
::::
</code></pre>
<p>There is an on/off slider switch on th rear of the badge just by the USB connector
(which is used for charging only).</p>
<h2 id="bugs">Bugs!</h2>
<ul>
<li>On some of the badges, the vibration caused by the vibration motors during startup can
cause the LED controller to stop working. If when you power your badge on it <em>doesn’t</em> go
through all the colours of the rainbow, power it on with your thumbs over the vibration motors
at the bottom left and right of the screen.</li>
<li>If your badge stops animating while in badge mode, try just pressing a button
and it should spring back to life (updating the actual Espruino firmware can fix
this - see <a href="#updating-espruino">Updating Espruino</a> below).</li>
<li>When you charge the badge via USB, the on/off switch on the back needs to be
set to ON (with the sticky-out part nearest the USB connector) or the battery
won’t charge.</li>
<li>If you’re writing bits of code using <code>require("Storage").write('.boot...')</code>
you may eventually get errors about not being able to write (the same can happen
when trying to change settings). You can solve this by following the
<a href="#returning-to-standard">Returning your badge to normal</a> instructions -
but <a href="#updating-espruino">Updating Espruino</a> can stop it happening again as well.</li>
</ul>
<h2 id="connecting">Connecting</h2>
<p>To avoid a complete free-for-all, when the badges start with the Nodeconf badge software
they disable the ability to connect to them. To connect, you must do one of:</p>
<ul>
<li>Go to the <code>Make Connectable</code> menu item</li>
<li>Power the badge off, and power it on with <code>BTN2</code> or <code>BTN3</code> held down. The badge
firmware will be loaded, but your badge will be connectable.</li>
<li>(Not recommended) Power the badge off, and power it on with <code>BTN1</code> held down while the bootloader
percent bar goes to the end, <strong>then release when told. Do not keep holding the button
down or all saved badge code will be erased.</strong>. This initialises a self
test, which will fail (because the board isn’t quite a standard Pixl.js). This
will start your badge without loading any of the badge code.</li>
</ul>
<p>You can then use the Chrome web Browser on any Windows 10 or Mac OS device
and go to <a href="https://www.espruino.com/ide" target="_blank">espruino.com/ide</a> and you can connect.
You’re looking for a device called <code>Pixl abcd</code> where <code>abcd</code> are the last 4
characters of the MAC address shown on the Badge’s screen.</p>
<p>*If you used Espruino before, ensure that the <code>Save on Send</code> option in the
<code>Communications</code> part of the Web IDE’s settings is set to <code>To RAM</code> otherwise
you’ll overwrite the badge firmware.**</p>
<p>Check out the notes for Monday’s <a href="https://gfwilliams.github.io/workshop-nodeconfeu2018/">Bluetooth Workshop</a>
for more information.</p>
<h3 id="using-your-own-editor">Using your own Editor</h3>
<p>You can use the Espruino CLI:</p>
<pre><code>npm install -g espruino
# abcd = last 4 digits displayed on your badge
espruino -d abcd --config RESET_BEFORE_SEND=false -w filename.js
</code></pre>
<p>The <code>-w filename,js</code> option watches that file for changes, so the connection
to the badge (and REPL) will be maintained and every time you save the file
in your editor it’ll automatically upload.</p>
<p>In this case the CLI tool will upload to RAM without resetting the device,
so writing an app like this will allow you to quickly test your code:</p>
<pre><code>Badge.apps["My App"] = ()=>{
// Reset everything on the badge to a known state
Badge.reset();
// Display a menu
Pixl.menu({ "": { "title": "-- A Test --" },
"LED1 on" : ()=>LED1.write(1),
"LED1 off" : ()=>LED1.write(0),
"Back to Badge":Badge.badge
});
};
// automatically run app for testing
Badge.apps["My App"]();
</code></pre>
<h2 id="returning-to-standard">Returning to Standard</h2>
<ul>
<li><a href="https://www.espruino.com/ide/?codeurl=https://raw.githubusercontent.com/nearform/nceubadge2018/master/js/badge.js" target="_blank">Click this link</a> in Chrome</li>
<li>Change <code>Badge.NAME = ...</code> to <code>["Your", "Name"]</code> - each array element is a new line</li>
<li>Connect to your badge (see above)</li>
<li>If you’re having trouble connecting, power your badge on with <code>BTN1</code> held down for ~10 seconds (until a message about code being erased is shown) - this will remove all code from the badge and make it connectable - ready for you to re-upload the badge code.</li>
<li>Optional: Type <code>require("Storage").eraseAll()</code> in the left hand side of the IDE. This will remove all data from nonvolatile storage.</li>
<li>Turn the <code>Save on Send</code> option in the <code>Communications</code> part of the Web IDE’s settings to <code>Direct To Flash</code></li>
<li>Upload the code</li>
<li>Return the <code>Save on Send</code> option in the <code>Communications</code> part of the Web IDE’s settings to <code>To RAM</code> so you don’t accidentally overwrite the code in the future.</li>
</ul>
<p>You’re sorted!</p>
<h2 id="stuff-to-do">Stuff to do</h2>
<p>On the badge, you have a bunch of stuff you can use. Most of it is available via <code>NC</code>
in a global variable created by the badge software. If you’re trying to
do things on your own without the badge software, use <code>var NC = require("nodeconfeu2018");</code>
first.</p>
<h3 id="bluetooth">Bluetooth</h3>
<p>Check out <a href="http://www.espruino.com/Pixl.js">the Pixl.js page</a> for examples.</p>
<h3 id="led1-led2">LED1, LED2</h3>
<p>You can turn the LEDs on and off with <code>digitalWrite(LED1,1)</code> or <code>LED1.write(1)</code>. Use <code>0</code> to turn them off.</p>
<h3 id="rgb-lighting">RGB lighting</h3>
<p>The badge has fancy RGB lighting. There’s:</p>
<ul>
<li><strong>LEDs facing up</strong> - Change these with <code>NC.ledTop([R,G,B])</code> or <code>NC.ledTop([])</code> to turn them off</li>
<li><strong>LEDs facing down</strong> - Change these with <code>NC.ledBottom([R,G,B])</code> or <code>NC.ledBottom([])</code> to turn them off</li>
<li><strong>LCD backlight with 4 zones</strong> - Change this with <code>NC.backlight([B,G,R,B,G,R,B,G,R,B,G,R])</code> or <code>NC.backlight([])</code> to turn them off</li>
</ul>
<p>In the above code, <code>B/G/R</code> are numbers between 0 and 255 and represent Blue, Green and Red.</p>
<h3 id="light-sensor">Light sensor</h3>
<p>LED2 can be used as an ambient light sensor - just use <code>NC.light()</code> to get
a reading between 0 and 1.</p>
<p>It will <em>definitely</em> be thrown off by any light from any of the other on-badge LEDs.</p>
<h3 id="vibration">Vibration</h3>
<p>You can use the vibration motors just like normal pins on Espruino…</p>
<pre><code>// Use VIBL/VIBR for left and right motors
// Motor on
digitalWrite(VIBL,1);
// Motor off
digitalWrite(VIBL,0);
// Pulse motor on for 100ms
digitalPulse(VIBL,1,100);
// Pulse motor 3 times, for 100ms, with 150ms between each pulse
digitalPulse(VIBL,1,[100,150,100,150,100]);
// Or slowly ramp the speed of the motor up and down
var n = 0;
setTimeout(function cb() {
analogWrite(VIBL,Math.sin(n));
n+=0.01;
if (n<Math.PI) setTimeout(cb,20);
else digitalWrite(VIBL,0);
}, 20);
</code></pre>
<h3 id="sound">Sound</h3>
<p>The vibration motors can also be used to create (reasonably quiet) sounds.</p>
<pre><code>analogWrite(VIBL,0.05,{freq:2000}); // Make sound!
</code></pre>
<p>There are some very simple examples at <a href="http://www.espruino.com/Making+Music">http://www.espruino.com/Making+Music</a>
that will work on the vibration motor - just make sure that the second argument
of <code>analogWrite</code> (the duty cycle) is low enough that the vibration motor isn’t
turning!</p>
<h3 id="accelerometer">Accelerometer</h3>
<pre><code>console.log(NC.accel());
// {x,y,z}
</code></pre>
<h3 id="magnetometer">Magnetometer</h3>
<pre><code>console.log(NC.mag());
// {x,y,z}
</code></pre>
<h3 id="lipo">LiPo</h3>
<pre><code>NC.getBatteryState()
// { charging:bool, standby:bool}
</code></pre>
<h2 id="extending-the-badge">Extending the badge</h2>
<p>You can add your own ‘Apps’ or LED patterns that will display in the Badge’s
memory just by adding them to the <code>Badge.patterns</code> or <code>Badge.apps</code> arrays.</p>
<p>Normally when you upload code from the right-hand side of the IDE it will reset
the badge (this won’t remove saved code, but will stop the badge code from running).
To avoid this, either copy/paste your code from the right-hand side of the IDE
to the left, or disable the <code>Reset before send</code> option in the <code>Communications</code> part
of the Web IDE’s settings.</p>
<h2 id="patterns">Patterns</h2>
<p>Just do something like:</p>
<pre><code>// LED patterns - each is [callback, period_in_ms]
Badge.patterns.blue=()=>{ var n=0;return [()=>{
var c = [127,0,0];
NC.ledTop(c);
NC.ledBottom(c);
NC.backlight(c.concat(c,c,c));
},0];};
</code></pre>
<p>And you can test by running <code>Badge.pattern("mine")</code>.</p>
<p>The above example will only be called once because it returns <code>0</code> for <code>period_in_ms</code>,
but you can easily supply a different value to be called more often:</p>
<pre><code>Badge.patterns.green=()=>{ var n=0;return [()=>{
n+=50;
if (n>1536)n=0;
NC.ledTop([0,Math.max(255-Math.abs(n-1024),0),0]);
NC.ledBottom([0,Math.max(255-Math.abs(n-1384),0),0]);
NC.backlight([0,Math.max(255-Math.abs(n-640),0),0,
0,Math.max(255-Math.abs(n-512),0),0,
0,Math.max(255-Math.abs(n-384),0),0,
0,Math.max(255-Math.abs(n-256),0),0]);
},50];};
</code></pre>
<p>50ms is usually a good balance of battery life and smoothness.</p>
<h2 id="apps">Apps</h2>
<p>Just write your app to the <code>Badge.apps</code> array:</p>
<pre><code>Badge.apps["My App"] = ()=>{
// Reset everything on the badge to a known state
Badge.reset();
// Display a menu
Pixl.menu({ "": { "title": "-- A Test --" },
"LED1 on" : ()=>LED1.write(1),
"LED1 off" : ()=>LED1.write(0),
"Back to Badge":Badge.badge
});
};
</code></pre>
<p>And you can test by running <code>Badge.apps["My App"]()</code></p>
<p>To return to normal badge functionality just call <code>Badge.badge()</code> or <code>Badge.menu()</code>
to return to the menu.</p>
<h2 id="saving">Saving…</h2>
<p>When you upload code as described above, your function will be loaded
into RAM and will be lost when the badge is reset.</p>
<p>To make it persist, you can write it into a file in the badge’s storage
called <code>.boot0</code>,<code>.boot1</code>,<code>.boot2</code> or <code>.boot3</code> - each one is executed in
turn on boot so you can have more than one extension at once.</p>
<pre><code>require("Storage").write(".boot0",`
Badge=global.Badge||{};
Badge.apps=Badge.apps||{};
Badge.apps["My App"] = ()=>{
// Reset everything on the badge to a known state
Badge.reset();
// Display a menu
Pixl.menu({ "": { "title": "-- A Test --" },
"LED1 on" : ()=>LED1.write(1),
"LED1 off" : ()=>LED1.write(0),
"Back to Badge":Badge.badge
});
};
`);
</code></pre>
<p>You can also do things like overwrite the built-in name,
without having to overwrite the basic badge firmware.</p>
<pre><code>require("Storage").write(".boot1",`
Badge=global.Badge||{};
Badge.NAME=["Hello","World"];
`);
</code></pre>
<h2 id="common-pitfalls">Common Pitfalls</h2>
<ul>
<li>If you get <code>Badge not found</code> errors while trying to upload an app from the right hand side, it’ll be because you’re uploading with the <code>Reset before send</code> option turned on in the IDE settings (it should be turned off)</li>
<li><code>reset()</code> (or ‘reset before send) removes all JS code from the badge’s RAM (including the <code>Badge</code> object) - it can be handy if you want to have full control of everything on the badge. To get back, see the next point…</li>
<li>If you want to get your badge firmware back out of flash memory <em>without</em> power cycling your badge, just type <code>load()</code> in the left-hand side of the IDE</li>
<li>Calling <code>Badge.menu()</code> will bring the Badge’s menu back up - <code>Badge.badge()</code> goes back to displaying the badge. If you want a button in the app to bring you back to the menu, you can just call: <code>setWatch(Badge.menu, BTN1);</code></li>
<li><code>Badge.reset()</code> attempts to reset the badge’s state (removing watches and intervals) - it’s an idea to stick this as the first line in your app to make sure you start from a known state each time.</li>
</ul>
<h2 id="soldering-stuff">Soldering Stuff</h2>
<p>There are some special GPIO connectors on the badge. These can be accessed with
commands like <code>digitalWrite(D10,1)</code> or <code>analogRead(A0)</code>.</p>
<ul>
<li><code>J2</code> (Top Left) contains (left to right) <code>GND</code>,<code>D10</code>,<code>D11</code>,<code>D12</code>,<code>D13</code> and <code>3.3v</code></li>
<li><code>J1</code> (Top Right) contains (left to right) <code>GND</code>,<code>A0</code>,<code>A1</code>,<code>A2</code>,<code>A3</code> and <code>3.3v</code></li>
<li><code>J3</code> (Bottom center) contains the pinout for an ESP8266 ESP01 module. This can
also be used for wired serial comms with the badge:</li>
</ul>
<pre><code>GND NC NC D1(Badge TX)
D0(Badge RX) D9 NC 3.3v
</code></pre>
<h3 id="esp8266-wiring">ESP8266 Wiring</h3>
<p>Due to a slight mirroring accident, a normal ESP8266 module has to be attached
to the FRONT of the badge, slightly covering the display:</p>
<pre><code> ...... ......
___________________________
BTN1 | | BTN2
| |
| ____ |
| | | |
BTN4 |___________| |__________| BTN3
|::::|
----
</code></pre>
<p>However by removing the ESP01’s pins and soldering them on the other side of the
module, you can fit the ESP01 to the rear of the badge very tidily.</p>
<p>Once soldered you can access the internet as follows:</p>
<pre><code>var WIFI_NAME = "...";
var WIFI_PASS = "...";
D9.set(); // power on
Serial1.setup(115200,{rx:D0,tx:D1});
var wifi = require("ESP8266WiFi_0v25").connect(Serial1, function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, WIFI_PASS, function(err) {
if (err) throw err;
console.log("Connected");
// Now you can do something, like an HTTP request
require("http").get("http://www.pur3.co.uk/hello.txt", function(res) {
console.log("Response: ",res);
res.on('data', function(d) {
console.log("--->"+d);
});
});
});
});
</code></pre>
<p>Check out <a href="Espruino's page on Internet stuff">http://www.espruino.com/Internet</a>
for more info.</p>
<h2 id="updating-espruino">Updating Espruino</h2>
<p>The badges came with Espruino v2.00, but there have <a href="https://github.com/espruino/Espruino/blob/master/ChangeLog">been a few changes</a>
to Espruino since then that have fixed:</p>
<ul>
<li>The badge pausing issue (caused by high Bluetooth LE traffic when scanning)</li>
<li>Filesystem issues when repeatedly calling <code>require("Storage").write</code></li>
<li>Other issues</li>
</ul>
<p>To update Espruino, just <a href="http://www.espruino.com/Pixl.js#firmware-updates">follow the Pixl.js instructions here</a>
with the ‘Cutting edge’ build linked from <a href="http://www.espruino.com/Download#pixljs">the firmware download page</a>.</p>
<p>This’ll take a few minutes, and you then need to follow the steps for <a href="#returning-to-standard">Returning your badge to normal</a> - so if you’re fine with everything as it is, we’d recommend that you keep version 2.00 for now.</p>
<h2 id="changing-your-name-on-the-badge-in-the-web-ide">Changing your name on the badge in the Web IDE</h2>
<p>This was the top request during NodeConf EU so we’ve made it as easy as possible. To update the name displayed by the badge, do the following:</p>
<ul>
<li>On the badge, press the top left button, then select “Make Connectable” from the menu and note the last four hex digits of the address of the badge</li>
<li><a href="https://www.espruino.com/ide/?codeurl=https://raw.githubusercontent.com/nearform/nceubadge2018/master/js/namechange.js" target="_blank">Click this link</a> in Chrome to open the Online IDE with the correct code</li>
<li>In that code, edit the two fields “Bob” and “Loblaw” to whatever you need.</li>
<li>Click the yellow Connect button in the top left corner of the IDE</li>
<li>Click “Web Bluetooth” in the pop-up</li>
<li>Click your device name</li>
<li>Once connected, click the “Send to Espruino” button in the middle of the IDE</li>
<li>Reboot your badge and you’ll see the new name</li>
</ul>
<h2 id="2017-badge">2017 Badge</h2>
<p>The old docs for the 2017 badge can be found in <a href="/2017badge/getting-started/">Getting Started</a> and <a href="/2017badge/challenges/">challenges</a>.</p>
</div>
</div>
<div id="navigation">
<a class="nav nav-next" href="/2017badge/" title="2017badges" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
</div>
</section>
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
</div>
<script src="/js/clipboard.min.js?1541954405"></script>
<script src="/js/perfect-scrollbar.min.js?1541954405"></script>
<script src="/js/perfect-scrollbar.jquery.min.js?1541954405"></script>
<script src="/js/jquery.sticky-kit.min.js?1541954405"></script>
<script src="/js/featherlight.min.js?1541954405"></script>
<script src="/js/html5shiv-printshiv.min.js?1541954405"></script>
<script src="/js/highlight.pack.js?1541954405"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="/js/modernizr.custom.71422.js?1541954405"></script>
<script src="/js/learn.js?1541954405"></script>
<script src="/js/hugo-learn.js?1541954405"></script>
<link href="/mermaid/mermaid.css?1541954405" type="text/css" rel="stylesheet" />
<script src="/mermaid/mermaid.js?1541954405"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
</body>
</html>
1b73fd9c3This file is pinned to the selected release. Download the original to open it in your design tool.