Author Archive

98-all-your-atmel-belong-to-us

Foobarred is Normal

Recently I started using my linux laptop as my primary avr-usb development environment. When I upgraded the laptop to the current Ubuntu-LTS release (10.4 aka Lucid lynx) a bunch of stuff was broken including all of the wonderful udev rules provided by my linux savvy friends at dorkbotpdx.

I mean jeesh even lsusb was broken.

$ lsusb -vd "03eb:"|grep iM
cannot read device status, Operation not permitted (1)
iManufacturer           1

When I started looking at what changed and how to adjust, the web dead ended to a lot of threads like the one at http://ubuntuforums.org/showthread.php?t=1360412 ; where two people declared that having to escalate privileges to root in order to talk to a user device was “normal”. Even when the developer said it wasn’t normal the ubuntu folk redeclared it normal (apparently after Bush you just have to repeat something blatantly stupid for it to be true). As an administrator the last thing you want is everything and its dog requiring root privileges.

Hanging around the #ubuntu channel was a lot like having people repeat the searches on the web that provided me with the same dead ends that I joined the channel trying to resolve.

Cherchez la femme (look at the squeeze)

This was getting stupid. All I wanted to do was to have devices that I could plug in and program and then communicate with them using ruby or perl or some other haphazzardly thrown together scripts without having to be root. Then I realized once again that ubuntu is really focused on making the users life easier and that this leads to a lot of non technical help. So I asked my friends what the nick name was for the Debian release that was the basis for the Ubuntu release nick named “Lucid” and then re did all of my dead ended web queries replacing “Ubuntu Lucid” with “Debian Squeeze”.

The results were heavy on the technical detail and light on social skills.

More importantly I quickly found the solution that I needed in the middle of this link (http://git.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver?a=blob_plain&f=README&hb=HEAD) what I was missing was the difference between the new and the old udev rules.

“If you are running a newer version of udev (as in Debian Squeeze and
Ubuntu 9.10), you need to adapt the rules-file to the new udev-version:
sed -i -e ’s/TEMPNODE/tempnode/’ -e ’s/SYSFS/ATTRS/g’ -e ’s/BUS/SUBSYSTEMS/’ \
/etc/udev/rules.d/xusbdfwu.rules”

One line of sed was all I needed and it had taken me a week of asking about lucid when i should have been asking about squeeze. With this I also was able to find the changes to the lay out of the /dev and /proc trees and the new tools to monitor udev and diagnose issues.

All-Your-Atmel-Belong to Us

I really just wanted to change the permissions so I could use my devices. Adding the following udev rule to your system will do just that.  You will also need to restart the udev service. Both of these will require you to be root.

# cat >/etc/udev/rules.d/98-all-your-atmel-belong-to-us.rules<<EOF
#------------------------/etc/udev/rules.d/98-all-your-atmel-belong-to-us.rules
#
# Make atmel devices (dfu, LUFA, obdev) accessible in userland
# 
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", MODE="0666"
EOF
# service udev restart

To actually own all my atmel I could have also added ‘ ,USER=”don” ‘ after the mode part but I just wanted to talk my Atmel usb-avr devices and the open source firmware I was developing. And the above rule made things “just work”.

$ lsusb -vd "03eb:"|grep iM
iManufacturer           1 mycompany.com
$

This rule fixed all of my LUFA based devices including the my open source arduino programmer as well as the dfu programmer.used to code them. Hopefully it will be a while before I have to go through this again.

More Sinatra from the Ubuntu Folk.

I remember when the kids decided that they wanted to adapt the unnecessarily complicated system V init system and I kissed the simple days goodbye (sometimes I miss early bsd/freebsd and sometimes i miss it alot). Nowadays even the sysv-init isnt complicated enough. We gotta have upstart.

So after upgrading two systems to Lucid, I can tell you that most of the details have been well paid attention to, and a few problems we were having with 9.10 and hardy actually got solved. But there is still stuff that wasn’t broken that the kids just had to fix. So without further adeau I will tell you how to get gdm (and X) to go away after you have installed sysv-rc configured it to runlevel 3 (multiuser - no x) and its still there.

Setting the runtime.

If you have a working inittab the existing scripts will reference it so you can skip to how to get rid of gdm.

if you don’t you will find that the default runlevel is set to 2 (linux’s ‘user defined’ graphical runlevel since rc5 wasnt good enough for some reason) in /etc/init/rc-sysinit.conf. This should be changed to look like this.

# Default runlevel, this may be overriden on the kernel command-line
# or by faking an old /etc/inittab entry
env DEFAULT_RUNLEVEL=3

rebooting and typing “runlevel” should verify the change.

Why is gdm/X still running?

Beats the begebes out of me. But if you want it to stop you need to edit the /etc/init/gdm.conf and comment out the “start on” conditions and change them so that they correspond to the appropriate runlevel.

#start on (filesystem
#          and started dbus
#          and (graphics-device-added fb0 PRIMARY_DEVICE_FOR_DISPLAY=1
#               or drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
#               or stopped udevtrigger))
start on runlevel [24]
stop on runlevel [0136]

Grubby.

If you don’t want gdm/x you probably don’t want the splash junk either. While /boot/grub/menu.lst allows you to set default options like nosplash every kernel upgrade i have done in the past year explicitly asks for quiet and splash way out at the end of each “kernel” line so just plan on hand editing the darned thing after each kernel update. I am sure you can uninstall splash but I prefer configuring things to keeping track of what needs to be uninstalled for a system to run correctly.

Damned Kids.

Hope this saves you some of your precious hair. All and all lucid (server and desktop) seems pretty sane and stable but they are still fixing things whether or not they were broken.

Dont even get me started on last weeks apparmor configuration update busting our dns.

Reprogramming your avr-usb device using atmel’s built in bootloader

Getting code onto the MidiMonster or Benito device.

Midi Monster Button Locations.

Midi Monster Button Locations.
Benito 7g Switch Positions.

Benito 7g Switch Lcations
Benito 2010 Switch Locations

Benito 2010 Switch Locations
Benito Without Buttons.

Benito Without Buttons

All of the code on the Benito and MidiMonster devices is open source and references an open source library called the Lightweight Usb For Avr (lufa). Getting the code compiled and onto the device requires a few other open source tools.

AVR-GCC

The most current and stable release of the toochain for the AVR has untill recently been maintained by Eric Wedddington and released as WinAvr (http://sourceforge.net/projects/winavr/) Winaver integrates nicely into atmels avr studio http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=2725 and I reccomend that you get both if you are running windows. Each Winavr Release is closely followed by objective developments CrossPack for avr http://www.obdev.at/products/crosspack/index.html and a script for building the current toolchain on linux which is hosted by AvrFreaks at present there is also a debian package that was put out last month http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=90172

HWB? DFU?

Most Atmel “atmega” devices have a pin dedicated to determining whether or not the device goes into the bootloader depending on the devices flag settings. This pin is labled HWB (for hardware boot) on most of the datasheets. The usb avr family has this mode set up by default. When you hold the hwb pin low and reset the device it goes into the bootloader. On these devices the built in bootloader uses a usb device class called the Device Firmware Uploader (DFU). Atmel provides a tool called flip for programming DFU devices on windows and linux. There is an open source programmer called dfu-programmer http://dfu-programmer.sourceforge.net/

That other guys stuff.

Those of you who have worked with the teensy boards from paul stoffregon will notice some subtle differences. Paul wrote his own (closed source) bootloader rather than use the bootloader tha comes installed on the chips. Then he uses a hardware trick similar to the auto reset hack to make a single button manipulate both the reset and the hwb pins to put his boards into the bootloader. I didnt feel that either the two button arrangement or the builtin bootloaders were broken so I like most people working with these chips dont fix them.

Using the dfu-programmer

All of the programs in Dean Cameras Lightweight Usb for Avr have a “dfu” target. Once you have the target into the DFU mode you can simply

$make dfu

This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip. You can also do this manually with the following commands

$dfu-programmer atmega32u2 erase
$dfu-programmer atmega32u2 flash mycode.hex
$dfu-programmer atmega32u2 start

This will cause the dfu-programmer to erase the flash reprogramm it with a new hex file and restart the chip.

Acid Testing Your Time Machine Backups

Disks Die, Laptops break, Bags are Stolen.

It’s more or less a fact of life,

In the 4 year process of transitioning from a noisy sun E-250 in the garage to something that could actually be in the same room with you I arrived at the above network arrangement.

Most of the my data is hosted by a central server and when I had more systems all of the home directories were NFS mounted (which is a major PITA on OSX). In the last hear I have worked primarily on my MacBook, occasionally syncing my projects with the file server. After migrating to leopard I purchased a 1 Terabyte external disk and backed up both the file server and my laptop using “Time Machine”. As I worked more and more on the laptop I did less and less syncing of the work to the file server. The thing about time machine is that its thoughtless. Set it up and as long as you get your laptop home and leave it on for a few hours and it should keep your work safe for you.

Two weeks ago My Bag was stolen.

On top of the work I had actively been doing I lost two active sketchbooks and in the end this loss is probably the most painful. Since I couldn’t immediately restore the data using the process described below, I spent much of last week recreating the designs for this months workshops. Once the critical work was done I turned to see what I could recover. I had used time machine to restore a couple of files I had foobared but I had never had to restore all 270G of data and applications. My Intel Imac did not have enough disk nor did it have most of the software. So I bought a 1T disk from Old Town Computers and “CarbonCopyCloner“ed a bootable operating system onto it and put it into my Intel Imac (Ernesto).

WHERE’S MY BACKUP?!?

After googling around I found that I was supposed to restore my files using the “Migration Assistant” tool. I had used migration assistant to move users and applications to new systems but never to restore files. When I first tried the migration assistant I mounted the disk remotely but I couldn’t see the backup. So I moved the disk to the target machine. Even then I only saw the option of restoring the server and not my laptop.
Panic set in until I found a file named with my laptops name and a .sparsebundle extension. Right clicking on this lets me open it with the appropriate mounting utility. But…. Not until it had checked the file system. Walking away and doing something else for a few hours let me come back to the image mounted. When I ran the migration assistant again the option of restoring the laptop was there.

SUCCESS!

Starting the restore process and going to sleep I woke to find that it had successfully restored all of my data and applications! I was only out the extra time on the designs and the actual property.

FAIURE.

Now all of my active work was on a disk which was large enough to also contain the rest of my images/music/video and web content which had been kept on the file server. Since I could see the fileserver’s backup and I was so happy with my success I tried then to restore the file server data.

Mounting your home directories on external disks on OSX is a lot like mounting them remotely. It just plain sucks. Half the time if I made any changes in the disks connected to the file server it would mount them in a different place. Then when you logged in it would create a new mount point and empty directory and you could not remount the disk where it was supposed to be until you removed the new directory.

When I restored the file server user I had few options. I could restore the user (giving an estimated size of like 20 meg , not the  >400G I expected) and on the next screen I could restore the file system at the top level directory. This did not show me enough data to represent the data directory either. I could also have restored the entire system and then re-restored the Intel files over it but I really didn’t want to deal with the mess.

So I punted.

I just plugged the file server disk in and dragged my home folder to the new disk. I will probably test the restore process to the file server with the external disk attached to make sure the data is recoverable on that system. Once this is done I will reformat the time machine disk for future backups and send the file servers external disk to another state. In the mean time I will rest better knowing that my time machine backups actually work transparently while I work.

Postgres + Ruby + OSX=Multi Architectural Hell

I was finally able to get my ruby/rails environment setup with my database of choice.

It wasnt easy as postgres will not build with more than one architecture at a time, I had gone through similar hell the last time I tried to build anything on OSX that had to compile against libraries made for different architectures. Fortunately the solution was relatively simple.

My database is running 64 bit and I use it for many other applications that are compiled against either multiple architectures including 64bit but also some which are 64 bit only.

Ruby on the other hand is compled for 32 bit which worked flawlessly on mysql and most of the other gems i installed when I got to the postgres it puked in weird ways and when I tried every third solution on the net it was always the same.

Bash-3.2# gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

The bottom line from one of the only success stories that I found on the net was that you either built everything 64bit or nothing. Easy enough if you want to build all of your dependencies by yourself. The whole point of gems is to have the tools work for you. I wasnt really able to figure this out in the web full of people beating their heads on the same problem each harder than the other and each reaching the same it doesnt work conclusion but I had the fortune of getting completely away from the web long enough to realize that only the client and libraries needed to match the architecture and since all interaction between rails and the database went through a socket the architecture of the client didn’t have to be the same as the database.

so going back to my postgres source tree i did a

...postgresql-8.3.6# make distclean

and then reconfigured the database using the prefix /usr/local32

..postgresql-8.3.6# ARCHFLAGS='-arch i386' ./configure --prefix=/usr/local32/

Then I just had to tel ruby/gem to use the 32 bit libraries. Since ruby uses pg_config I made sure that the 32bit version is in the path first.

# PATH=/usr/local32/bin/:$PATH ARCHFLAGS='-arch i386' \
gem install pg  -- --with-pgsql-dir=/usr/local32/

And we are off but my god what at PITA.

Virtualizing the UCSF Cluster.

The computing cluster we maintain at uscf is built on a stock ubuntu hardy (desktop) with software added to it either to match the previous configuration or as needed by the experiments which are being conducted on the system. This decision was made as a compromise between the user community which was familiar with Ubuntu and the need for a stable (LTS) platform from an administration perspective. Since the hardware on the cluster is aging and reinstallation of systems requiring on site administration is expensive. We are evaluating alternatives such as the Amazon Elastic Cloud. This is an overview of an attempt to create a virtual instance of the servers used in the cluster. (The process is actually done twice since the head node is built on intrepid (desktop) because the processor configuration was not compatible with hardy’s install kernel.)

Out of hundreds of prebuilt images avaliable for the “Elastic Cloud” there are two sets of ec2 AMIs that closely match the platform that we are running. One is from alestic http://alestic.com/2009/04/official-ubuntu-ec2 and the other is a relatively new bundle from Ubuntu http://www.ubuntu.com/products/whatisubuntu/serveredition/features/ec2.

My initial attempt to create a package used the alestic desktop image. On top of taking more than 7 hours to merge the packages installed on the reference platform the result was completely unusable. Some of this was due to my not catching packages which did not work on ec2 such as grub and the kernel which was installed on the reference platform. Unlike VMware’s virtualization the amazon cloud is pretty particular about a few things. For this reason I found it prudent to start with systems which were native to the cloud and modify them.

The Ubuntu AMI advertises itself as “server” which is bare bones to the point of uselessness. Comparing the installed packages on the reference platform to the server left over 500 packages to sort through.
Fortunately the instantiated version allows you to install a set of packages which includes the desktop. This left us a delta of around 100 packages. Eliminating the packages that were not likely to work on the EC2 such as the standard kernel and grub resulted in less than 90 new packages to install.

Once I set up the ec2 tools and environment in accordance with amazons documentation http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/. I created an instance of the Ubuntu AMI (ami-5d59be34)

$ ec2-run-instances ami-5d59be34 -k n01-keypair
$ ec2-describe-instance (...wait until its running)
$ ssh -i id_rsa-furm-keypair ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com

With the basic instance installed you can  “sudo tasksel” and select Ubuntu desktop (in addition to the ssh server and any other appropriate packages). Once it completes the installation you can get a list of the installed packages and compare it to the packages on the reference platform and using aptitude install the additional packages. I use aptitude since it handles dependencies more ‘apt’ly than apt-get.

# dpkg --get-selections|grep install|cut -f1>ubuntu-intrepid-ec2.packages
# exit
$ exit
$ scp -i ~/.ssh/id_rsa-n01-keypair ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com:ubuntu-intrepid-ec2.packages .
$ dpkg --get-selections|grep install |cut -f1 >reference.package
$ diff ubuntu-intrepid-ec2.packages reference.packages |grep \>|sed 's/> //'>packages2add
$ nano packages2add <<<<<< delete linux* grub and any kernel packages.>>>>>>>
$ cp -i ~/.ssh/id_rsa-n01-keypair packages2add  ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com:.
$ ssh -i ~/.ssh/id_rsa-n01-keypair ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com
$ sudo bash
# for p in `cat packages2add` ; do echo $p;  aptitude -y install $p; done

At this point you should back check the new manifest and reboot the instance to make sure that you didn’t break anything before using your modified instance to create a new bundle. The ubuntu AMIs come with two disks defined by default / and /mnt which are close to the same size. you use /mnt to create an image. The process is convoluted at best. There is a pretty good description at http://alestic.com/2009/06/ec2-ami-bundle.

$ scp -i ~/.ssh/id_rsa-n01-keypair  *.pem ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com:.
cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem     100%  916     0.9KB/s   00:00
pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem       100%  922     0.9KB/s   00:00
$ ssh -i ~/.ssh/id_rsa-n01-keypair ubuntu@ec2-75-101-175-209.compute-1.amazonaws.com
$ sudo bash
# ec2-bundle-vol -r i386 -d/mnt -p ucsf-hardy-node \
-u XXXX-XXXX-XXXXX \
-k /home/ubuntu/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem \
-c /home/ubuntu/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem \
-s 10240 -e /mnt,/tmp,/root/.ssh,/home/ubuntu/.ssh
Copying / into the image file /mnt/ucsf-intrepid-head-node...
... <<<<<<< wait for a small eternity >>>>>>>
Bundling image file
... <<<<<<< wait for a nother small eternity >>>>>>>
Creating bundle manifest...
ec2-bundle-vol complete..
#ec2-upload-bundle  -b ucsfintrepid -m /mnt/ucsf-intrepid-head-node.manifest.xml   \
-a XXXXXXXXXXXXXXXX  -s XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Creating bucket...
Uploading bundled image parts to the S3 bucket ucsfintrepid ...
Uploaded ucsf-intrepid-head-node.part.000
...
Uploaded ucsf-intrepid-head-node.part.167
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.

Once this is done you have to register the bundle this is done from the local machine (reference).here.

$ ec2-register ucsfintrepid/ucsf-intrepid-head-node.manifest.xml
IMAGE    ami-f339d89a

Then you can test load it.

$ ec2-run-instances ami-f339d89a -k n01-keypair
$ ec2-describe-instances
...INSTANCE    i-af261cc6    ami-f339d89a    ec2-67-202-25-96.compute-1.amazonaws.com    domU-12-31-39-00-65-C8.compute-1.internal    running    n01-keypair    0        m1.small    2009-07-20T03:41:11+0000    us-east-1c    aki-714daa18    ari-6a5bbc03        monitoring-disabled
$ ssh -i ~/.ssh/id_rsa-n01-keypair  ubuntu@ec2-67-202-25-96.compute-1.amazonaws.com

If this is successfull you can terminate your original instances.

$ for i in `ec2-describe-instances |grep INSTANCE |cut -f2` ; do ec2-terminate-instances $i; done
INSTANCE    i-cd4f75a4    running    shutting-down
INSTANCE    i-af261cc6    running    shutting-down.

(This is important since amazon charges a nominal amount for each instance’s runtime ).

Reinventing the Wheel (watcher)

Its not very often that you get to go back to old designs and make improvements. Recently I got to rework a design from last year and build on the collective knowlege of 2 design teams and 3 design cycles.

Does practice make perfect? We shall see.

The first run.

Last year I got to build the electronics for a stationary bike racing system. The system had a large ballfield style clock with four hands that were run by these monster stepper motors The initial design was for two bikes done by Percor: a company that makes excercize equipment. Their design used these industrial (expensive and very bulky) cherry hall effect sensors which they loaned us for a race at Lance Armstrong’s bike shop in Austin (http://www.mellowjohnnys.com/). My job for that cycle was to replace Percor’s pic based board with a 4 bike setup.

I broke the stepper driver section into four individual boards. For the processor I built a custom mega128 based board and did the programming in wiring.

Second iteration.

When the Austin race was over Percor needed their parts back so I got to rebuild the sensors. I found some allegra hall effect sensors which were a small fraction of the cost of the cherry’s (like (75c<$25.00)X4). As an attempt to get a zero indicator on the clock I experimented with a triangle based design

While I never did get this particular part of the clock to work correctly the triange stuck as a shape that I liked working with.

I also wanted to replace the cat5 wire used in the Percor design with with less expensive phone cord. (I got a panicked phone call  from Texas and had to remotely direct someone how to get some very expensive ethernet cable on a weekend: it was not cool). To do this I put a non inverting buffer on the sensors and since buffers come in 6s I put an indicator led on the sensors output. In the practice of setting this up for the next race, the blinking lights were invaluable.

Third Time Charm.

A few weeks ago I was asked about another race setup in SanFrancisco. They were going to use a system called open sprints for the display but the open sprints people were out of their hardware for the sensors. So I got a 3 week timeline to put together a sensor and hardware interface that would be compatible with open sprints.

Open sprints (www.opensprints.org) is an open source ruby based software which takes information from an arduino and presents the race data in a way that can be projected instead of having a physical race clock. The only thing that needed to be built was the input side.

So I went back to what I liked and didn’t like about my earlier design and compared and contrasted the opensprints, the percor and my designs to come up with a new system which I could then have fabbed by our local pcb fab (sunstone.com). Looking at the opensprints design I revisited the hall effect sensors and found a set of sensors to experiment with and began to lay out my boards.

I had intended to use the dart design with a through hole led and a throuch hole (sip) sensor and then have some laser cut transparent plastic which could then be “lit” up by the led on the board. A second piece of opaque plastic would be cut to insulate the bottom of the board.

After talking to some of my ee freinds I decided to replace the on board drivers with a single schmidt trigger on the other end of the sensor cable (the percor design used these as well) When selecting the parts I found myself looking at a few options for the rj11 connectors. I ordered a few of each as well as both sip and the origional smt sensor from last year.

Who needs plastic?

When I got the parts I started looking at these rj11 connectors and rethinking things. The connectors were surface mount and shielded. The shielding wasn’t needed but they matched the un-soldermasked boards in texture in color they were about 7 cents more expensive apiece but they looked futuristic.

I went back to surface mount only. If I got rid of the sips and used the surface mount rj11 mounts then the bottom of the board would be shield/ground no insulation needed. The metal from the surface of the board and cable connector would reflect the light from the led and if any attention were payed to the layout of the traces it would look cool!

Even in the hand rolled prototype!

Who needs an Arduino?

At this point given Paul Stoffregon’s (pjrc.com) “teensyduino” software and his 90usb based boards there is no reason to buy any other arduino or arduino clone. ( at least in cases where you need usb to serial solution — in cases where usb-serial is not needed the dorkboard rules :) My first thought was to do a carrier board for on of Paul’s boards and adapt the opensprints code for the inverted inputs. The opensprints code needs to be adapted to invert the input signal and to adjust the registers for the different processor but using the teensyquino codebase that should be simple enough.
In this application however, the board was so simple that it made more sense to just adopt the eagle design for my at90usb162 board (the benito).

Tomorrow I get the boards from sunstone and I should have the hardware built out by late friday. The customer will be in portland saturday.

Does practice make perfect? We will let you know by next week.

Embedding Quartz Compositions in Cocoa Applications.

Yesterday I asked Greg Borenstein what he was using to do his really cool Arduino presentations to show the hardware alongside the code being used to program it. His answer suprised me. It was a simple Quartz Composition run using Composer. He used it to flip the views put out by his web cam so that they made sense from the users viewpoint. I have been seeing a lot of people using quartz composer to do testing and other cool graphic things.

An example I have been working with takes a camera that I had on a pole with a motor that moved it around like a periscope. The camera is sideways so the view has to be rotated. I did this by hand using Core Image this summer using filters and transforms but wanted to do it in Quartz Composer. The composition looks like this.

And the resulting image like this.

On the way down to UCSF last month I experimented with some code that embeds a quartz composition into an application.

You can download it from our svn repository ( https://ssl.tempusdictum.com/pubsvn/trunks/QuartzSnap/ add this url to your x-code scm repositories) and play with it. It builds into a standalone application.

Most all of the work is done by adding your composition to the xcode project and then placing a Quartz Composer View (QCView) from the objects library in your window using Interface builder. The only code I needed to make my application usable (to take pictures) was the action to save the view to a file.

——————————– CameraViewController.h —————————-


#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@interface CameraViewController : NSObject {

IBOutlet NSButton *SnapButton;
IBOutlet QCView *CameraView;
NSImage    *TheSnapShot;
NSData *theSnapData;

}
- (IBAction)DoSnapShot:(id)sender;
@end

——————————– CameraViewController.m —————————-


#import "CameraViewController.h"

@implementation CameraViewController

- (IBAction)DoSnapShot:(id)sender {
   theSnapData = [[CameraView snapshotImage] TIFFRepresentation];
   int runResult;
   NSSavePanel *sp = [NSSavePanel savePanel];
   [sp setCanSelectHiddenExtension:YES];
   [sp setRequiredFileType:@"tif"];
   runResult = [sp runModalForDirectory:nil file:nil];
   if (runResult == NSOKButton) {
     if (![theSnapData writeToFile:[sp filename] atomically:YES])
       NSLog(@”Well that didn’t work!”);
   }
}

@end

And that is pretty much it.

Compared to the several pages of code it took to get the same results using Core Image this was a snap.

3 ways to 3 volts

I have a few devices that I need to interface to either the benito or another avr board that run at 3.3v. one is an ethernet interface, one is a bluetooth modem and then there are the x-bees.

One Way: Simple Voltage Divider.

When looking for interface examples for the xbee I found a site that started out with a circuit from maxstream and then once everything was working tried a resistor based voltage divider. This is how I got my first set of x-bees running via the ftdi chips.

One thing that this circuit didn’t do for me was to provide a decent pull-down for the reset. The 2 transistors on the right of this circuit are an attempt to do just that.

Another Way: Run everything at 3.3v

If you look at the datasheet for the atmega168 you will find the following diagram.

Looking at this you can see that 16mhz may or may not be in the operating range at 3.3v. But if you drop the crystal down to 8mhz you are good for sure. You may have to change a few things but it is doable.

The Ever Illusive Third: Buffers.

The idea of adding another layer at each interface between boards can have you asking for some Tzatziki and falafel to go with the PITA. There are buffers which are designed specifically for this. Many of the odd, many of them expensive. But there are also many families of buffer which are “tolerant” of a range of voltages outside of their supply. One of the buffers I checked out was the 74abt126 which is a tri state buffer. (I was looking at that because with the tristate buffers you can actually do a two way buffer by selecting the direction). I am not entirely certain that the 5v receive side is kosher with these.

The other buffers I am looking at with 5v tolerant i/o are the 74lvc125 and 74lvc126. These are 3.6v native parts with 5v “tolerant” io.

Since I ordered the wrong series of parts last group order I will have to wait a week to check this out.

See Also.

Practice 1, Theory 1

As part of getting the new workspace space I moved the toxins related to casting and circuit board fabrication out of my apartment. The theory being that the space is semi industrial.

So as a test of the new space I took one of Alex Normans board designs and etched it.

Since the last time I worked with Alex on his designs he has picked up quite a bit and I only spent about 10 minutes getting his eagle files layed out and printed before going to the office. When I got there I realized that I had forgotten the green trf and bon ami but we were still able to get a reasonable etch and the new space has been broken in on the practice side.

Testing the Atmel Mega32U4

Mega 32 U4

While I am wrangling with the appropriate board design, I needed to get started working with the underlying software so I ran up one of the six samples I was able to get from Cascade on a tqfp adapter from measure explorer.

Schematic For Test Board

The AtMega32U4 http://www.atmel.com/dyn/products/product_card.asp?part_id=4317 is the midrange model in the atmel usb chipset. It follows a new standard naming convention that atmel is adapting U for Usb 4 is for the 40 pins 32k, there is another 32K part the U6 which has the same pinouts as the 90usb646/647/1286/1287. The U4 does not have a legacy pinout however the q1000 price for this board is around $2 which makes it a very powerful chip for the money.

Dfu-Programmer.

There is a recent release of dfu-programmer (0.4.6) but it seems that they havent read the atmel doc on the signatures for the dfu recently. http://www.atmel.com/dyn/resources/prod_documents/doc7618.pdf recently.

I need to check the memory and eeprom sizes against the datasheets for the parts. However the table in arguments.c should have the following entries; added new parts, corrected 64x and 82 signatures. (I will resubmit this patch).

/* ----- target specific structures ----------------------------------------- */
/*  { "name",         value,            ,device_type, chipID,VID   , MemSize,FPSize,abt,ifclass,eepgsz,eepmemsz} */
static struct target_mapping_structure target_map[] = {
    { “at89c51snd1c”, tar_at89c51snd1c, device_8051, 0×2FFF, 0×03eb, 0×10000, 128, false, true,  0,   0      },
    { “at89c5130″,    tar_at89c5130,    device_8051, 0×2FFD, 0×03eb, 0×04000, 128, false, true,  128, 0×03FF },
    { “at89c5131″,    tar_at89c5131,    device_8051, 0×2FFD, 0×03eb, 0×08000, 128, false, true,  128, 0×03FF },
    { “at89c5132″,    tar_at89c5132,    device_8051, 0×2FFF, 0×03eb, 0×10000, 128, false, true,  0,   0      },
    { “at90usb1287″,  tar_at90usb1287,  device_AVR,  0×2FFB, 0×03eb, 0×1F000, 128, true,  false, 128, 0×0FFF },
    { “at90usb1286″,  tar_at90usb1286,  device_AVR,  0×2FFB, 0×03eb, 0×1F000, 128, true,  false, 128, 0×0FFF },
    { “at90usb647″,   tar_at90usb647,   device_AVR,  0×2FF9, 0×03eb, 0×0F000, 128, true,  false, 128, 0×07FF },
    { “at90usb646″,   tar_at90usb646,   device_AVR,  0×2FF9, 0×03eb, 0×0F000, 128, true,  false, 128, 0×07FF },
    { “atmega32U6″,   tar_atMega32u6,   device_AVR,  0×2FFB, 0×03eb, 0×07000, 128, true,  false, 128, 0×03FF },
    { “atmega32U4″,   tar_atMega32u4,   device_AVR,  0×2FF4, 0×03eb, 0×07000, 128, true,  false, 128, 0×03FF },
    { “atmega16U4″,   tar_atMega16u4,   device_AVR,  0×2FF3, 0×03eb, 0×03000, 128, true,  false, 128, 0×01FF },
    { “at90usb162″,   tar_at90usb162,   device_AVR,  0×2FFA, 0×03eb, 0×03000, 128, true,  false, 128, 0×01FF },
    { “at90usb82″,    tar_at90usb82,    device_AVR,  0×2FF7, 0×03eb, 0×01000, 128, true,  false, 128, 0×01FF },
    { NULL }
};

Then we test.

static
dfu-programmer atMega32U4 get bootloader-version --debug 20
     target: atMega32U4
    chip_id: 0x2ff4
  vendor_id: 0x03eb
    command: get
      quiet: false
      debug: 20
device_type: AVR
------ command specific below ------
       name: 0

Bootloader Version: 0x00 (0)

(after reading the datasheets for the 3 classes of avr usb chips and looking at the way that the avr-gcc library calls the cpu names there are some changes to the above that I will post later.)

Next up some code.

Tried running up the midiGate software that I wrote last week and found my first bug for the chip in avr-libc

UBRR1 is redefined in iom32u4.h

#define UBRR1 _SFR_MEM16(0xCC)

#define UBRR1L _SFR_MEM8(0xCC)
#define UBRR0 0
#define UBRR1 1
...

Which results in lvalue errors errors when trying to set the register to a given value. Setting the bit values as in some of the other registers seems to resolve this issue.

#define UBRR1 _SFR_MEM16(0xCC)

#define UBRR1L _SFR_MEM8(0xCC)
#define UBRR_0 0
#define UBRR_1 1
#define UBRR_2 2
#define UBRR_3 3
#define UBRR_4 4
#define UBRR_5 5
#define UBRR_6 6
#define UBRR_7 7

#define UBRR1H _SFR_MEM8(0xCD)
#define UBRR_8 0
#define UBRR_9 1
#define UBRR_10 2
#define UBRR_11 3

This is a pretty braindead error so I am sure that its been resolved by now. I need to see if it is fixed in 1.6.3 or the current release candidate (since AvrMacPack is out of sync and has 1.6.2) And yes this is the case.

We have a device!!!

Fix(ing) it!

Both of these issues were easy enough to fix within the source of the utilities but to make it possible for everyone else to use the new chips some body needs to Fix it! So I went about looking up the chain to get these issues resolved over the long run.

Dfu Programmer.

dfu-programmer is a source forge project so I logged an error through the sourceforge project page. https://sourceforge.net/tracker2/?atid=767783&group_id=147246&func=browse A new release has been made (0.5.0) which resolves the issue above.

Avr-Libc

Since avr-libc is a savanaha project and so making bug requests is a little different. http://savannah.nongnu.org/bugs/?group=avr-libc Fortunately (sort of) I had already been around the buggier parts of the release in question (1.6.2) when I first ran up the at90usb647. When Eric Weddington released the June rev of WinAvr (with avr-libc 1.6.3) I thought I had seen the last of it as obdev released the coresponding AvrMacPack. The bug noted above was fixed in 1.6.3 and I was able to verify that using my windows vmware session. For some reason this was not the case and AvrMacPack went out with the buggy (for this new chip anyway) libc. I filed a bug report with obdev and followed up with Christian from obdev and Eric until the version descrepency was resolved. The new version of WinAvr just came out and I am waiting to verify that the AvrMacPack version matches WinAvr.

If you are running linux plan on building from source and patching as in the script kept current at avrfreaks (you will need to log in) . http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=42631&start=0&postdays=0&postorder=asc&highlight= This script has not been updated for the latest winavr but it should at least give you a version above 1.6.2.

Is it me or does that look like a target?

http://www.gearthblog.com/blog/archives/2008/10/google_earth_for_the_iphone_release.html

Note the dorkboard….

Ethan and his dad came to the first dorkboard based induction. This is one of his recent projects.

http://etharooni.wordpress.com/2008/09/21/nunchucklogger/

Very cool stuff.

Our first reseller.

Brian Reilly at Wulfden picked up the dorkboard in his freeduino line of products.

http://wulfden.org/TheShoppe/freeduino/dorkboard.shtml

Yeah!

Local Induction.

NDA-ROX

I just spent the weekend with a few people who knew a lot more about programming the iphone than I did and several people that knew about as much as I did. I can tell you that the Portland group got the best of satellite category for our collectively built app.

(If you look behind the sf group you can see the Portland and Seattle groups in the background)

But given Apple’s NDA I can’t tell you much else.

Rapha Race Controller

Rapha Sportswear has a stationary race controller prototype that they need replicated for an event next week. The first step int this process was to break out the original design into 3 boards one for input processing one for the stepper drivers and one for the processor itself. Since the customer wanted to be able to modify the code themselves in the future and expand the system an Arduino or Wiring compatible board will be used.

(The completed project)

Motor Boards

The motor boards consisted of 4 darlington transistors on the best performing heat sinks I could find.

The I/O - Processor Board.

The I/O Processor board consisted of to schmidt triggers to clean up the input and a usb to serial connection for programming and future use. The board also has 3 free ports for future use.

Happy Birthday to Me!

I am old. I won’t say how old exactly but I am half way through a few experiments. Life, work.

It makes me very happy that three of these experiments will be funded as Tempus Dictum Projects.

  1. The Dorkboard.

  2. The Benito Serial Programmer

  3. The Arduino Cult Induction Series.
    (Next Induction Sunday June 22)

I would like to thank Tempus Dictum for the opportunity to work on these items.

I am a very lucky man.

Write Locally Post Globally

I like wordpress.

It allows me to do much of what I post on the web without having to look at the underlying html and still letting me at the html. In fact I use WordPress to to post on Dorkbots Drupal pages. It is easier than hand rolling html and the new wordpress saves your drafts. This is no small issue: As I was reminded at 2:30 monday morning as Drupal timed out the session that I was writing on and ate my post. Between that and the Eagle files I was working with I lost most of sunday nights sleep. The other issue is portability.  So last night I ran up mysql, unpacked the latest wordpress into my home directory and reconfigured the apache daemon that comes with leopard.

I plan to get more done and loose less sleep.

The Really Really Bare Bones Arduino

This has been reposted on dorkbotpdx.org

A few weeks ago I bought the last of the Really Bare Bones Arduino rev A boards from Brian at Wulfden (http://wulfden.org/freeduino/freeduino.shtml) I now have enough boards for one more workshop and then we have to reevaluate the boards which are avaliable. Pictured below is a finished board from the first “Arduino Cult Induction Workshop”

In addition to letting me clean out his new old stock Brian threw in one of the “Rev B” boards so I could check it out. Unfortunately I don’t like it.

The new board is almost 3/4″ of an inch longer than the original. Most of the new space is dedicated to room for a power jack and a regulator. Things that I never use. The design is supposed to allow you to cut the power jack off as well as the regulator. Notice in the finished board above that their is space for a big old reset switch. When the original Arduino came out you had to reset the board to get it into the bootloader. However in the past year or so all the new boards have been using the dtr signal run through a capacitor to pull the reset line so the switch is wasted space. The original board made up for this space by adding ample ground and supply connections. The new board adds another 1/8″ and gets rid of these.

As I was grumbling about this Mark Gross suggested that I just roll my own.

So we are back to the drawing board. Above is my pen markup of the changes that I wanted to see done to the original Really Bare Bones Arduino and below is the draft of the rework to scale with the RBBB rev B.

Now comes the fun part The cost of goods sold and a business case.

Return top