{{ :wiki:tutoriels:galileo_serial.png |}} **__Part 1 :Serial Terminal Introduction__** The purpose of this section is to propose a protocol for a new user to be able to create a serial connection to their Intel Galileo Gen 2 using a "terminal emulator". A "terminal emulator" is a program that will allow us to communicate with the Galileo via command line. **Note** The command line communication in and of itself offers no benefit to a newbie user. However, it is the only way to take advantage of a whole host of tools to better exploit our Galileo Gen 2. The reader should already have read through the previous sections and should be familiar with the basic Terminal Connection Vocabulary. Just as importantly all drivers and firmware should be up to date. The reader should equally have already installed the Arduino IDE and have successfully tested the communication with the Galileo using the "Blink" example. **__Intel's IoT devellopement kit__** To start we must first download a larger version of linux than what is already found within the galieo's flash drive. We must also download a software that will allow us to write this software onto a microSD card. I will be using Win32 The software can be downloaded from the "Galileo Basic's section" of this tutorial or can be found here: [[https://downloadcenter.intel.com/download/26472/Intel-IoT-Developer-Kit-Installer-Files?product=83137|Intel's IoT Dev Kit]] [[https://sourceforge.net/projects/win32diskimager/|Win32 Disk Imager]] *After downloading Win32 Disk Imager install as you would any other program *After downloading Intel's Iot dev kit: *Create a new folder "IoT" in the C:/Galileo/ folder * Unzip into C:/Galileo/IoT * You should have a filenamed "iot-devkit-prof-dev... .direct" *Place your MicroSD (1gb-32gb) into a card reader and connect it to your PC * Many PC's have an integrated SD card reader * If yours does not you will need a USB to SD card converter *Open Win32 Disk Imager {{ :wiki:tutoriels:capture_d_ecran_138_.png |}} * Select the blue folder next to the large blank space {{ :wiki:tutoriels:capture_d_ecran_139_.png |}} * Enable "search all file types" in the bottom right corner of the search menu * Search within C:/galileo/IoT * Select the "iot-dev-... .direct" file {{ :wiki:tutoriels:capture_d_ecran_140_.png |}} * The large blank space is now "iot-dev-... .direct' * Verify that the selected "write drive" next to the blue folder is the drive that corresponds with your SD card * You can easily test this by connecting then disconnecting your SD card reader and noting the drive that no longer appears. This is your SD card. * Select Write {{ :wiki:tutoriels:capture_d_ecran_141_.png |}} * You will br promoted to confirm the operation * Select Yes ***The file transfer will require 3-5 minutes** ***DO NOT DISCONNECT THE SD CARD DURING THIS OPERATION** *When complete you will be prompted that the file transfer has been successful **__ Accessing the Linux Shell__** I will be using PuTTY for this tutorial which can be downloaded here: [[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html|PuTTY]]. This is a well known software for Windows that will enable SSH and serial communication with the Galileo. There are multiple methods to establish serial communication with the Galileo. In this tutorial we will be using just an Ethernet Cable and a pre-made Arduino Script. Other methods require special FTID cables which I do not currently have. void setup() { Serial.begin(9600); //It’ll not continue until you send an ‘a’ through the serial monitor while(Serial.read()!='a'){ Serial.println("hello"); delay(1000); } //Display ifconfig result to serial monitor system("ifconfig > /dev/ttyGS0"); } void loop() { } {{ :wiki:tutoriels:capture_d_ecran_149_.png |}} *First we will copy/paste this code into the Arduino IDE * The command "system("ifconfig > /dev/ttyGS0");" will ask for, then transmit the Galileo's Ethernet IP address and send it to the Arduino Serial monitor {{ :wiki:tutoriels:capture_d_ecran_150_.png |}} * Before transfering the sketch verify the the COM# * Now that linux is being ran from the SD card, arduino MAY recognise the arduino under a different COM# * You can verify the COM# using start>run>devmgmt.msc>Ports(COM & LPT) mine is now COM5 * Verify connection with "Blink Example" * Transfer the sketch, after succesful tranfer, open the Serial Monitor {{ :wiki:tutoriels:capture_d_ecran_143_.png |}} * The serial monitor (at 9600 baud) will be transmitting "hello" * Type "a" into the serial monitor in the top bar * You will now have this list of IP addresses and other information *** We need the IP address that has been highlighted in blue** *Copy this IP address {{ :wiki:tutoriels:capture_d_ecran_144_.png |}} *run PuTTY *Within "Host address" Paste the IP address previously Copied *Select Open {{ :wiki:tutoriels:capture_d_ecran_145_.png |}} *You are presented with a security alert *Select Yes *It may take a moment to connect {{ :wiki:tutoriels:capture_d_ecran_148_.png |}} *You will now be asked to login into Linux that has been installed onto the Galileo *Use the login "root" *When " root@galileo:~# " appears, you are succesfully signed into the Linux shell {{ :wiki:tutoriels:capture_d_ecran_152_.png |}} * We can see that Python can be easily invoked using this interface * We simply type "Python" into the command line and we have Python now running on our galileo. * Yes; 2+3 does equal 5 **__ Part 1 Conclusion__** After reading the first part of the Linux Terminal Communication, you should now have the Intel IoT devellopement kit installed onto your Galileo Gen 2. We have introduced only 1 means of serial communication; using an ethernet cable and an arduino sketch. We hope to explore the pros/cons of this choice over an alternative method. To test a second method, we will need an FTDI cable. It should be noted that there exist multiple terminal emulators, each with pros & cons. It may interest certain users to consider: *[[https://sourceforge.net/projects/y-a-terminal/|YAT]] *[[https://ttssh2.osdn.jp/index.html.en|Teraterm]] *[[https://sourceforge.net/projects/realterm/|Realterm]] *[[http://www.dalverson.com/zterm/|Zterm]] **__Part 2: SSH for Newbies__** [[https://en.wikipedia.org/wiki/Secure_Shell|Secure Shell]] is a cryptographic network protocol for operating network services securely over an unsecured network. It is the method that we must use in order to communicate with the Intel Galileo. In order to help new users, we have compiled a short list of helpful commands to get jump started. For all of these examples: *Hit enter/return after every command unless specified otherwise *All commands are lowercase and case sensitive *All commands will be presented with first their SSH defintion * Then a more casual term to help us understand what it does * Finally a brief explanation of what it does **//Where am I//** {{ :wiki:tutoriels:capture_d_ecran_155_.png |}} *print working directory *pwd *It will identify what file you are currently in. * In this case /home/root **//What is in here//** {{ :wiki:tutoriels:capture_d_ecran_156_.png |}} * list command - **a**ll files in **l**ong format (date/size/ect) **h** (display setting) * ls -alh? * It will give a full list of all folders and files within the current directory * In this case I have node_history, python_history, ect **//Run a Program//** {{ :wiki:tutoriels:capture_d_ecran_157_.png |}} *Type the name (case sensitive) of the file we want to execute *In this example we will use "python" * Python 2.7.3 is now operating on our Galileo **//Terminate a running program//** {{ :wiki:tutoriels:capture_d_ecran_158_.png |}} *Ctrl-d will terminate a running program *Ctrl-d will terminate the terminal session if no program is running **//Create a new folder//** {{ :wiki:tutoriels:capture_d_ecran_159_.png |}} *make directory *mkdir "directory name" or mkdir "dir/file/path" *We will create a folder named dirTest * mkdir dirTest * use ls -alh to verify it exists **//Change directory//** {{ :wiki:tutoriels:capture_d_ecran_160_.png |}} *change directory *cd "directory name" or cd "dir/file/path" * allows you to open other folders * we will go into dirTest * cd dirTest * Use pwd to verify that we are in the new directory * type cd * this takes us back 1 directory * use pwd to verify that you are in /home/root * type ls -alh to view the contents **//delete directory//** {{ :wiki:tutoriels:capture_d_ecran_161_.png |}} *remove folder *rm -rf 'folder name" * be careful because this command will delete ALL files within a directory * We will delete dirTest * rm -rf dirTest * use ls -alh to verify that it has been deleted **//delete file//** *Remove *rm "filename" * An example of this is given in the follwing Part 3 **__ SSH conclusion__** We have only offered a small selection of basics SSH commands just to get started. For a more in depth understanding of SSH i would advise that you read through: *[[https://mediatemple.net/community/products/dv/204643550/common-ssh-commands|Media temple's online tutorial]] *[[http://www.sshcommands.co.uk/|SSH.co.uk offers a very complete directory]] Being able to master SSH will only empower a user to exploit the Galileo Gen 2 at it's best. This skill should not be neglected, and it's as good as time as any to learn SSH! **__Part 3 : File Sharing__** {{ :wiki:tutoriels:putty.jpg?200 |}} When using the Galileo GEN2 it is best practice to write all of your scripts/programs on you main PC and then transfer them to the Intel Galileo Gen 2. We do this for 2 main reasons: *It is far easier to compile code using our screen and proper developement tools on our pc. The galileo can not exploit a graphic interface *If for what ever reason your SD card/galileo fail, you will have all of your backup work on your PC. (which should also be backed up!) You may also find it interesting to send files back and forth between the Galileo and a server (or personal pc). This may be interesting when the data recovered by the Galileo must be transformed or shared with other nodes in a greater network. This tutorial will show the simplest case where a Master PC will send a file to a Slave galileo. When accessing the shell through SSH (so all the methods above except UART connection), files can be copied between the computer and Intel® Galileo Gen 2 with the utility scp. If using Linux or Mac OS, scp should be there already. In Windows you can get pscp. *[[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html|download PSCP]] *Once downloaded place PSCP onto your desktop for the sake of this tutorial *goto the start menu> run>cmd (open command prompt) {{ :wiki:tutoriels:capture_d_ecran_163_.png?300 |}} *we want to navigate to our desktop * cd desktop * //note// Not all commands used in command prompt are not identical to SSH although some are the same. {{ :wiki:tutoriels:capture_d_ecran_164_.png?300 |}} *Once in C:/Users/name/Desktop * type dir (for directory) * this will give a full list of programs within the dir * notice pscp, type pscp {{ :wiki:tutoriels:capture_d_ecran_165_.png?300 |}} *You will have activated PSCP. This program is only usable from the command prompt. You must also place yourself within it's directory path in order to execute this program. You can now login to your Galileo's Linux operating system using PuTTY as explained within section 1 of this chapter. We will now use the PSCP software to transfer a Python script that we write using our favorite python IDE (in this case Spyder). However, the code can be copied here (Thanks to [[https://communities.intel.com/docs/DOC-23764|the intel community board]].) from datetime import datetime #Get current time, if Intel® Galileo Gen 2 is connect to internet #It should automatically get the real time n=datetime.now() res=n.strftime("%d/%m/%y %H:%M:%S") #Append time to log file located in home directory of Intel® Galileo Gen 2 f=open("/home/root/buttonLog.txt","a+") f.write(res+"\n")f.close() *Save this file as "recordTime.py" under C:/galileo/pythonscripts {{ :wiki:tutoriels:capture_d_ecran_168_.png |}} Once logged into our Galileo Gen 2 we: *type "pwd" to see what directory we are in *type "ls -aph" to have a full list of files within our directory * here we are in /home/root {{ :wiki:tutoriels:capture_d_ecran_173_.png |}} We now open both the Command Prompt (on the left) and our Galileo's Linux OS (on the right) *Within the Command Prompt: * we type "pscp filename root@ Galileo IP address :/directory/we/want/to/save/to" * in this case : pscp recordTime.py root@169.254.10.241:/home/root * tap enter/return {{ :wiki:tutoriels:capture_d_ecran_174_.png |}} * the file should transfer (look bottom left) {{ :wiki:tutoriels:capture_d_ecran_175_.png |}} *Within the Linux terminal: * again type ls -alh * we note that recordTime.py has now been added to our /home/root directory * **note** we should create another directory "pythonScrips" to keep our galileo well organised * **note** we can delete this script anytime we want using the aforementioned SSH commands **__File Sharing conclusion__** This is a basic method to transfer scripts/files from your PC to you galileo. It should be noted that your Galileo also has a program named "spc" under the file: */usr/bin/spc This program will equally allow you send documents from your Galileo to your PC. As mentioned before, this can be an extremely powerful tool as it can allow your Galileo to recieve data and allow your PC to do the heavy calculations. In order to make scripts that will allow us to automate this process we will need to increase our knowledge/understanding of SSH and Linux. **__ Linux Conclusion__** We have now been introduced to the linux consel on the Galileo Gen 2. It is now that I will reiterate that the command line in and of itself offer's us nothing. It does however allow us to exploit a series of tools that will allow us to make the most of our Galileo Gen 2. After looking around the galileo we can probe around the different directories such as : */usr/bin : List of all supported Linux commands: * Note: The YOCTO build of Linux does not support * sudo commands * apt-get * npm (node.js file package command) * /usr/lib : List of arduino supported libraries (this is where you will want to import any future library if required. (use pscp) * /usr/include : A list of all node.js commands The YOCTO linux image will allow us primarily to exploit very powerful tools that we will elborate on within the following sections: *[[https://en.wikipedia.org/wiki/Node.js|Node.js]]: A programming language that merges front-end web & mobile apps devellopement with a very good IO control on the "arduino" side of the board. *[[https://www.python.org/|Python]]: A widely used cross-platform programming language. It is heavily used in many fields of research and therefore many projects currently being develloped by FABlab users with Python can be implemented fairly easily. *[[https://www.lighttpd.net/|Lighttpd]]: An ultra-light weight web server program. The software is very efficent at hosting static webpages with static data. Now that we can communicate with the Galileo using both the Arduino IDE as well with Linux via SSH we will now study what can be done with these various tools.