|
|
Line 1: |
Line 1: |
| [[Category:Language]]{{NoTitle}} | | #REDIRECT [[Language - Python]] |
| {|
| |
| |style="vertical-align:middle; width: 60%;"|
| |
| <font size=6>'''Language - Python'''
| |
| | |
| '''SBC Linux with Python'''</font>
| |
| | |
| Welcome to using Phidgets with Python! By using Python, you will have access to the complete Phidget22 API, including events.
| |
| | |
| |{{TOC limit|2}}
| |
| |}
| |
| ==Getting Started With the Phidget SBC==
| |
| Welcome to using the Phidget SBC. If you haven't already, check out the [[SBC3003 User Guide#Getting Started | user guide]] in order to set up the following:
| |
| * Networking
| |
| * Administrator password
| |
| | |
| | |
| If you are ready to go, the first step will be deciding how you will use the SBC:
| |
| *Use a more powerful external computer to develop your code, and then simply copy the files to the SBC.
| |
| *Use the SBC like any other Linux computer, simply connect a monitor and a keyboard and begin your development.
| |
| | |
| | |
| This guide will cover development using an external machine. For development using the SBC itself, check the [[Language_-_Python_Linux_Terminal|Terminal (Linux)]] page.
| |
| | |
| To begin, this video will help you get started:
| |
| <center>{{#ev:youtube|OhFbGzalBFw}}</center>
| |
| | |
| | |
| ===Developing with an External Computer===
| |
| {{SBC_Developing_with_an_External_Computer}}
| |
| | |
| | |
| ===Installing Packages for Development===
| |
| Installing support for Python has three steps:
| |
| #Ensure ''Include full Debian Package Repository'' is checked on the SBC Web Interface (System->Packages)
| |
| #Install Python
| |
| #Install Phidget Python module
| |
| | |
| You will need to run commands on the SBC to install support for Python. You can either use SSH to issue the commands, or you can connect directly to the SBC via a monitor and keyboard.
| |
| | |
| ====Basic Python====
| |
| The base Python functionality can be downloaded and installed in one step:
| |
| <syntaxhighlight lang=bash>
| |
| apt-get install python
| |
| </syntaxhighlight>
| |
| | |
| Next, you need to install the Phidget Python module. To do so, you have to main options:
| |
| | |
| {{SBC_Python_Tabber}}
| |
| | |
| You're now ready to begin programming! Continue through this guide for code examples and directions on where to go next.
| |
| | |
| {{Finding Code Samples|Python}}
| |
| | |
| ==Setting up a New Project==
| |
| '''''For simplicity, if you have not used Phidgets before, we recommend first trying them out directly on an external development machine like a desktop computer. For Python development, check the [[Language_-_Python_Windows_Command_Line|Command Line (Windows)]], [[Language_-_Python_macOS_Terminal|Terminal (MacOS)]], and [[Language_-_Python_Linux_Terminal|Terminal (Linux)]] pages.'''''
| |
| | |
| When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget Python library.
| |
| | |
| When developing on an external computer, you will write, compile, and test your programs on that machine. When you are ready, you will then upload your programs to the SBC to run them.
| |
| | |
| | |
| Once your code is written, follow these steps to get your program running on the SBC:
| |
| | |
| 1. Using the SBC Web Interface, create a new project:
| |
| [[File:Phidgetsbc_createproject.PNG|link=|alt=|center]]
| |
| | |
| 2. Transfer all the example files from the development machine to the SBC, either using the SBC Web Interface or a tool like [https://winscp.net/eng/download.php WinSCP]. The project directory will be <code>/usr/userapps/ProjectName</code>
| |
| | |
| 3. Use [[#SSH|SSH]] to access the SBC terminal
| |
| | |
| 4. Navigate to the project folder using the command:
| |
| | |
| <syntaxhighlight lang=bash>
| |
| cd /usr/userapps/ProjectName
| |
| </syntaxhighlight>
| |
| | |
| 5. You can now run the program with the command:
| |
| | |
| <syntaxhighlight lang=bash>
| |
| python ExampleName.py
| |
| </syntaxhighlight>
| |
| | |
| Success! The program is running on your SBC. Next, you may want to learn about [[#Running a program automatically|running a program automatically]].
| |
| | |
| ==Running a Program Automatically==
| |
| After testing your program, you will likely want it to run on boot, or on a schedule, without your input.
| |
| | |
| To run a Python script as a standalone application, you will need to add a line called a "shebang" to the top of the script, with the path to your Python executable. If you have followed the steps in this guide, the line will be:
| |
| | |
| <syntaxhighlight lang=python>
| |
| #!/usr/bin/python
| |
| </syntaxhighlight>
| |
| | |
| {{SBC_Running_A_Program_Automatically}}
| |
| | |
| {{Language Page What's Next}}
| |