220 likes | 369 Vues
This guide walks you through the essential steps to set up a Python programming environment on the BeagleBone. From connecting your BeagleBone to your PC and verifying internet access, to downloading and installing the necessary PyBBIO library, this tutorial covers all aspects needed to get you started. You'll also learn how to interact with Python’s console, run scripts, and utilize flow control in your programming exercises. Perfect for beginners looking to harness the power of Python on their BeagleBone.
E N D
Lab 5 Environment setup • BeagleboneLibrary for Python • Introduction to Python • Programming exercise
Beaglebone Library for Python • Library for Beaglebone– PyBBIO • Including bbio libraries and so on. • Provides pin configuration and functions we need when programming. • Download and update from internet.
Beaglebone Library for Python • Step1Connect Beagleboneto PC through USB cable and to router(DHCP supporting) by Ethernet cable . • Step2 Log in to your Beaglebone with Terminal program. • Step3 Make sure your beaglebone getting on the Internet.Using ping instruction.Ex: ping google.comEnd it by using Ctrl+c
Beaglebone Library for Python • Step4 Download BeagleBone Library for Pythonpython-distutils, python-mmap, python-pyserial and PyBBIO • Type in ↓opkg update && opkg install python-distutils python-mmap python-pyserial
Beaglebone Library for Python • Type in↓cd ~/*Changes to root directory
Beaglebone Library for Python • Type in ↓git clone git://github.com/alexanderhiam/PyBBIO.gitLoad(Clone) PyBBIO.git to your Beaglebone. • Check “root” directory by ls, make sure there is a folder “PyBBIO”
Beaglebone Library for Python • Step5 Change directory to PyBBIO and see if there is a file setup.py
Beaglebone Library for Python • Step 6 Install PyBBIO by ↓python setup.py install • All will get ready when installation has done.
Introduction to Python • Python has been provided in our Beaglebone OS • Type in python –V for checking version.
Introduction to Python • Type in python for getting into conversation mode
Introduction to Python • Try to input >>> a=5>>> b=3>>> a+b>>> a-b>>> a*b>>> a/b>>>a%bafter ‘>>>’ • See what happened.
Introduction to Python • Use quit() to leave conversation mode.
Introduction to Python • Write a python source code file with .py . • Run Python source code bypython xxx.py
Introduction to Python • Printprint xxxprint ‘xxx’ or print “xxx”print value • Print multiple objectprint ‘abc’, 10result = root@beaglebone:# abc 10 • raw_input()raw_input(“Index”)
Introduction to Python • Flow control • If [condiction]: statement 1elif [condiction]: statement 2else: statement 3 • Distinguish statement by indent.
Introduction to Python • while [condiction]: statement statement statement
Introduction to Python • for [var] in range([init.], [term.], [step]):statementEx: for i in range (1, 16, 3 ) • for [var] in [array]:statementEx: for j in my_array
Introduction to Python • Nest loop • for [var] in range(): for [var] in range(): statement2 statement1
Programming exercise • 1. Write a program enable you to input your Student ID and nickname.Print out the information.
Programming exercise • 2. Write the instructions we mentioned in example of conversation mode into a file and execute it.Print the results.
Programming exercise • 3. Print out the 9*9 table. Using flow control statement.
References • Victor 程式設計教學 • http://ez2learn.com/index.php/python-tutorials/python-basic-tutorials • Head First Python–O’Reilly • Google “Python”