.comment-link {margin-left:.6em;}


A Periodic (P)review Of Leaping Forward

By: Johan

Saturday, January 14

Phidgets & Mac - Part 1 - Introduction & Installation

I bought myself a Phidgets LED Kit from Active Robots for Christmas. Phidgest are physical widgets; they allow electro newbies like myself to develop cool stuff ranging from a simple website controlled dog feeder to full blown cockpit simulators. I have an idea or two as well but before revealing those I have a host of problems to tackle.

I'm planning to write a series of 'notes to myself' here on my blog to document my Phidgets programming experience. I'll try and write in such a way that it may work as a tutorial on phidgets coding for other Mac users as well. This first part is a total newbie's, idiot's slash dummy's introduction.

When I bought the LED board I didn't own this Powerbook yet. I was planning to develop in VB on Win XP first since it seemed the easiest language with lots of working examples ready to be hacked to bits. I'm not a code guru and have no plans becoming one but for a hobby I don't mind learning another language. OK maybe I am close to a PHP expert but that doesn't translate easily into all the other languages out there like Ruby, C and Xcode. My back-up plan was to just develop in Java or Python on Linux; back then my OS of choice.

All of those plans went out of the window when I was given a Powerbook as a Christmas bonus. Luckily Phidgets do support Mac OS Tiger! And judging by the installation readme it's all quite simple as well:

The framework is basically just a dynamic shared library. The easiest way to use it is to create an xcode project and add the Phidget20 framework, then in your sourcecode you just have to define top level header:


CoreFoundation has to be included before Phidget20.

Yeah... But I had never heard of a 'dynamic shared library' or 'xcode'.


Xcode seems Apple's programming language of choice. They've dedicated a whole section of their website to it here. Appdevadvisor puts it in these words:

You can think of Xcode as being the Apple equivalent of VS.NET. It’s probably fair to say that the ‘preferred’ mainstream PC programming language is now C# (preferred by Microsoft, that is, but not necessarily what the majority of third-party developers are currently using). On the Mac, the hot dev language on the block is a deeply strange animal called Objective-C.

So I guess Xcode is just the tool or framework to write Objective-C? No idea. What is Cocoa then? Also Objective-C language according to Jason's comparison with VB.net. So I'm a bit confused but that doesn't stop me from diving in at the deep dark end. Comprehension of this OS language geekspeak will probably come later. Before I say that, according to Wikipedia, Xcode is nothing but a coding environment, just an IDE. So if Zend studio is my IDE for PHP, I guess Xcode will be my developing environment for Objective C. This quote confirms that idea:

Xcode includes GNU Compiler Collection (GCC), and can compile C, C++, Objective C++, Java, AppleScript, and Objective C source code with a variety of programming models, including but not limited to Cocoa, Carbon, and Java. Third parties have added support for GNU Pascal, Free Pascal and Ada.

So... Let's get cracking!

I've hooked up the Phidgets LED board via USB to my Powerbook and via a Skytronic 12 Vdc switch mode power supply to the wall for juice. That's about the max recommended voltage for this Phidget; the included leaflet talks about just 6 Vdc at 1.5 Amps. The guys at Active Robots said this would be perfect so fingers crossed...

After the hardware, we'll need the software components. Go get the Mac OS Phidgets Framework wich includes the phidget20 (C API) library, the MAX/MSP extension, and the PhidgetWebService. As far as I'm aware, the Phidget20 API library contains all the pre-built API's to see and use your connected widgets. They should help speed up the development process. I have no clue what the MAX/MSP extension is; maybe we'll get to that later. The PhidgetWebService is an interesting one; this allows use to remote control our phidgets. I've seen someone who built a tablet PC with servo phidgets on a remote control car chassis so you could control it from anywhere in the world via the internet. Something I'll be using as well but not so much to control it externally but more to pull in data from across the web and let the LEDs change according to that data.

We'll also have to install the Xcode Tools package that ships with your Mac. It's located under Applications > Installers > Xcode Tools. Just double click the mpkg file to launch the install wizard. I could find where it went with the help of a spotlight search. Browse to it via Macintosh HD > Developer > Applications. Once you open it and run the assistant wicard, there's another little suprise. No windows open! (Remember, I'm new to Mac, OS programming and phidgets; I'm like a kid in Harrod's Toy Kingdom...)

First real stumbling block...

Xcode 2.1 is the version I have and the Phidgets documentation says:

The included examples are in XCode 2.1 format. If you can't open the project files, you probably need to upgrade, or you can create your own project and just add the sources. There are four Cocoa examples and one command line example. The cocoa built tools are included in the base examples folder.

I browsed to the Example folder which was still mounted under Volumes. There's a Phidget LED file there, a .app. Double clicking doesn't do anything and choosing it from File > Open in Xcode doesn't open anything either. Not even an error about supported formats. WTF?! Looking a bit further in the Examples folder we see CocoaLED.xcodeproj - I guess we will be using the mysterious Cocoa as well then! This does open in Xcode.

I went through the Phidget setup instructions once again to check I hadn't forgotten anything and I couldn't find the files that were meant to be in the systems folder. A search brought up an entry in the system crash log:

Library not loaded: /System/Library/Frameworks/Phidget20.framework/Versions/A/Phidget20
Referenced from: /Volumes/Phidgets/Examples/Phidget LED.app/Contents/MacOS/Phidget LED
Reason: image not found

That must have come from when I clicked that .app example. Back to installing the framework again.

Victory! One reboot and a cup of green tea with lemon later and I can actually run the example .app which shows a switchboard with tick boxes for the LED board. Ticking no. 14, the one I put a 3mm red LED in, actually makes it goes bright red! It doesn't look as if the brightness slider is working but that may well be due to my LED. What do I know?! It works so well, I can even flick it on and off in tune with the music now :)

All in all, that wasn't too hard. Just make sure the Phidgets framework installation was completed. Just use spotlight and search for 'phidget' and see if any matching files are in the System folder. Turns out Xcode wasn't even needed just yet. We'll leave that for the next episode. Now let me try my UV LEDs I got from LED1.de in Germany. Never thought I'd get so excited over such a little bit of light!

Now I've hooked up my 10x 3mm red LEDs, 10 x 3mm blue LEDs and 10x 3mm UV LEDs I realzie the Phidget LED only ships with extension cables for 32 LEDs whilst its capacity is 64. I also found one connection not working - not sure yet whether it's the cable or the board - it isn't the LED.

Here's a picture of the result:

It works, let's get coding!


Anonymous Mitch Cerroni said...

Finally someone who is going in depth about programming phidgets on a Mac. I too am diving into learning Xcode and objective-c to start doing cool projects with Phidgets. I have a website devoted to robotics developement on the Mac platform, so check it out. http://www.macbotics.com

January 22, 2006  
Blogger Johan said...


Thanks for dropping by. I signed up for your forum but Gmail is kicking up a fuss so when I get it activated I'll come and say hi.

You a VB coder then I guess?

January 23, 2006  

Post a Comment

Links to this post:

Create a Link

<< Home