Beaglebone black supports various high-level languages such as a C, C++, and scripting languages like Java and Python. Programming of an application is mostly written in C language for controller or processor. Python is an interpreted language and great library source available for BBB. At low level, programming in python is efficient and responds quicker than C language.
This tutorial talks about making first python program with Beaglebone Black. So in case you are not aware of basic python programming then I suggest you to go through the same before proceeding. You can also gain knowledge about BBB through the tutorial getting started with Beaglebone Black.
Install python on Beaglebone Black
Before starting programming, user is required to install python on Beaglebone black. Let’s check if the python is installed on the Beaglebone black or not. Enter the following command:
dpkg -s python
This command displays the information of package installation. If status is “Installed”, you can directly start with program.
If python is not installed, install from debian repository by entering the following command. Before entering the command, make sure that BBB has internet connection.
Apt-get install python
Wait for completion of installation process and check once if it’s working correctly or not.
Enter the following command form ssh command prompt:
Fig. 1: Screenshot of Running Python from Linux Console on Beaglebone Black
Now it’s time to run Python. It is interpreted, so quick response is displayed after run instruction.
It is working perfectly, if the display on screen is similar to the above image.
Run python from SSH command prompt in Beaglebone black
Let’s explain a few instructions of python for understanding of concept. Refer to some online python tutorial or book if you want to learn python programming.
Enter the following line after right shift prompt and press ENTER key, if you want to print some string on command terminal.
>>> print “Engineers Garage”
The following output is printed on screen:
Fig. 2: Screenshot of Printing Message by Python Script on Linux Console on Beaglebone Black
Create a file in python and run from command terminal
Create a new folder in /root by entering following command:
Enter the following command from command terminal for entering in project directory:
Now create a new file with .py extension. Enter the following command:
Fig. 3: Screenshot of Creating New Python File from Linux Console on Beaglebone Black
Here print.py is name of flie. Open the file using any editor from terminal.
Copy the following code and paste in print.py file:
print “Hello Engineersgaragen”
print “Python script in BBBn”
Fig. 4: Screenshot of Python Script on Beaglebone Black
Press ctrl+x and save the changes in file. Now, run the following command for run print.py file:
The following output will be printed on screen:
Python script in BBB
Fig. 5: Screenshot of Python Script on Beaglebone Black
You may also like:
Filed Under: BeagleBone, Electronic Projects