Blog Archive

Wednesday 27 February 2008

UBW USB Whacker under ubuntu linux

I recently bought one of these, a "UBW USB Whacker".
It will allow me to control all sorts of fun things from my PC, much in the same way as my parallel port home automation experiment. Brian Schmalz, the inventor, explains far better than I, what it does on his site:
The UBW board is a small board that contains a Microchip PIC USB-capable microcontroller, headers to bring out all of the PICs signal lines (to a breadboard for example), only costs about $15-$20 to build and is powered from the USB connection.
Also on Brian's site are several explanations on how to use this gadget with Windows and Liberty BASIC. I don't want to use it under Windows, so here are a few first pointers to using it under Linux, specifically the flavour I run , Ubuntu 7.10:

Step 1 : Just plug it in. It should appear at /dev/ttyACM0 or /dev/ttyACM1 - go take a look.
Step 2: Create a symbolic link from /dev/ttyS3 to /dev/ttyACM0 so gtkterm can talk to it.
Step 3: Run up gtkterm, connect to /dev/ttyS3 and type "V" without the quotes and press ENTER. You should get something back along the lines of: "UBW FW D Version 1.4.1". This shows everything is working.
Step 4: I wanted to run something in a programming language, and as I am quite familiar with PHP, I got hold of this class for talking to serial devices.
Step 5: The following code in conjunction with the above class allowed me to do the same thing from within a PHP program as I did from within gtkterm:

<?php
include "php_serial.class.php";

// Let's start the class
$serial = new phpSerial;

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyS3");

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("V\n");

// Or to read from
$read = $serial->readPort();
echo "output : \n $read \n";

// If you want to change the configuration, the device must be closed
$serial->deviceClose();

?>


That's it for now. Look on the UBW home page for more information on the commands you need to send to the device to make it do stuff. I'll post more interesting stuff when I've learnt how!