Using an Arduino Serial USB board with an Ardweeny

January 30, 2011

This afternoon I joined the world of Arduino hacking. I put together an Ardweeny and hooked it up to an Arduino Serial USB Board. I probably should have used a newer FTDI basic breakout board which supports auto-reset, but I didn’t.

Assembly and Power Up

Putting the Ardweeny together was pretty simple. One word of advice: you do not want to do this without a third hand tool. Even that won’t be enough for soldering the chip onto the headers – you’ll need a friend or some good gentle alligator clips to hold the chip while you do the first tack solders.

I powered it up by connecting +5v of the Ardweeny to +5v of the Serial USB board, and then connecting Gnd on the Ardweeny to Gnd on the Serial USB board. It started blinking right away – always a good sign.

Connecting to USB Serial

Connecting the Ardweeny to the Serial USB board was a little trickier. I used a pair of jumper wires. In one end of each one I stuffed a little clipping of 22 awg bell wire, so I had a female connector at one end and a male connector at the other.

Next, the big (and as far as I can tell undocumented) question: does TX on the Serial USB board go to RX on the Ardweeny and vice versa, or does TX on the Serial USB board go straight to TX on the Ardweeny? The answer:

TX on the Serial USB board (the pin furthest from Gnd on the left side) goes to RXI (the pin above A4 on the Ardweeny v1.1a)

RX on the Serial USB board (the pin just above +5v on the left side) goes to TXO (the pin above A3 on the Ardweeny v1.1a)

I hooked those up backwards and my USB port stopped recognizing the Serial USB board. I had to pull the Serial USB board from the USB hub and plug it back in to continue. (I’m doing all of this through a powered USB hub just to avoid burning out my motherboard’s USB if I make a mistake.)

Downloading Code

Once I’d done that, I sent a program down. The first program went with no problems after I set my COM port and chose the “Arudino Duemilanove or Nano w/ATmega 328”.

Subsequent programs wouldn’t write – I got the following error:

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

It turns out the Ardweeny is pretty particular about when things get uploaded to it. (This is where the auto-reset function of the FTDI basic breakout board shines, but I didn’t know that since I’d never done Arduino programming before.) So the magic trick to upload is to wait until you see:

Binary sketch size: 1018 bytes (of a 30720 byte maximum)

in the IDE, then immediately hit the reset button on the Ardweeny. At that point, you’ll see the TX and RX LEDs flash on the USB Serial board, and your code should be uploaded.

Configuring a website on Apache2 with server-side includes

January 22, 2011

I recently got myself involved in helping with a website for a local club. In order to maintain it, I wanted to set up an Apache instance at home as well.

Luckily, in Ubuntu 9.10, it’s almost all set up by default. The only changes I had to make were to change the DocumentRoot directory and enable server-side includes. Here’s what I did:

Changing the document root

First I edited /etc/apache2/sites-available/default to put my document root in DocumentRoot, and also changed the two directory references that did point to /var/www to my new document root. Then I made sure all the parents of my document root had r+x permission for the Apache user.

Turning on server-side includes

My hosting facility has server-side includes turned on for .html. This is not the best use of resources, but this website doesn’t get enough traffic to make a difference. So I added:

AddType text/html .html
AddHandler server-parsed .html
Option Include (plus whatever options were there before)

to the two directories that used to be /var/www and /. After that, I had to enable mod_include with:

cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/include.load include.load

Then restart apache with sudo /etc/init.d/apache2 restart

Resolving git error: unable to create temporary sha1 filename

January 11, 2011

I’m just starting to use git for source control. Tonight I got an error when I tried to commit:

$ git add ./foo/bar/
error: unable to create temporary sha1 filename .git/objects/95: File exists

error: foo/bar/baz: failed to insert into database

Luckily, someone else ran into this before me. The magic incantation:

git fsck
git prune
git repack
git fsck

and then I was able to add my files.

I ran into another case where this didn’t help. In that instance,

git gc

was able to get me committing again.

Inserting current date and time with EMACS

January 10, 2011

I was recently involved in an activity that required keeping track of notes with timestamps. I decided to do it in EMACS. Here’s what I stuffed in my .emacs init file:

;; Insert the current time in the current buffer
        ; If you want to insert date and time, you can use:
        (insert(format-time-string "%Y-%m-%d %H:%M:%S ")))
;; Bind Ctrl-T ("transpose") to the timestamp function - need a better key binding
(global-set-key (kbd "C-t") 'timestamp)

Incidentally, I also needed to save the file to DOS format instead of Unix format. To do that:

M-x set-buffer-file-coding-system

then use “dos” (or “mac” or “unix”).

Installing the Brother MFC 9840cdw driver on Ubuntu

January 2, 2011

When I had Ubuntu 8.04, I’d struggled my way through installing the official Brother driver from the Brother Linux site.

Since then I’ve upgraded a couple of times to 9.10, and had not reinstalled my printer. It turns out Ubuntu has made life much easier for us Brother printer owners – so these days there’s no reason not to install the printer driver, especially if the printer is networked.

Here’s how to do it:

  1. Open Synaptic Package Manager
  2. Search for 9840. You should see two packages:
  3. Select those for installation (along with their required packages).
  4. Go to System->Administration->Printing and press the “New Printer” button.
  5. After a “Search for new printers” message comes up and goes away, expand “Network Printers”.
  6. If you’re lucky like me, you’ll see your printer there. I chose to use the one that was found by IP address (LPD Network Printer via DNS-SD).
  7. Then I printed a test page, which shot a bunch of colour toner out. (If I had to do it over again, I would have just printed from Firefox to save toner.)
  8. Finally, I did System->Preferences->Default Printer to set the new printer as the default.

That does the printer; next you’ll want the scanner. This isn’t quite as straightforward, since the scanner stuff isn’t in Synaptic. Again I’m assuming it’s set up on a network:

  1. Make sure you’ve already installed xsane and its requirements.
  2. Download the .deb for brscan3 from the Brother web site. If you’re like me, you want the 32-bit version.
  3. Install the driver with:
    $ sudo dpkg  -i  --force-all brscan3-0.2.11-2.i386.deb
  4. Configure the scanner:
    $ brsaneconfig3 -a name=SCANNER model=MFC-9840CDW ip=aaa.bbb.ccc.ddd

    (where aaa.bbb.ccc.ddd is your MFC-9840’s IP address).

  5. Verify the driver installed:
    $ brsaneconfig3 -q | grep SCANNER
      0 SCANNER             "MFC-9840CDW"       I:aaa.bbb.ccc.ddd
  6. Run xsane and it should find the scanner.

Creating thumbnail images with convert

January 1, 2011

A little while ago, I found I had a bunch of images that needed thumbnails that were 100×75. This isn’t hard to do – I used convert and a pair of bash for loops.

The core was a call to convert, which is part of ImageMagick.

convert -thumbnail 100x75 input.jpg thumbnail.jpg

All of my images happened to be 4:3 – if they hadn’t, I might have used 100x75! or rotated/resized them.

Next, all my files had numbers of the form file01..file09 file10 file11… etc. If you’re nuts, you try to figure out how to do this in a single for-loop with a condition for the first 9 elements that start with 0.

If you’re lazy like me, you use two loops, with a cursor-up in bash so you don’t have to type as much:

export INFILEPREFIX=file
for i in {1..9}; do convert -thumbnail 100x75 ${INFILEPREFIX}0${i}.jpg ${OUTFILEPREFIX}0${i}t.jpg; done
for i in {10..25}; do convert -thumbnail 100x75 ${INFILEPREFIX}${i}.jpg ${OUTFILEPREFIX}${i}t.jpg; done

For the non-thumbnails, I resized as well, using -resize 800×600.

Scale your website images

January 1, 2011

I just noticed that if you scale an image using width= and height= attributes of the img tag, Firefox 3.6 will (sometimes) put a thin border on the top and left of the image – something that you can’t get rid of with CSS/styling.

Weird – but a good rule seems to be scale your images to the correct size before using them in HTML.

This is different from the “border around link images” issue – which is easy enough to get around by using
border-style: none in CSS.