Phidgets supports a variety of languages, but before you start programming, you’ll need to get the library for the language you like working in, which can be found on the language pages on Phidgets.com. While you’re there, you’ll also find the code examples and an in-depth API. The C library comes with the drivers you installed in Phidgets Lesson 1. So, for this lesson, we’ll run those examples. This should get you started and ensure the Phidgets are working. You can refer to the resources provided by Phidgets to run examples in the other languages. - Download the example code and unpack the downloaded file, which has the Phidget generic C examples.
- On Linux and OSX, open a terminal window and go to the directory where the examples are unpacked, then compile the
HelloWorld.c example: On Linux: gcc HelloWorld.c -o HelloWorld -lphidget21 On Mac: gcc example.c -o example -F/Library/Frameworks -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers On Windows, you can use Visual Studio to open the examples. To load all projects in Visual Studio, go to File → Project → Solution, and open Visual Studio Phidgets Examples.sln in the VCpp folder of the examples. (Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project.) - Run the
HelloWorld example. On Linux (The sudo is needed for USB access for now, see “Setting udev Rules” for how to change this): sudo ./HelloWorld On Mac: ./HelloWorld On Windows, in Visual Studio, click on Debug → Start Debugging. The projects, by default, try to find the phidget21.h and phidget21.lib in the $(SystemDrive)\Program Files\Phidgets . If you have these files installed in another location, please change the path to the file’s location accordingly. The HelloWorld program will simply print out basic information for any device you plug in, and print a message upon unplugging the device. The output will look something like this: Opening... Press Enter to end Hello to Device Phidget InterfaceKit 8/8/8, Serial Number: 37299 Goodbye Device Phidget InterfaceKit 8/8/8, Serial Number: 37299 Closing... Examples are provided for most Phidget devices. You can compile and run each with the process enumerated above. Phidgets supports a variety of languages. If you’re not programming in C, you’ll need to get the library for the language you’re using before you start. The libraries can be found on the language pages on Phidgets.com. When you’re there, you’ll also find the code examples and an in-depth API. Now, it’s on to writing your own code. You can use the examples as a guide for your project. In later lessons, we’ll explore some of the functions, data structures and classes to give you an idea of all that can be done with Phidgets. Phidgets are easy to use sensors and controllers for programmers. After just a bit of coding, you’ll have your computer connected to the real world via an assortment of sensors as well as motors, relays, remote control, RFID, LEDs and more! But first, you’ll need to get the drivers installed, and luckily, it will take less than 5 minutes. - Download the appropriate Phidgets driver for your operating system from Phidgets.com.
- If you’re on Windows or Mac, open the installer you just downloaded. A wizard will guide you through the installation.
- If you’re using Linux, use
apt-get to install libusb-1.0-0-dev , if you don't have it already. (Note that libusb-1.0 may be on your system already, but the development libraries probably aren’t.) Navigate to the directory where you unpacked the Phidget libraries. From the main unpacked library directory first run ./configure , then make and finally sudo make install . - Now that the Phidgets drivers are installed, let’s do some quick tests to make sure the installation worked. First plug in one of your USB devices (like an interface kit, which is what we’ll use in this example).
- On Windows, go to the Windows Device Manager, then to Devices and Printers (this is for Windows 7 and exact naming may be different on your computer). A list of all the connected devices should appear, and if you scroll down, any connected Phidgets should be listed under the section titled "unspecified".
- On Mac, go to "About This Mac" and click on more info, then system report. Under hardware, click on USB and there you can see that a Phidget device is connected.
- On Linux, you can use the kernal log reader
dmesg . Pipe the output of the dmesg into the utility tail to read the last ten lines of the log: $> dmesg | tail ....(9 lines).... [24344.013638] usb 2-1.2: new low speed USB device number 5 using ehci_hcd The number between the square brackets is the system time in seconds since the last boot up, so you can tell whether the event was recent or not. If the Phidget device is not showing up, then check these general troubleshooting tips, or these specific ones for Linux. - If you’ve got it working, it’s time to try out the software. The Windows and Mac installation come with a Control Panel app that offers a quick check that your devices are connected. For Linux, we’ll use the examples to check that everything is working fine, which will be covered in the next lesson.
- On Windows, you should see the icon in the taskbar. Double click on it to bring up the Phidget Control Panel. If the icon does not appear, just find and open the Phidget Control Panel from the start menu.
- On a Mac, open up your System Preferences. You should see a Phidgets icon in the "Other" section at the bottom. Clicking on it will open the Phidgets Control Panel.
- If you have devices connected, they'll show up in the Control Panel. As you can see in the General tab, we're working with an RFID 2-output and Phidget InterfaceKit 8/8/8.
- Double click on the Phidget device you want to play with. The software will be able to control outputs (like LEDs) and respond to inputs (like sensors or RFID chips). If the Phidget device is not showing up or working properly, then check these troubleshooting tips.
That was easy! You’ve already got to see your Phidgets interacting with the real world, but there’s more we can do. Let’s check out the examples in Lesson 2. |
No comments:
Post a Comment