Differences

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

Link to this comparison view

iot:labs:02 [2015/06/22 08:25]
madalina.tanea [The Setup]
iot:labs:02 [2017/09/11 09:33] (current)
alexandru.radovici created
Line 1: Line 1:
-===== Lab 02. Blinking LED =====+====== Lab 2: Linux =====
 +Embeded boards run Linux, this is why when interracting with them you might need some basic notions concerning this operating system in case you haven'​t come across it so far. 
  
-==== What you need ==== +===== The Shell===== 
-  * One Edison connected ​to Wyliodrin;​ +The Shell is a window that allows you to interact with the boardIt waits for you to enter a command and it executes itOnce you open a Shell, you will see the prompt. That means everything works fine and the Shell is waiting for your command.
-  * One LED; +
-  * One 200 Ohm resistor; +
-  * Two male-female jumper wires. +
-{{:​iot:​labs:​ledd.png?30}}  +
-{{:​iot:​labs:​resistor.png?60 |}}+
  
 +The prompt also offers you some information. First of all, it shows you the user currently logged in. The user's name is that you see before //@//. It also shows the host name of your board.
 +The most important information the prompt displays is the working directory. That is the directory where you are currently working in. It is displayed right after the colon in the prompt. You will notice that the default working directory is //~//. That is the user's home directory and its equivalent is ///​home/​username//​.
 +===== Paths =====
  
-==== The Setup ==== +In order to access a certain file or directory, you have to take into account the path to it. There are two different paths you can use: absolute and relative.\\ 
-Connect ​the LED to the Edison following ​the schematics ​the figure.+In Linux, the directories'​ structure is like a tree. The root directory is ///// and it contains all the other directories and files.\\ 
 +If you use an absolute path to a file or a directory, that means that you build the path to it starting with the root directory. Thus, you can say that any path that starts with // / // is an absolute path.\\ 
 +On the other hand, you can use a relative path, which means that you build it starting from the directory you are working in, your working directoryThus, all the files and directories are relative to it.\\ 
 +When building paths, there are three symbols you should be familiar with:
  
-You will see when you look at the LED that it has two legs. One is longer, that one is usually the anode. This one has to be connected to the GPIO pin of the Edison. The shorter leg should to be connected to the resistor and then to the ground pin of the board.  +  *  - current directory 
-{{ :​iot:​labs:​ledblink.png?500 |}} +  ​* ​.. -parent directory 
-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. That means that we 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.  +  * // ~ //  - home directory (/​home/​username)
-==== Streams programming language ==== +
-Streams is an inbuilt programming language used in Wyliodrin to create many complex IOT projects. ​+
  
-It is quite different from  usual programming languages, and it can sometimes contain visual blocks as functions.+===== pwd =====
  
-This programming language works not as in imperative one, but is based on a data flow. The nodes will send messages to one another. You can look at these messages as JSON objects. Any message has two important fields: one will be the payload and a second one the topic.  +The //pwd// command makes the Shell print the working directoryIt is important to know which directory ​you are working ​in and sometimes it is difficult to get it from the promptSoanytime ​you feel lost, use //pwd//.
-Any action in Streams starts with the //run// nodeAs you can see in its description,​ this node will set a payload at a certain intervalMore specifically, you can choose in its settings to send the message at a certain time interval or at a specific time.  +
-==== The Code ==== +
-ou go to the Wyliodrin Applications page and create a new application. You name it and select for the Streams programming language and select the example ​//Led Blink - Streams//. This will create an application that makes an LED connected to the pin 0 of the Edison to blink.+
  
-Once created, you click on the new application'​s name to open it. A new window will open to display it. +===== ls =====
-{{ :​iot:​labs:​blinkstreams.png?​500 |}} +
-In this example, the //run// node will send a message every 1 second to the node that says //blink//. Look in its settings. The //payload// field will be a number, incremented by one. The //blink// node is the one which holds the visual blocks. Double click on the latter to see the function inside. It will be in Visual Programming.  +
-{{ :​iot:​labs:​blinkblocks.png?​600 |}} +
-What it does is to set a variable //new message// with the value of the data sent from this node to the next one to come.  Now, this very message is composed like this: take the payload sent from the first node and divide it by 2. Which means the new message will be either 1 or 0. The function returns just one of these values, depending on the case.  +
-The last node is simply the digital write function. It will ask as a parameter for the pin number, so double click on it and specify the pin you are going to use. On this pin it will write the message that was previously composed.  +
-==== Tips & Tricks ​===+
-We said that 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. +
-==== Add a button ==== +
-You can easily add a button to turn on and off the LED. +
-=== What you need ===+
  
-  * One Edison connected to \Wyliodrin;​ +//ls// makes the Shell print all the files and directories located in the working directoryIf you want to see la contents of some other directory, you can pass that directory as an argument ​to the commandFor instance, if you want to print all the files and directories in /, you will write:  //ls / // .\\
-  * Two 200 Ohm resistor; +
-  * Four male-female jumper wires; +
-  * Two male-male jumper wires; +
-  * One button; +
-  * One LED. +
-=== Schematics === +
-To connect it, just think about the button as a voltage divider, ​the same as for the thermistorLook in the introduction ​to electronics ​to properly understand ​the concept{{ :​iot:​labs:​buton.png?​300 |}} +
-=== The code === +
-You won't need to use more than 3 blocks.  +
-{{ :iot:​labs:​button.png?​300 |}} +
-  *  one is the usual //run// +
-  *  read the digital pin to which the button is connected +
-  *  write its value on the pin where the LED is wired+
  
 +===== cd =====
  
 +You already know that once you open a Shell, the working directory is your home directory. However, you will need to work in other directories too. In order to change the working directory, you will have to use // cd// followed by the directory you want to go to.\\
 +For example, if your home directory contains a directory called //​homework//​ and you want to have that as the working directory, you use //cd homework//. You can notice that you used an absolute path. Some other alternatives would be //cd /​home/​pi/​homework//​ or //cd ~/​homework//​. In the last two examples you used an absolute path to refer to //​homework//​ directory.\\
 +
 +===== cat=====
 +
 +//cat// asks the Shell to print the contents of a file. However, it must be clear that you can only see its contents, you cannot modify them. For that you need an editor.
 +
 +Just like with the //cd// command, //cat// gets as an argument the file it should display.
 +
 +Example: //cat /​etc/​passwd//​
 +
 +===== htop =====
 +
 +By using the //htop// command you can see real-time all the processes that run on your board. Once you entered the command you will notice that the prompt does not appear, that is because you cannot enter another command until you are finished with displaying the processes. So, if you want to go back to what you were doing, just hit the //q// key.
 +
 +{{ :​iot2015:​labs:​htop.png?​500 |}}
 +For each process displayed, you can see its PID (Process ID), the user who launched the process, how much CPU and memory it is using, the command that started the process and other information.
 +
 +What you are most interested in is the PID. That is because each process can be identified by its PID and if you want to interact with it, you have to know its process ID.
 +===== kill =====
 +
 +You know that you can use //htop// to find a process'​ ID in order to be able to interact with it. //kill// is the command that allows us to interact with another process.
 +
 +Two processes can interact by using signals. A signal is a number a process sends to another. Both processes know that each number represents an action. you can refer to a signal either by the number or by its name.
 +{{ :​iot2015:​labs:​kill.png?​500 |}}
 +
 +The format of the //kill// command is the following: //kill -signal pid//, where signal is the number representing the action you want to process to do and pid is the process ID.
 +
 +The two signals you are most interested in are //SIGTERM// (number 15) and //SIGKILL// (number 9). 
 +
 +SIGTERM tells the process to stop its execution. Normally, the process should save all its data and stop running. However, this signal can be ignored by the process. There are times when you cannot kill a process by using SIGTERM.
 +
 +On the other hand, SIGKILL, kills the process no matter what. The downside is that the process does not have the opportunity to save its data, so killing it like this can result in loss of data. Neverthless,​ if something happened and your process must be forced to stop, you have to use SIGKILL.
 +
 +In case the running process has a Shell attached and you can access it, you can simply use a key combination to send the SIGTERM signal to it and make it stop, //Ctrl+C// .
 +
 +===== killall =====
 +
 +//killall// has the same effect as //kill//, except that you do not have to know the PID of the process, but its name. Instead of passing the process ID as an argument, you have to pass the process name.
 +
 +===== Tips & Tricks =====
 +
 +Getting used to working with a Linux Shell is not difficult, especially if you know the following tricks:
 +  *  Whenever you are typing a command use the //TAB// key. It will auto complete what you wanted to type, thus eliminating spelling errors. In case there are multiple possibilities,​ press TAB once more and they will be displayed. If by pressing TAB the command or the argument you want to type is not automatically filled in, it means the command is not valid.
 +  * The most important command you should know is //man//. By using //man// followed by another command name, you have access to that command'​s manual and you can find how to use it and all it can do.
 +===== Exercises =====
 +
 +  - Create a new folder // Folder1 // and a file inside it //My file //. Create a new folder // Folder 2//. Move it inside the first folder and rename it to // Folderception//​. List the content of Folder1. Delete the first folder and its content using a single command. \\ **Hint** you can use the manual pages to find and understand the commands. Also use apropos to find the needed command (eg. $ apropos "move files" )
 +  - Open a new project in Wyliodrin and run it. Find the process and its PID. Kill the process. \\ **Hint** Some commands may need root permissions to run. Using //sudo// in the beginning of the respective command gives you the needed permissions. ​
  
iot/labs/02.1434950708.txt.gz · Last modified: 2015/06/22 08:25 by madalina.tanea
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