Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iot:labs:03 [2016/06/23 10:15]
alexandru.radovici
iot:labs:03 [2017/09/11 09:34] (current)
alexandru.radovici
Line 1: Line 1:
-===== Lab 3: Plugins and Local Storage ​=====+====== Lab 3: Light Blink ======
  
-You will find information related ​to the plugins here: +===== What you need ===== 
-https://​build.phonegap.com/​plugins/​core +  * One Raspberry Pi connected ​to Wyliodrin STUDIO; 
-and here +  * One LED; 
-http://​docs.phonegap.com/​en/​edge/​cordova_plugins_pluginapis.md.html#​Plugin%20APIs+  * One 220 Ohm resistor; 
 +  * Jumper wires; 
 +  * Breadboard;​ 
 + ​{{ ​:iot2015:​labs:​leed.png?80 |}} 
 +{{ :​iot2015:​labs:​resist.png?100 |}}
  
-==== Settings ==== 
  
-Create a setting page where the user can change some settings of the app  +===== The Setup ===== 
-(EG: on iPhone if the status bar should be visible or not ) +Connect ​the LED to the Raspberry Pi following ​the schematics in the figure.
-The settings must be persistent. Restarting ​the app should load the settings at initialization. +
-Also try building with phonegap build where possible.+
  
-==== Media ==== +First of allyou need to distinguish the anode from the cathode. The LED has two legs: one is longerthat one is usually the anode and the shorter one is the cathode. Another way of identifying them is by looking inside the LED. There are two metal parts in it. The smaller one is connected to the anode and the bigger one is connected to the cathode.  
-Try capturing some media (audio,video,image) ​and upload ​it on the server+{{ :​iot:​labs:​led-blink-schematics.png?​300 |}} 
-Take an image from the image library ​and display it in a HTML elementMake that element persistent upon relaunching ​the app+To understand ​the anode and the cathode of the LED, imagine these two following situations:  
-Play some audio files from your phones when different events happen in the UI.+  -  The cathode is connected ,through the resistor of course, to the groundThis means that the anode will be wired to the GPIO pin, which has to be //High// in order to make the LED light up
 +  - The anode is connected to the VCC pin of the board. Which means that, should you want to light up the LED, the cathode has to be connected to the GPIO setted to //Low //. Don't forget this kind of a circuit also requires a resistor
  
-==== Phone senors ====+To sum it up, although the position of the resistor is not fixed, it can can either connect the ground to the cathode or the anode to the GPIO pin, the cathode should be connected to the ground to obtain the usually desired behaviour. Meaning you want the LED to light when the GPIO is set to HIGH and not to light when the GPIO is set to LOW. If you put the legs the other way around, the effect will be the opposite. ​
  
-Display information from geolocation,​ accelerator and compas on a page. +===== The Code ===== 
-Make those auto-update by using the watch methods+Let's see the same application in three different programming languages
  
 +==== Visual Programming ====
 +First, you can try it out in Visual Programming. ​
 +Here's an example: ​
 +{{ :​iot2015:​labs:​blink-application.png?​300 |}}
 +The first two blocks will simply print on the screen the messages written inside them. 
 +The // repeat while true// blocks will create an endless loop. Inside it, there will be the blocks that turn on and off the LED on the chosen pin. There is also a // delay// block, which will insert here a pause of 0.5 seconds between the // on //  state of the LED and the // off // one.
  
-==== Optional ​====+==== Python ​====
  
-Try interacting with a public plugin made by someone else+An important feature of Visual Programming in Wyliodrin is that you can easily get the Python code for your projects, just by clicking the // Show code// button. ​  
 +<code python>​ 
 +from wyliodrin import * 
 +from time import *
  
 +pinMode (0, 1)
  
 +print('​Led on pin 0 should blink'​)
 +print('​Press the Stop button to stop')
 +while True:
 +  digitalWrite (0, 1)
 +  sleep ((500)/​1000.0)
 +  digitalWrite (0, 0)
 +  sleep ((500)/​1000.0)
 +</​code>​
  
 +First of all, you need to import the //​wyliodrin//​ and //time// modules that will allow you to use some simple functions.
  
 +Firstly, you have to declare the pins you are going to use and their purpose. In this case, pin 0 is used as //OUTPUT//. This is what //​pinMode(0,​1)//​ does (1=OUTPUT, 0=INPUT). ​
 +
 +Next, there are the //print// functions that simply write the text in the shell.
 +
 +Another useful function is //​digitalWrite//​. The function receives as parameter the pin and the value. As you are doing a digital write, the value can be either 0 or 1. If the value is 0, the pin will have no current. If the value is 1, there is current.
 +
 +The //sleep// function makes the program wait for the desired number of seconds.
 +
 +All this code is enclosed within the //while True// loop that makes it to be run forever, until the application is stopped.
 +
 +==== Useful Functions ====
 +You can use the following functions both in Python and JavaScript:
 +  * **wyliodrin.pinMode (pin, mode)** - configures the specified pin to behave either as an input or an output;
 +  * **wyliodrin.digitalWrite (pin, value)** - writes a HIGH or a LOW value to a digital pin;
 +  * **wyliodrin.delay()** - pauses the program for the amount of time (in miliseconds) specified as parameter.
 +
 +In order to use these function, import the **wyliodrin** module:
 +  * **Python:** from wyliodrin import wyliodrin
 +  * **JavaScript:​** var wyliodrin = require ('​wyliodrin'​);​
 +===== Tips & Tricks =====
 +Usually the longer leg is the anode and the shorted one is the cathode. However, this is not standard, to make sure which is which, you should know that the cathode leg is always connected to the bigger part inside the LED.
 +
 +===== Exercises=====
 +  - Use one LED to write SOS using the international morse code using Python or JavaScript.{{ :​iot2015:​labs:​international_morse_code.png?​300 |}}
 +  - Create a traffic lights system that has lights for cars and for pedestrians. ​
 +  - Use [[http://​openweathermap.org/​api|Open Weather Map]] to get the temperature in Bucharest and light up one of the green, yellow or red LEDs depending on the temperature. **Note:​**Use the **requests** module.
iot/labs/03.txt · Last modified: 2017/09/11 09:34 by alexandru.radovici
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0