Beaglebone Library for Python

Download Report

Transcript Beaglebone Library for Python

Lab 5 Environment setup

 Beaglebone Library 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

 Step1 Connect Beaglebone to 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.com

End it by using Ctrl+c

Beaglebone Library for Python

 Step4 Download BeagleBone Library for Python python-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.git

Load(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%b after ‘>>>’  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 by python xxx.py

Introduction to Python

 Print print xxx print ‘xxx’ or print “xxx” print value  Print multiple object print ‘abc’, 10 result = root@beaglebone:# abc 10  raw_input() raw_input(“Index”)

Introduction to Python

Flow control  If [condiction]: statement 1 elif [condiction]: else: statement 2 statement 3  Distinguish statement by indent.

Introduction to Python

 while [condiction]: statement statement statement

Introduction to Python

 for [var] in range([init.], [term.], [step]): statement Ex: for i in range (1, 16, 3 )  for [var] in [array]: statement Ex: 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”