Beaglebone black supports several high-level languages like C, C++ and scripting languages like java, python. Application programming is mainly written in C language for controller or processor. Python is an interpreted language and a great library source available for BBB. At low level, Python programming is efficient and responds faster than C language.
This tutorial talks about how to create the first python program with Beaglebone Black. So, if you don't know basic Python programming, I suggest you do the same before continuing. You can also gain knowledge about the BBB through the tutorial starting with Beaglebone Black.
Install python on Beaglebone Black
Before starting programming, the user must install python on Beaglebone black. Let's check whether python is installed on Beaglebone black or not. Enter the following command:
dpkg -s python
This command displays the package installation information. If the status is “Installed ”, you can start directly with the program.
If python is not installed, install from the debian repository by typing the following command. Before entering the command, make sure the BBB has an internet connection.
Apt-get install python
Wait for the installation process to complete and check once whether it is working properly or not.
Enter the following ssh command prompt in the command form:
Phyton
Now it's time to run Python. It is interpreted, so a quick response is displayed after the execute statement.
It is working perfectly, if the on-screen display is similar to the image above.
Run python from SSH command prompt on Beaglebone black
Let's explain some python instructions to understand the concept. Refer to some online python tutorial or book if you want to learn python programming.
Type the following line after the right shift prompt and press the ENTER key if you want to print some string in the command terminal.
>>> print “Engineers’ Garage”
The following output is printed on the screen:
Engineers Garage
Create a file in Python and run it in the command terminal
Create a new folder in /root by typing the following command:
mkdir project
Enter the following command in the command terminal to enter the project directory:
CD project
Now create a new file with .py extension. Enter the following command:
tap print.py
Here print.py is the name of the fly. Open the file using any terminal editor.
nanoprint.py
Copy the following code and paste it into the print.py file:
print “Hello Engenheirosgaragen”
print “Python script in BBBn”
Press Ctrl+x and save changes to the file. Now, run the following command to run the print.py file:
python print.py
The following output will be printed on the screen:
Hello Engineersgarage
Python script on BBB