{"id":8413,"library":"phidget22","title":"Phidget22 Python Wrapper","description":"Phidget22 is the official Python library for working with Phidgets in Python applications. It provides lightweight bindings to the native phidget22 library. The current version is 1.25.20260408, and the library is actively maintained with frequent updates, often multiple times per year, bundling native libraries for major operating systems.","status":"active","version":"1.25.20260408","language":"en","source_language":"en","source_url":"https://github.com/lucapinello/Phidget22Python","tags":["hardware","phidgets","sensors","actuators","io","embedded"],"install":[{"cmd":"pip install phidget22","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"The Python wrapper provides lightweight bindings to the native Phidget22 C library. For Windows, Linux, and macOS, the native library is bundled with the pip package. For other operating systems, or for specific hardware like HID USB Phidgets on macOS, the native library or drivers may need separate installation.","package":"Phidget22 native library","optional":false}],"imports":[{"note":"Phidget22 uses 'Phidget22' as the top-level package, distinguishing it from the older Phidget21 library which used 'Phidgets'.","wrong":"from Phidgets.Phidget import *","symbol":"*","correct":"from Phidget22.Phidget import *"},{"note":"Device-specific classes are found under `Phidget22.Devices`. It's common to import specific device classes for clarity.","symbol":"TemperatureSensor","correct":"from Phidget22.Devices.TemperatureSensor import TemperatureSensor"}],"quickstart":{"code":"import time\nfrom Phidget22.Phidget import *\nfrom Phidget22.Devices.TemperatureSensor import *\n\ndef onAttachHandler(self):\n    print(\"Attach Event: \" + self.getDeviceName())\n\ndef onDetachHandler(self):\n    print(\"Detach Event: \" + self.getDeviceName())\n\ndef onTemperatureChangeHandler(self, temperature):\n    print(\"Temperature: \" + str(temperature) + \" °C\")\n\ndef main():\n    try:\n        # Create your Phidget channels\n        temperatureSensor = TemperatureSensor()\n\n        # Set event handlers\n        temperatureSensor.setOnAttachHandler(onAttachHandler)\n        temperatureSensor.setOnDetachHandler(onDetachHandler)\n        temperatureSensor.setOnTemperatureChangeHandler(onTemperatureChangeHandler)\n\n        # Open your Phidget and wait for attachment\n        print(\"Waiting for Phidget TemperatureSensor to be attached...\")\n        temperatureSensor.openWaitForAttachment(5000)\n\n        print(\"Press Ctrl+C to Exit\\n\")\n        while(True):\n            time.sleep(1)\n\n    except PhidgetException as e:\n        print(\"Phidget Exception: \" + str(e.code) + \" - \" + e.details)\n    except KeyboardInterrupt:\n        pass\n    finally:\n        try:\n            temperatureSensor.close()\n        except PhidgetException as e:\n            print(\"Error closing Phidget: \" + str(e.code) + \" - \" + e.details)\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart initializes a `TemperatureSensor` object, registers event handlers for attachment, detachment, and temperature changes, and then waits for a sensor to be connected. It prints temperature readings to the console as they occur. The program includes basic error handling and a clean shutdown."},"warnings":[{"fix":"Review the 'Upgrading Code from Phidget21 to Phidget22' guide in the official Phidgets documentation and rewrite affected parts of your application, focusing on the new modular object model and event-driven programming. Ensure you are importing from `Phidget22` and not `Phidgets`.","message":"Upgrading from Phidget21 to Phidget22 involves significant API changes. Object structures have been broken into more modular components, property and method names have changed (e.g., `open()` instead of `open()`), and outputs/settings are no longer persistent across channel opens/closes.","severity":"breaking","affected_versions":"All versions of Phidget22 when migrating from Phidget21"},{"fix":"Install the necessary macOS libraries or the Standalone Control Panel from the Phidgets website. Check your Phidget's product page specifications to determine its USB stack.","message":"HID USB Phidgets on macOS (legacy devices) require special driver installation or the Phidget Control Panel to function correctly, even with the Python library installed via pip. Newer USB and VINT Phidgets do not have this requirement.","severity":"gotcha","affected_versions":"All versions of Phidget22 on macOS with HID USB Phidgets"},{"fix":"Double-check that the addressing parameters match your physical Phidget device and its connection. If unsure, try omitting parameters with `openWaitForAttachment()` to allow the library to find any available device of the specified class.","message":"Phidgets require specific addressing parameters (e.g., `DeviceSerialNumber`, `Channel`, `IsHubPortDevice`) for unique identification. Incorrect or missing parameters are a common cause of devices not attaching or 'Timed Out' errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure that your Phidgets and any connected VINT Hubs have the appropriate external power supply connected and functioning.","message":"Many Phidgets, especially certain VINT devices or hubs, require external power to operate correctly. A lack of power can lead to 'Device Not Attached' or 'Timed Out' errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Add `NetworkServer.exe` (typically in `C:\\Program Files\\Phidgets\\Phidget22\\`) to your Windows Defender Firewall exceptions, or configure your firewall to allow connections for the Phidget Network Server.","message":"The Phidget Network Server (used for remote Phidgets) can be blocked by firewalls, preventing Python applications from connecting to remote devices or discovering them.","severity":"gotcha","affected_versions":"All (when using network server)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `phidget22` is installed in your environment (`pip install phidget22`). Verify your import statements use `from Phidget22...` and not `from Phidgets...`. If using a virtual environment, ensure it's activated.","cause":"The Phidget22 Python package is either not installed in the active Python environment, or the import statement refers to the old Phidget21 library (e.g., 'Phidgets' instead of 'Phidget22').","error":"ImportError: No module named 'Phidget22' (or similar for submodules like Phidget22.Devices)"},{"fix":"Verify the Phidget is physically connected, powered on (if needed), and not already in use by another application (e.g., the Phidget Control Panel). Double-check any `DeviceSerialNumber`, `Channel`, or `HubPort` parameters you've set, or increase the `openWaitForAttachment()` timeout.","cause":"The Phidget device could not be opened within the specified timeout. Common reasons include the device not being plugged in, incorrect addressing parameters (serial number, channel, hub port), the device being busy (opened by another program), or a power issue.","error":"PhidgetException: TIMED_OUT (or a similar message containing 'Timed Out')"},{"fix":"Close any other programs or instances that might be using the Phidget, including the Phidget Control Panel. If you suspect a background process, check your operating system's task/activity monitor.","cause":"The Phidget device you are trying to open is already open by another process or application. This could be the Phidget Control Panel, another instance of your program, or a different application.","error":"PhidgetException: BUSY (or a similar message containing 'Resource Busy')"},{"fix":"Ensure the device is firmly connected and powered. Use `openWaitForAttachment()` with a sufficient timeout before attempting to read from or write to the device. Implement `onAttachHandler` and `onDetachHandler` to manage the device's state.","cause":"The program is attempting to interact with a Phidget channel that is not currently attached or has become detached. This can occur if the device was unplugged, lost power, or the `openWaitForAttachment()` call failed or was not used, and the program tried to access the device before it was ready.","error":"PhidgetException: DEVICE_NOTATTACHED (or a similar message containing 'Device Not Attached')"}]}