Linkit Smart Duo: Python support

The objective of this post is to explain how to use Python in the Linkit Smart Duo Operating System.


Introduction

As explained in a previous post, we can use the Python programming language to develop applications for the Linkit Smart Duo board.

This tutorial will focus on explaining the basics of using Python in the Linkit Smart Duo which, as we will see, is pretty much the same as we would do in any Linux environment.

Since Python comes pre-installed in the board’s operating system (OpenWrt), we can start using it straight ahead.

First of all, we will need to connect to the Linkit Smart Duo through SSH. You can check a detailed guide on how to connect to the Linkit Smart Duo using a software called Putty here.


Using Python

Once establishing the connection to the Linkit Smart Duo, we can start exploring Python.

We will start by determining which version of Python comes pre-installed in the board. To do so, in the command line, we just need to type python -V and press enter. Figure 1 shows the expected result.

My board’s installation came with version 2.7.9, as seen in figure 1.

linkit-smart-python-version

Figure 1 – Checking Python version of the Linkit Smart Duo board.

You can check more details on the available commands for Python here.

Although in Python we typically program by developing scripts in a file and running the whole script, this language also allows for the execution of separate commands in a command line style. To keep things simple, this is the approach we will follow in this introductory tutorial.

So, to launch Python’s command line, just type Python and press enter. You should get a result similar to the one shown in figure 2.

 linkit-smart-duo-python-command-line

Figure 2 – Running Python’s command line.

Now, we can send some commands. So, to print the famous “Hello World”, we just need to type the following and press enter:

print “Hello World”

A “Hello World” message should be printed in the command line, as shown in figure 3.

linkit-smart-python-hello-world

Figure 3 – Python “Hello World” on the Linkit Smart Duo.

To finish our first test with Python’s command line on the Linkit Smart Duo, we will just issue a final command to print all the available Python Modules. To do so, we just type the following and press enter:

help(‘modules’)

We will first get a “Please wait” message, as shown in figure 4.

linkit-smart-python-get-available-modules

Figure 4 – Python’s module information fetching.

After a while, we will get the list of available modules, as shown in figure 5.

linkit-smart-default-python-modules-list

Figure 5 – List of default Python modules.

To exit Python’s command line and go back to the Operating System command line, just type the following and press enter:

exit()


Installing additional modules

Although the default Python installation already comes with a big list of modules, we may need to install some additional ones. So, the board also comes pre-installed with a Python package installer called pip.

Installing Python packages with pip is as easy as typing the following command:

pip install packageName

Naturally, to install new packages with pip we need to have our Linkit Smart Duo connected to the Internet.

We can check pip version with the command pip -V. The expected output is shown in figure 6.

linkit-smart-pip-version

Figure 6 – Printing pip version.

We can also check the modules installed with pip with the command pip freeze. The expected output is shown in figure 7.

linkit-smart-check-pip-modules

Figure 7 – Printing pip modules.

Note that the previous pip commands should be sent from the Operating System command line and not from Python’s command line.


Related Posts


Related Content

Advertisements
This entry was posted in LinkIt Smart and tagged , , , , , , , . Bookmark the permalink.

4 Responses to Linkit Smart Duo: Python support

  1. Pingback: Linkit Smart Duo: Blinking a LED with Python | techtutorialsx

  2. Pingback: LinkIt Smart Duo: Connecton to WiFi Network | techtutorialsx

  3. Pingback: LinkIt Smart Duo: Transferring files with SCP | techtutorialsx

  4. Pingback: LinkIt Smart Duo: Running a Flask server | techtutorialsx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s