Differences

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

Link to this comparison view

iot:labs:04 [2017/09/11 09:34]
alexandru.radovici removed
iot:labs:04 [2017/09/11 09:35] (current)
alexandru.radovici created
Line 1: Line 1:
-=====Lab 4: Raspberry Pi Setup===== +====== Lab 4: Programming with Streams====== 
-====Raspberry Pi 3==== +===== Traffic Lights ===== 
-The Raspberry Pi is a very small computer that has the characteristics of the computers people would use 15 years ago. +===== What you need ===== 
-Raspberry Pi 3 characteristics:​ +  * One Raspberry Pi connected to Wyliodrin STUDIO; 
-  * Broadcom BCM2837 SoC (4 ARM Cortex-A53)+  * Five LEDs
-  * GB of RAM+  * One button
-  * integrated WiFi and BLE+  * Six 200 Ohms resistors
-  * HDMI port, an Ethernet port and four USB ports+  * Jumper wires
-  * several pins to use for electronics:​ +  * Breadboard.
-    * two 5V pins; +
-    * two 3.3V pins; +
-    * 8 ground pins; +
-    * 26 data pins; +
-    * 1 PWM pin. +
-{{ :​iot:​labs:​raspberry_pi3.png?500 |}}+
  
-The Raspberry Pi 3 has 26 GPIO soldered pins and 5 GPIO pins that you need to solderThese may be used to control electronics ​connected to the Raspberry PiAmong the things ​that can be done are+===== The Setup ===== 
-  *light up LEDs; +Connect the LEDs and the button to the Raspberry Pi following the schematics in the figure. 
-  ​*place buttons; +{{ :​iot:​labs:​traffic-lights.png?​600 |}} 
-  *use relays; +The button is connected in a voltage divider circuit. You can notice ​that the button has 4 legsUsually, one leg from one side is connected to the one in front of itHowever, there might be the case that the legs care connected side by side, this is why we encourage you to use a measuring device in order to identify how the legs are connected. Once the button is pressed, all the legs get connected. 
-  *control motors.+{{:​iot:​labs:​connected.png?​200|Button}}
  
-It is important ​to know how these pins can be accessed. For the Raspberry PiWyliodrin uses the WiringPi pins layout described below+In the schematics, the button ​is connected ​to a pull-up resistorthat means that the GPIO pin will read the value 1 if the button is pressed and 0 otherwise
-{{ :​iot:​labs:​pins-raspberrypi.png?700 |Raspberry Pi 3 Pins Layout}}+===== The Code ===== 
 +Create a new Wyliodrin STUDIO application and name it **traffic lights**.
  
-====Wyliodrin STUDIO====+{{  :​iot:​labs:​semaphore_button_streams.png?​600 ​ |Traffic Lights Applicatio }}
  
-Wyliodrin STUDIO is a web-based platform for Internet of Things applications development. You are going to use this platform throughout the course for programming ​and controlling the Raspberry Pi.+The previous shows the nodes you need to use and how to connect them. Now let's see what each node does.
  
-In order to connect ​the Raspberry Pi to Wyliodrin STUDIO you will need an SD Card with minimum 4 GB (class 10 is recommended)You also need to assure ​the Raspberry Pi has a network connection or a serial connection ​to your computer (Ethernet or serial cable).+First of all, notice ​the **semaphore** function nodeThis node is connected ​to the nodes controlling the GPIO pins connected to the LEDs and it outputs the values that need to be written on each pin.
  
-Setting up the board requires ​the following steps: +The figure below shows the code of the function. Basically, it verifies ​the value of the payload it received and depending on the value, it describes a certain state. The value 0 corresponds ​to the initial state when the cars lights have their green light turned on and the rest turned off and the pedestrian lights have the red light turned on and the green one turned off. This is why the function returns a list containing the values [0,​0,​1,​1,​0]. The block automatically knows to distribute each of these values in a message on the corresponding output (the first value is transmitted on the first output, the second value on the second output and so on). As a result, the **digital write*nodes (red, yellow, green, ped-red and ped-greed) receive ​the values 0,0,1,1 and respectively 0.
-  *Install Wyliodrin STUDIO; +
-  *Download ​the Raspberry Pi SD Card Image; +
-  *Write ​the image to an SD Card; +
-  *Connect ​the board to your computer; +
-  ​*Connect ​the board to Wyliodrin STUDIO+
  
-===Install Wyliodrin STUDIO=== +{{  ​:iot:​labs:​semaphore_function.png?​400  ​|Semaphore function}}
-Install Google Chrome and launch it. Go to [[http://studio.wyliodr.in|Wyliodrin STUDIO]], add the application to the Chrome browser and launch it.+
  
-===Set up the Raspberry Pi=== +The **digital write** nodes have names according to the LED they control (the red node controls the red LED of the cars' semaphore ​and so on)Each node controls a pin by either setting it to HIGH or to LOWThe pin will be set to HIGH if the payload of the message is 1 and to LOW if it equals 0. For each node, you need to select ​the number of the pin they are controllingFor the **red** node you need to type the number 2 for the pin, as the LED representing ​the red light is connected to GPIO 2.
-In Wyliodrin STUDIO so to **Help** and select **Setup**Choose Raspberry Pi and follow the tutorial.Connect the Raspberry Pi to the network via the Ethernet cable, then connect ​it to the platformThe default username is **pi** and the default password ​is **raspberry**.+
  
-Once the board is connected ​double click its name and give it a more suggestive name so you can recognize itThengo to **network manager** and set the WiFi credentials.+Another important aspect are the two **run** nodes. The one directly ​connected ​to the **set 0** node will get triggered once the application start running ​and then it will send message every 48 hoursFor thisyou need to double click the node and mark the **Fire once at start?**. Afterwards, you also need to set the interval to every 48 hours.
  
-So you make sure nobody connects ​to your board, open the **Shell** tab and type **passwd**. Set another password for the user **pi**.+The node connected ​to **run****set 0** is a **change** node and it allows you to change the payload of the messageAs the first state of the system is 0, the payload is set to 0 and sent to the function. Basically, the run-set 0- function connection resets the traffic lights every 48 hours. All the other **set** nodes work the same, but they set some other values to the payload. 
 +{{  :​iot:​labs:​change_edit.png?​400 ​ |}}
  
-Disconnect the board from the Ethernet cable and now you will be able to connect to it via WiFi.+The other **run** node is connected ​to **digital read**, so each second a new reading is done.
  
-====Exercises==== +The **digital read** node reads the value coming from the buttonYou have to set the number of the pin the reading should be done fromIn this case, the button is connected to pin 6, so go to the node's properties ​and set 6 for the pin
-  - Create a new Python application that prints your name in the console. +
-  - Load the **Music** example application,​ connect a speaker or headphones to the Raspberry Pi and make it sing. +
-  - Install *Math.Pi* using the **package manager**. +
-  - Create a Python application that prints your name every one second. +
-  - Run the previously created applicationUsing the **task manager** identify ​the corresponding task and kill it.+
  
 +If the value read is 1 (HIGH), you need to change the states of the lights, otherwise you can simply ignore the reading. The node named **if button pressed** is a **switch** node that routes messages based on their properties. This specific node has only one output which will send further on any message that has the payload 1, basically it will act as a filter which sends a message only when the button is pressed. The figure below depicts how to filter the values.
 +
 +{{  :​iot:​labs:​if_button_pressed.png?​400 ​ |}}
 +
 +The **switch** node is then connected to a **trigger** node. This node creates two messages whenever a message arrives on the input and it outputs the messages separated by a distance specified in the properties. For this project the node allows you to automatically send a message after 30 seconds from the pushed button so that the traffic lights system returns to its initial state. The first message has the payload 1 and the second has the payload 0, thus identifying the states the lights need to get to.
 +
 +{{  :​iot:​labs:​trigger.png?​200 ​ |Trigger node properties}}
 +
 +Further on, depending on the value the **trigger** node outputs, the **filter input** node will set the lights to the intermediate state and after 5 seconds (**delay** node) it will send another message with the value of final state stored in the payload.
 +
 +The **filter input** node is also a **switch** node which has two outputs, in this case. The first output is for the value 0 (triggered when the button has just been presses) and the second for the value 1 (triggered when the system needs to get back to its initial state). This way you can differentiate between the two.
 +
 +{{  :​iot:​labs:​filter_input.png?​400 ​ |Filter input node properties}}
 +
 +===== Exercises =====
 +  - Use a button in the dashboard to control the traffic lights;
 +  - Display in the dashboard the state of the traffic lights using the **extra widget**. **Note:** you can use the following pictures: ​
 +  * red light on: https://​dl.dropbox.com/​s/​6xl3vmpk8p4wgfc/​trafic-lights-red.png?​dl=0
 +  * yellow light on: https://​dl.dropbox.com/​s/​5mg4wecyi5xi6md/​trafic-lights-yellow.png?​dl=0
 +  * green light on: https://​dl.dropbox.com/​s/​83d90kghg0d53k4/​trafic-lights-green.png?​dl=0
 +  * pedestrians red light on: https://​dl.dropbox.com/​s/​sjr52ohr8pxb9he/​pedestrian-lights-red.png?​dl=0
 +  * pedestrians green light on: https://​dl.dropbox.com/​s/​m1ritf34ethvgt2/​pedestrian-lights-green.png?​dl=0
iot/labs/04.txt · Last modified: 2017/09/11 09:35 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