Language - Python Windows Visual Studio

From Phidgets Support
Revision as of 19:54, 5 July 2018 by Mparadis (talk | contribs)

Use our examples

One of the best ways to start programming with Phidgets is to use our example code as a guide. Before we get started, make sure you have read how to install the Phidget Python module section above. You will also need to download Microsoft Visual Studio if you have not already.

Now that you have Python and the Phidget Python module installed, as well as Visual Studio, select an example that will work with your Phidget:


Next, create a new Python project:

Python vs newproject.PNG


Delete the Python file that was generated with the project:

Python vs delete.png


Add the example you just downloaded by right-clicking on the project and adding an existing item:

Python vs addexisting.png

Add PhidgetHelperFunctions.py in the same as the example.

Select the example as the startup file:

Python vs startupproject.png


Ensure that your Python environment is the same as the version you have installed. Enter the following command to view your Python version if you are unsure:

python -V
Python version.PNG

You can view/edit your Python environment under the Python Environments tab:

Python vs environment.png


You should now have the example up and running for your device. Your next step is to look at the Editing the Examples section below for information about the example and important concepts for programming Phidgets. This would be a good time to play around with the device and experiment with some of its functionality.

Setting Up a New Project

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.

To start, you need to create your project as shown in the previous section.

To include the Phidget Python library, add the following line to your code:

from Phidget22.PhidgetException import *
from Phidget22.Phidget import *

Then, you will also have to add a reference to your particular Phidget. For example, you would include the following line for a DigitalInput:

from Phidget22.Devices.DigitalInput import *

The project now has access to Phidgets.

Further Reading

Phidget Programming Basics - Here you can find the basic concepts to help you get started with making your own programs that use Phidgets.

Data Interval/Change Trigger - Learn about these two properties that control how much data comes in from your sensors.

Using Multiple Phidgets - It can be difficult to figure out how to use more than one Phidget in your program. This page will guide you through the steps.

Polling vs. Events - Your program can gather data in either a polling-driven or event-driven manner. Learn the difference to determine which is best for your application.

Logging, Exceptions, and Errors - Learn about all the tools you can use to debug your program.

Phidget Network Server - Phidgets can be controlled and communicated with over your network- either wirelessly or over ethernet.