Archive for June, 2009

Mac OS X Compilation for Heyu Home Automation

Heyu, Home Automation, Mac OS Xon June 26th, 2009Comments Off

I suppose this will be much like my last post. If you don’t know much about Heyu, this is from the main website:

HEYU is a text-based console program for remotely controlling lights and appliances in the home or office. The complete source is made available under the free Heyu License.

Heyu uses the CM11A computer interface to send and receive X10 control signals over the AC power lines to modules which can turn On, Off, or Dim attached lamps or appliances. It can store a schedule of timed events in the CM11A memory for execution when the computer is turned off or disconnected.

Now it is written for Linux, and that worked for me for a long time. However, I want to be able to create a GUI and use my most familiar programming environment of Xcode and Mac OS X.

Unless my search skills are horrible, it takes a looooong time to find instructions on how to compile the Heyu libraries for Mac OS X and get it up and running. I finally found some stuff from 2002, and I will share my newfound knowledge here so that it can spread on the interwebs.

First, you need a USB to Serial adapter. Sorry. They are probably $15, but cheaper ones must exist. Next, you need to discover where OS X thinks the adapter is. Open up Terminal and type:

cd /dev
ls

This should show a whole bunch of stuff. Ignore the tty* stuff and look for something that sounds like our adapter. My terminal shows an item called cu.usbserial. Perfect! So write down (or remember) the location.

Download Heyu from the website linked above. ‘cd’ into the downloaded directory and type:

./Configure freebsd

Mac OS X has a Unix base built upon freeBSD, so this creates a makefile perfect for OS X. Even though it says “now run make as a normal user,” there’s one last change left. Edit the x10.h file (I just use ‘pico’ in the Terminal) and perform the following:

change

#else
#define LOCKDIR “/var/lock”
#endif

to

#else
#define LOCKDIR “/tmp”
#endif

Now go ahead and run ‘make’. Heyu will guide you through the rest of the install. At some point you ’sudo make install’ and give and option of where the config file should live. I chose the home directory so I could have easy access to it. (It will be a hidden directory so access through Terminal with ls -a). Also at some point, you’ll be asked to give the address of the CM11a interface, which you’ve connected to your USB to Serial port by now. Give it the location we found earlier. For what I found, this was ‘/dev/cu.usbserial’.

After the ’sudo make install’ everything is ready to go! You can use the standard Heyu command set. Here are a few to get you started.

heyu start
heyu info
heyu on a1
heyu dim a1 10

My next Heyu post will discuss how to execute shell scripts and commands from an Xcode project using NSTask.


OpenCV and Xcode

Uncategorizedon June 26th, 2009Comments Off

OpenCV is really awesome. I’ve been using the library extensively in my summer research. For those who don’t know what OpenCV is, this is from the main website:

OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real time computer vision.

Example applications of the OpenCV library are Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Motion Tracking, Ego Motion, Motion Understanding; Structure From Motion (SFM); Stereo and Multi-Camera Calibration and Depth Computation; Mobile Robotics.

Cameo – Reid Draper: roommate and programmer extraordinaire.

I wasted a lot of time trying to get the library to compile on OS X. Don’t make the same mistake! Download the pre-compiled Universal Binary from this site. Currently, it is version 1.2, but a huge 2.0 release is coming in August.

Back to the framework. Don’t waste your time try to add build phases and whatnot. I never managed to get that to work. Just copy OpenCV.framwork to /Library/Frameworks. Do not add it to ~/Library/Frameworks, but the root Library.

After that, when adding “existing framework to application” just navigate to it. Everything will link just fine. Now, do something awesome.


Arduino to Mac OS X Serial Communication

Uncategorizedon June 1st, 2009Comments Off

I ran into a snag when trying to get an xcode project to talk to an Arduino in April. After a bit of researching, I finally got things working with AMSerialPort from Andreas Mayer. I had to tweak it a bit…the method to change the baud rate didn’t work at first, but it’s fixed now. Also, the part of AMSerialPort that waits in the background thread for incoming data was modified a bit to play nice with Arduino serial messages. I re-packaged everything into a new Xcode project with a simple interface that let’s a user select an attached serial device and then send messages to it as well. My code has the incoming messages just go straight to the console instead of being displayed in the view. I could have done otherwise, but each implementation of this will require vastly different interfaces when completed. I know that I will never need to display the incoming messages on the screen, so I didn’t bother.

The modification the background-thread-waiting is by my design. It waits for a newline character, or more specifically, a serial message that is sent with

Serial.println()

So Serial.print() can be used several times without the Xcode project reporting any incoming data. What it is really doing is storing up the data until a newline character. Just end your bout of serial messages with a Serial.println() for the message to come through to the console. If you’d prefer every message to come through, just always use Serial.println().

The project is hosted here on Google Code.


Arduino Mega

Uncategorizedon June 1st, 2009Comments Off

It’s been a while since my last post, but now the semester is over and my summer schedule is in full swing. I just had to express my joy at the release of the Arduino Mega. For some reason, I’m still scared to enter into the realm of AVR and ARM, so I’ll stick with the Arduino for now.

I actually already have my hands on one from Sparkfun. It’s absolutely sensational. No longer do I have to worry about running out of analog ports.