<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mehmandarov.com/tag/iot/feed.xml" rel="self" type="application/atom+xml"/><link href="https://mehmandarov.com/tag/iot/" rel="alternate" type="text/html"/><updated>2017-05-07T20:46:00+02:00</updated><id>https://mehmandarov.com/tag/iot/feed.xml</id><title type="html">Rustam Mehmandarov - tag: iot</title><subtitle type="text">Posts tagged &quot;iot&quot; on Rustam Mehmandarov.</subtitle><author><name>Rustam Mehmandarov</name></author><entry><title type="html">Hvordan l&#230;re opp ditt eget kamera</title><link href="https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera/" rel="alternate" type="text/html" title="Hvordan l&#230;re opp ditt eget kamera"/><published>2017-05-07T20:46:00+02:00</published><updated>2017-05-07T20:46:00+02:00</updated><id>https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera</id><content type="html" xml:base="https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera/"><![CDATA[<p><a href="/how-to-train-your-camera/">[English version &#8211; Engelsk versjon]</a></p>

<p><em>Bildegjenkjenning gjort enkelt. Slik gjenkjenner du en bestemt gjenstand ved hjelp av et kamera.</em></p>

<ul>
  <li><a href="#utfordringen">Utfordringen</a></li>
  <li><a href="#litt-teori">Litt teori</a></li>
  <li><a href="#hvor-starter-jeg">Hvor starter jeg?</a></li>
  <li><a href="#la-oss-kj&#248;re-bildegjenkjenning">La oss kj&#248;re bildegjenkjenning</a></li>
  <li><a href="#bonus-video">Bonus: Video</a></li>
</ul>

<hr />

<h2 id="utfordringen">Utfordringen</h2>

<p>Denne uken har jeg f&#229;tt utfordringen &#229; foresl&#229; en l&#248;sning p&#229; f&#248;lgende problem:</p>

<blockquote>
  <p><em>&#8220;Med en enkel datamaskin, som en Raspberry Pi, et kamera og et fuglebrett, lag et program som kan artsbestemme hvilke fugler som er innom brettet og spiser i l&#248;pet av en dag.&#8221;</em></p>
</blockquote>

<p>Siden sp&#248;rsm&#229;let var av mer teoretisk art, bestemte jeg meg for &#229; begrense dette innlegget til &#229; introdusere byggeblokkene og gi en forklaring p&#229; hvordan du typisk kan bygge et slikt system.</p>

<p>&#197; gjenkjenne gjenstander er en ganske vanlig oppgave n&#229; for tiden, og den har blitt l&#248;st p&#229; flere forskjellige m&#229;ter, og med forskjellige tiln&#230;rminger. La oss se p&#229; hvordan dette virker.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> Det fins noen tradisjonelle m&#229;ter &#229; lage bilde- og gjenstandsgjenkjenning p&#229;, som i OpenCV, og det fins noen teknikker basert p&#229; Deep Learning, som i TensorFlow. Vil du vite mer? Fortsett &#229; lese.</p>
</blockquote>

<hr />

<h2 id="litt-teori">Litt teori</h2>
<p>De mer tradisjonelle prinsippene bak OpenCV for &#229; oppdage er godt beskrevet i <a href="http://www.learnopencv.com/image-recognition-and-object-detection-part1/" target="_blank">dette blogginnlegget</a>, s&#229; vel som i denne veiledningen for &#229; gjenkjenne (hold dere fast!) <a href="http://www.pyimagesearch.com/2016/06/20/detecting-cats-in-images-with-opencv/" target="_blank">katter p&#229; bilder</a>.</p>

<p>Mens <a href="https://www.tensorflow.org/tutorials/keras/basic_classification" target="_blank">dette innlegget</a> forklarer hvordan bildegjenkjenning virker i TensorFlow, som bruker en modell kalt dypt konvolverende nevrale nettverk, vil det ogs&#229; la deg <a href="https://research.googleblog.com/2016/03/train-your-own-image-classifier-with.html" target="_blank">trene opp din egen bildeklassifiserer</a>, slik som OpenCV.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_1.png" alt="Training your own model" class="bigger-image" /></p>
<figcaption class="caption">Noen m&#229; l&#230;re opp modellen som du skal bruke til bildeklassifisering (-gjenkjenning).</figcaption>

<hr />

<h2 id="hvor-starter-jeg">Hvor starter jeg?</h2>

<p>I utgangspunktet har du to valg &#8211; du b&#248;r enten l&#230;re opp din egen modell eller finne en modell som har blitt l&#230;rt opp av noen andre, og du vil kanskje alltid starte med &#229; se etter en forh&#229;ndsoppl&#230;rt modell. Men jo mer spesifiserte bildeklassifiseringskravene dine er, jo h&#248;yere er sjansen for at du m&#229; l&#230;re opp din egen modell. Dette vil v&#230;re det samme enten du velger OpenCV eller TensorFlow.</p>

<p>Siden vi vil kj&#248;re modellen p&#229; en relativt enkel datamaskin, kan du vurdere &#229; gj&#248;re prosesseringen i skyen. Det b&#248;r imidlertid ogs&#229; v&#230;re mulig &#229; kj&#248;re <a href="http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/" target="_blank">OpenCV</a> og <a href="https://svds.com/tensorflow-image-recognition-raspberry-pi/" target="_blank">TensorFlow</a> p&#229; den nyeste Raspberry Pi.</p>

<hr />

<h2 id="la-oss-kj&#248;re-bildegjenkjenning">La oss kj&#248;re bildegjenkjenning</h2>

<p>N&#229; vet du litt om teorien. La oss s&#229; ta en rask titt p&#229; hvordan vi kan l&#230;re opp modellene i v&#229;re behov.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> M&#229;ten dette virker p&#229;, er at du viser modellen ganske mange bilder av en gjenstand, og en tilsvarende mengde bilder uten gjenstanden p&#229;.</p>
</blockquote>

<p>La oss si at du vil bruke modellen til &#229; gjenkjenne fugler utenfor huset ditt i Norge. Et godt utgangspunkt vil da v&#230;re &#229; f&#229; en liste over de typiske artene som du mest sannsynlig ser i hagen din, og samle s&#229; mange bilder av hver art som mulig.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_2.png" alt="Your own model in action" class="bigger-image" /></p>
<figcaption class="caption">Din oppl&#230;rte modell i aksjon.</figcaption>

<p>Her er hva du kan gj&#248;re:</p>

<ol>
  <li>Start med &#229; finne en liste over norske fugler p&#229; <a href="https://en.wikipedia.org/wiki/List_of_birds_of_Norway" target="_blank">Wikipedia</a>, eller <a href="https://snl.no/Fugler_i_Norge" target="_blank">Store Norske Leksikon</a>.</li>
  <li>S&#248;k p&#229; nettet etter bilder av hver fugleart. Det kan v&#230;re du vil automatisere dette arbeidet, og s&#248;rg for at du plukker ut bilder med de riktige opphavsrettstillatelsene.</li>
  <li>Bruk disse bildene i oppl&#230;ringen av din modell.</li>
  <li>Sett opp din Raspberry Pi med et kamera og fuglebrett, og gj&#248;r deg klar til &#229; identifisere fuglearter. Du b&#248;r optimalisere programvaren slik at bildeklassifiseringen ikke skjer hele tiden, men kun n&#229;r man ser en bevegelse.</li>
</ol>

<p><em>Pro tip:</em> Det kan ogs&#229; v&#230;re litt utfordrende &#229; ta gode bilder av v&#229;re fj&#230;rkledde venner, s&#229; s&#248;rg for at kameraet ditt er godt plassert, og materen er p&#229; et godt opplyst sted. Uten &#229; forstyrre dyrelivet, s&#229; klart.</p>

<p>Lurer du p&#229; om lignende systemer har blitt implementert eller om det er mulig? Svaret er ja. Her er det noen lenker til inspirasjon for videre lesning:</p>

<ul>
  <li><a href="https://www.oreilly.com/learning/dive-into-tensorflow-with-linux" target="_blank">En fugleklassifiserer med tensorflow</a></li>
  <li><a href="https://web.archive.org/web/20161205073600/http://www.bitfusion.io:80/2016/08/31/training-a-bird-classifier-with-tensorflow-and-tflearn/" target="_blank">Trene opp en fugleklassifiserer med Tensorflow og TFLearn</a></li>
  <li><a href="https://www.youtube.com/watch?v=S-W9tMZu8PU" target="_blank">Kj&#248;ret&#248;yklassifisering og -telling med OpenCV</a></li>
  <li><a href="https://web.archive.org/web/20170925210229/http://www.fyens.dk/article/3141726" target="_blank">Blomstergjenkjenning i naturen</a> (p&#229; dansk)</li>
  <li><a href="https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721" target="_blank">Maskinl&#230;ring er morsomt! Del 3: Dypt konvolverende nevrale nettverk</a>. (Ta ogs&#229; gjerne en titt p&#229; de andre delene i denne artikkelserien.)</li>
</ul>

<p>Pr&#248;v n&#229; &#229; sette alt dette sammen, og fortell meg gjerne hvordan det g&#229;r!</p>

<p><em>Lykke til!</em></p>

<hr />

<h2 id="bonus-video">Bonus: Video</h2>

<p>En video vi har laget av mine tegninger og en kort forklaring p&#229; hvordan dette virker.</p>

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/kOXBCWvmtD4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen=""></iframe>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Bildegjenkjenning gjort enkelt. Slik gjenkjenner du en bestemt gjenstand ved hjelp av et kamera og OpenCV eller TensorFlow</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/bird_small.jpg"/><category term="blog"/><category term="iot"/><category term="machine learning"/><category term="norwegian"/></entry><entry><title type="html">How to Train Your Camera</title><link href="https://mehmandarov.com/how-to-train-your-camera/" rel="alternate" type="text/html" title="How to Train Your Camera"/><published>2017-04-29T20:46:00+02:00</published><updated>2017-04-29T20:46:00+02:00</updated><id>https://mehmandarov.com/how-to-train-your-camera</id><content type="html" xml:base="https://mehmandarov.com/how-to-train-your-camera/"><![CDATA[<p><a href="/hvordan-laere-opp-ditt-eget-kamera/">[Norwegian version - Norsk versjon]</a></p>

<p><em>Image recognition made simple. How to recognise a specific object from a camera feed?</em></p>

<ul>
  <li><a href="#the-challenge">The Challenge</a></li>
  <li><a href="#a-tiny-bit-of-theory">A Tiny Bit of Theory</a></li>
  <li><a href="#where-to-start">Where to Start?</a></li>
  <li><a href="#doing-image-recognition">Doing Image Recognition</a></li>
</ul>

<hr />

<h2 id="the-challenge">The Challenge</h2>

<p>This week I have been given the challenge to suggest a solution to the following problem:</p>

<blockquote>
  <p><em>&#8220;Given a simple computer, like a Raspberry Pi, a camera and a bird feeder, create a system that can identify the birds feeding there throughout the day.&#8221;</em></p>
</blockquote>

<p>Since the question was more of a theoretical kind, I decided to limit this post to introducing the building blocks and giving an explanation of how you would typically build a system like that.</p>

<p>Recognising objects is a pretty common task these days, and it has been solved in quite a few ways by different approaches. Let&#8217;s have a look at how this works.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> There are some traditional ways of doing image recognition and object detection, like in OpenCV, and there are some techniques based on Deep Learning object detection, like in TensorFlow. Want to know more? Keep on reading.</p>
</blockquote>

<hr />

<h2 id="a-tiny-bit-of-theory">A Tiny Bit of Theory</h2>

<p>The more traditional principles behind OpenCV are well described in this <a href="http://www.learnopencv.com/image-recognition-and-object-detection-part1/" target="_blank">blog post</a>, as well as in this tutorial for detecting (<em>brace yourselves!</em>) <a href="http://www.pyimagesearch.com/2016/06/20/detecting-cats-in-images-with-opencv/" target="_blank">cats in images</a>.</p>

<p>While <a href="https://www.tensorflow.org/tutorials/keras/basic_classification" target="_blank">this post</a> explains how image recognition works in TensorFlow that is using a model called a deep convolutional neural network. Like OpenCV, it will also let you <a href="https://research.googleblog.com/2016/03/train-your-own-image-classifier-with.html" target="_blank">train your own image classifier</a>.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_1.png" alt="Training your own model" class="bigger-image" /></p>
<figcaption class="caption">Someone has to train the model that you will be using for image classification (recognition).</figcaption>

<hr />

<h2 id="where-to-start">Where to Start?</h2>

<p>Basically, you have two choices &#8211; you should either train your own model, or find a model that has been trained by someone else, and you might always want to start by looking for a pre-trained model. However, the more specific your image classification requirements are, the higher are chances that you will need to train your own model. This will be the same whether you go for OpenCV or TensorFlow.</p>

<p>Since we want to run the model on a relatively low-end computer, you might consider doing the processing in the Cloud. However, it should also be possible to run <a href="http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/" target="_blank">OpenCV</a> and <a href="https://svds.com/tensorflow-image-recognition-raspberry-pi/" target="_blank">TensorFlow</a> on the latest Raspberry Pis.</p>

<hr />

<h2 id="doing-image-recognition">Doing Image Recognition</h2>

<p>By now, you should know a bit about the theory. So, let&#8217;s have a quick look into how we can train the models for our needs.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> The way this works, is that you feed the model with quite a few pictures of an object, and the similar amount of images without that object.</p>
</blockquote>

<p>Say you want to use the model to recognize birds outside your house in Norway. A good starting point would be to get a list of the typical species you are most likely to see in your backyard and collect as many pictures of each type as possible.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_2.png" alt="Your own model in action" class="bigger-image" /></p>
<figcaption class="caption">Your trained model in action.</figcaption>

<p>Here is what you can do:</p>

<ol>
  <li>Start by looking at <a href="https://en.wikipedia.org/wiki/List_of_birds_of_Norway" target="_blank">Wikipedia</a> for a list of the Norwegian birds, or <a href="https://snl.no/Fugler_i_Norge" target="_blank">Norwegian Encyclopaedia</a> (<em>in Norwegian</em>).</li>
  <li>Search the web for the images of each bird type. You might want to automate that task and make sure you are picking images with the right copyright permissions.</li>
  <li>Use those images to train your model.</li>
  <li>Set up your Raspberry Pi with a camera and the bird feeder, and get ready to identify. You might want to optimise the software not to do the image classification all the time, but only when movement is detected.</li>
</ol>

<p><em>Pro tip:</em> It might also be a bit challenging to take a good picture of our feathered friends, so make sure your camera is well-placed, and the feeder is in a well-lit location. Obviously, without disturbing the wildlife.</p>

<p>In case you wonder if similar systems have been implemented, or if it is even possible. The answer is yes. I will provide you with some links to inspire for further reading:</p>

<ul>
  <li><a href="https://www.oreilly.com/learning/dive-into-tensorflow-with-linux" target="_blank">A Bird Classifier with Tensorflow</a></li>
  <li><a href="https://web.archive.org/web/20161205073600/http://www.bitfusion.io:80/2016/08/31/training-a-bird-classifier-with-tensorflow-and-tflearn/" target="_blank">Training a Bird Classifier with Tensorflow and TFLearn</a></li>
  <li><a href="https://www.youtube.com/watch?v=S-W9tMZu8PU" target="_blank">Vehicle classification and Counting with OpenCV</a></li>
  <li><a href="https://web.archive.org/web/20170925210229/http://www.fyens.dk/article/3141726" target="_blank">Wild Flower Detection</a> (<em>in Danish</em>)</li>
  <li><a href="https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721" target="_blank">Machine Learning is Fun! Part 3: Deep Learning and Convolutional Neural Networks</a>. (<em>Also, check out the other parts of the article series.</em>)</li>
</ul>

<p>Now, try putting it all together, and let me know how it goes!</p>

<p><em>Good luck!</em></p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Training your camera to recognize objects using OpenCV or TensorFlow</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/bird_small.jpg"/><category term="blog"/><category term="iot"/><category term="machine learning"/><category term="english"/></entry><entry><title type="html">Playing with IoT</title><link href="https://mehmandarov.com/iot-prototyping-startup-kit/" rel="alternate" type="text/html" title="Playing with IoT"/><published>2017-03-16T10:06:00+01:00</published><updated>2017-03-16T10:06:00+01:00</updated><id>https://mehmandarov.com/iot-prototyping-startup-kit</id><content type="html" xml:base="https://mehmandarov.com/iot-prototyping-startup-kit/"><![CDATA[<p><em>How to get started prototyping Internet of Things (IoT) solutions and why should you do that?</em></p>

<ul>
  <li><a href="#motivation">Motivation</a></li>
  <li><a href="#building-blocks">Building Blocks</a></li>
  <li><a href="#now-what">Now what?</a></li>
</ul>

<hr />

<h2 id="motivation">Motivation</h2>

<p>Playing around with Internet of Things (IoT) devices provides several advantages. Apart from the obvious ability to easily prototype systems tailored to your specific needs, it can also give you a more engaging way to gain insight into the tools and infrastructure that usually comes with IoT devices, and is relevant for most of the modern developers:</p>

<ul>
  <li>Cloud</li>
  <li>Distributed systems</li>
  <li>Data analysis</li>
  <li>Data visualization</li>
  <li>Machine learning and prediction models</li>
</ul>

<p>This post is meant to give you a simple and minimal set-up to get you started playing around with IoT. I would like to show you just a few devices I have used and to provide you with the code examples for them.</p>

<hr />

<h2 id="building-blocks">Building Blocks</h2>

<h3 id="a-computer-brain">A Computer Brain</h3>
<p>First, we will need something to orchestrate the events, collect the data and communicate with other services, like Cloud services or other machines. It can be a Raspberry Pi, or any other (preferably small) computer. It can also be Arduino, NodeMcu or similar.</p>

<p>In my case, it is a <a href="https://www.raspberrypi.org/products/raspberry-pi-2-model-b/">Raspberry Pi 2 Model B</a> with Wifi and Bluetooth 4.0 (BTLE) adapters. The Pi will be running Raspbian &#8211; a computer operating system, based on Debian (Linux).</p>

<h3 id="sensors">Sensors</h3>
<p>Now we need some sensors. It can be anything &#8211; sensors connected directly to the Raspberry Pis GPIO pins, or separate sensors that can deliver information over the main machine for collection and processing.</p>

<p>I have good experience using <a href="http://www.ti.com/ww/en/wireless_connectivity/sensortag/tearDown.html">SensorTag</a> from Texas Instruments. It uses Bluetooth Low Energy for communication and offers quite a few sensors and hardware buttons, such as:</p>

<ul>
  <li>Infrared and Ambient Temperature Sensor</li>
  <li>Ambient Light Sensor</li>
  <li>Humidity Sensor</li>
  <li>Barometric Pressure Sensor</li>
  <li>9-axis Motion Tracking Device &#8211; Accelerometer, Gyroscope, and Compass</li>
  <li>Magnet Sensor</li>
  <li>Hardware buttons</li>
</ul>

<p><strong>Getting started code:</strong> You will find some code for getting started with Node.js and SensorTag with examples and references to documentation <a href="https://github.com/mehmandarov/sensortag-gettingstarted">here</a>.</p>

<h3 id="other-devices">Other devices</h3>
<p>After setting up a computer to orchestrate the events and getting communication with some sensors up and running, we can add more devices that we can control and/or use to collect more data. In the sections below, I have mentioned some of the devices I have been working with, as well as linking to some code examples to get you started.</p>

<h4 id="razberry-z-wave">Razberry (Z-Wave)</h4>
<p>Since we are using Raspberry Pi, we can extend it even more by using Razberry platform, that brings all the components needed to turn a Raspberry Pi board into a fully operational and inexpensive Z-Wave gateway. Z-Wave is a wireless communication technology often used for smart homes.</p>

<p><strong>Getting started code:</strong> In <a href="https://github.com/mehmandarov/razberry-gettingstarted">this repo</a> I have provided some information about the REST APIs and the commands that can be sent through them.</p>

<h4 id="microbit">Micro:bit</h4>
<p>You can also connect some other devices, like this ARM-based embedded system designed by the BBC for use in computer education.</p>

<p><strong>Getting started code:</strong> <a href="/microbit-bluetooth-challenge/">My previous post</a> gives some pointers for getting started, links to the editor and documentation. It also contains some example implementations.</p>

<p>It should be also possible to connect a micro:bit to a computer or a phone via Bluetooth to send or receive data to or from it.</p>

<h4 id="other">Other</h4>
<p>Previously, I have also used devices like Zumo robots and drones:</p>

<ul>
  <li><a href="https://github.com/mehmandarov/myZumo">Zumo robots</a></li>
  <li><a href="https://github.com/voodootikigod/node-rolling-spider">Parrot drones</a></li>
</ul>

<p>Just keep on adding devices, sensors, and components as you wish. Sky is the limit!</p>

<hr />

<h2 id="now-what">Now what?</h2>
<p>Now that you have connected a bunch of sensors and started collecting some sensor data, we might like to send the data to the cloud, visualize it, or use some machine learning and prediction techniques on that data. Here are some ideas that might help you get started:</p>

<ul>
  <li><a href="https://firebase.google.com/">Google Firebase</a>: A simple solution for storage and publishing of the data.</li>
  <li><a href="https://market.mashape.com/explore">Mashape.com</a>: A list of different APIs, most of which are available to free, that might give you some ideas on how you can use your data.</li>
  <li>Any simple JavaScript visualization library, like <a href="https://d3js.org/">D3</a>, for making your data available in an intuitive way.</li>
</ul>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Start-up kit for prototyping IoT solutions</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/lego-ferrari-italia.jpg"/><category term="blog"/><category term="iot"/><category term="english"/><category term="conferences"/></entry><entry><title type="html">Micro:bit Bluetooth Challenge</title><link href="https://mehmandarov.com/microbit-bluetooth-challenge/" rel="alternate" type="text/html" title="Micro:bit Bluetooth Challenge"/><published>2017-03-11T12:06:00+01:00</published><updated>2017-03-11T12:06:00+01:00</updated><id>https://mehmandarov.com/microbit-bluetooth-challenge</id><content type="html" xml:base="https://mehmandarov.com/microbit-bluetooth-challenge/"><![CDATA[<p><em>Can you build Scissor-Paper-Rock game using micro:bit and Bluetooth?</em></p>

<ul>
  <li><a href="#the-challenge">The Challenge</a></li>
  <li><a href="#the-building-blocks">The Building Blocks</a></li>
  <li><a href="#extra">Extra</a></li>
</ul>

<hr />

<p>This post is the challenge for the Race Condition badge at <a href="http://ariot.no/Home/Badges" target="_blank">Arctic IoT Challenge</a>. The description for the badge is as follows:</p>

<blockquote>
  <p>At random, the jury will present a challenge. Timeboxed to one hour, the first team with a working solution gets all the points.</p>
</blockquote>

<p>This time I am designing the challenge, so here it comes:</p>

<hr />

<h2 id="the-challenge">The Challenge</h2>

<p>We want you to simulate a popular Scissor-Paper-Rock game using <a href="https://en.wikipedia.org/wiki/Micro_Bit" target="_blank">micro:bits</a>. Each team gets two devices.</p>

<ul>
  <li>On shake the micro:bit should pick a random shape (scissors, paper, or rock) and show it using LED array on the device</li>
  <li>The two devices should connect and send the data over to each other</li>
  <li>The opposite device compares then its shape to the one received and decides whether it won or lost</li>
  <li>Each of the two micro:bits shows then &#8220;Won&#8221; or &#8220;Lost&#8221; on the LED array.</li>
</ul>

<hr />

<h2 id="the-building-blocks">The Building Blocks</h2>

<h3 id="connecting-to-a-microbit">Connecting to a micro:bit</h3>
<p>Connect the micro:bit to your computer using a micro USB cable. It should appear as a USB disk on your machine.</p>

<h3 id="editor-and-language">Editor and Language</h3>
<p>Yan can use Python and the editor here: <a href="http://python.microbit.org/editor.html" target="_blank">http://python.microbit.org/editor.html</a>.</p>

<p>After you are done writing the code, click <em>Download</em>, and you will get a binary file you will be using in the next step. Check out the <a href="http://python.microbit.org/help.html" target="_blank">help section</a> for more information.</p>

<p>Python documentation for the API can be found <a href="https://microbit-micropython.readthedocs.io/en/latest/index.html" target="_blank">here</a>.</p>

<h3 id="deploying-to-a-microbit">Deploying to a micro:bit</h3>
<p>Copy the binary *.hex file from the previous step on to the micro:bit, just like you would copy to any USB drive.</p>

<h3 id="sending-data-between-microbits">Sending Data Between micro:bits</h3>
<p>Now, over to connecting micro:bits and sending data over. Take a look at the example below. Make sure to change <em>group=1</em> to a number between 0 and 255. Both chips should belong to the same group to connect with each other. You will be assigned a number.</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="n">microbit</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="n">radio</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="n">random</span> <span class="kn">import</span><span class="o">*</span>

<span class="c1">#turn radio on and configure group
</span><span class="nf">on</span><span class="p">()</span>
<span class="nf">config</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">length</span><span class="o">=</span><span class="mi">251</span><span class="p">)</span>

<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
    <span class="k">if</span> <span class="n">button_a</span><span class="p">.</span><span class="nf">was_pressed</span><span class="p">():</span>
        <span class="c1">#send the images
</span>        <span class="nf">send</span><span class="p">(</span><span class="sh">"</span><span class="s">Hello, World!</span><span class="sh">"</span><span class="p">)</span>
     
    <span class="c1">#receive data    
</span>    <span class="n">data</span> <span class="o">=</span> <span class="nf">receive</span><span class="p">()</span>
    
    <span class="c1">#check that we have received any data
</span>    <span class="k">if</span> <span class="n">data</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
        
        <span class="c1">#split the data into different pictures by the marker
</span>        <span class="n">display</span><span class="p">.</span><span class="nf">scroll</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

        <span class="c1">#clear the screen
</span>        <span class="n">display</span><span class="p">.</span><span class="nf">clear</span><span class="p">()</span></code></pre></figure>

<h3 id="the-scissor-paper-rock-game">The Scissor-Paper-Rock Game</h3>
<p>Have a look at the <a href="https://www.microbit.co.uk/blocks/lessons/rock-paper-scissors/challenges" target="_blank">simple implementation of the game</a>. You will need to translate it to MicroPython and extend.</p>

<p><img src="/assets/images/posts-images/2017-03-11-microbit-bluetooth-challenge-1.jpg" alt="Pseudocode for the Scissor-Paper-Rock Game" /></p>

<hr />

<h2 id="extra">Extra</h2>
<p><em>[Spoiler alert!]</em> The winning team gets to submit their code to this <a href="https://github.com/mehmandarov/scissor-paper-rock-microbit" target="_blank">GitHub repo</a>.</p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Scissor-Paper-Rock challenge using micro:bit and Bluetooth</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/clouds.jpg"/><category term="blog"/><category term="iot"/><category term="python"/><category term="english"/><category term="conferences"/></entry></feed>
