Relation between motor’s torque/speed and its voltage/current.

2010 January 23
by David
  1. The torque of a motor is proportional to the current flowing through it (\tau \propto i).
  2. The angular velocity of a motor is proportional to the voltage across it (\omega \propto v).

Details and derivation here: motor.pdf.

Wacom Jitter Fix (for Linux)

2010 January 1
by David

My Wacom Bamboo Fun tablet has been exceptionally jittery on my Lenovo ThinkPad T500. I assume this is probably caused by EM noise (though I’m not sure). Today I decided I should try to fix that.

Here’s an image to demonstrate the problem (click to enlarge):
lines1

On Ubuntu, there’s a package called wacom-tools that includes a configuration utility named xsetwacom. The xsetwacom utility has a couple parameters to help against noise: RawSample and Suppress. RawSample allows you to adjust the number of samples taken from the tablet before the coordinates are committed to the mouse pointer on screen. Suppress prevents the mouse pointer from moving unless it has been moved by a given amount. So, all you need to do is tune those parameters to something that works well for your setup. I found the following to be acceptable:

xsetwacom set "Wacom BambooFun 4x5" RawSample 9
xsetwacom set "Wacom BambooFun 4x5" Suppress 10

Note that those commands are specifically for the Wacom BambooFun 4×5 tablet. You will probably need to replace that part with something else. You can find out what you should replace it with by executing this command and looking over its output:

xidump --list

Now, I wanted these commands to be run automatically every time I logged in, so I created a small script at ~/.local/bin/wacom_init and put the following in it:

#!/bin/sh
xsetwacom set "Wacom BambooFun 4x5" RawSample 9
xsetwacom set "Wacom BambooFun 4x5" Suppress 10

Finally, I went in my menu to System > Preferences > Startup Applications and created an entry to automatically run the command /home/david/.local/bin/wacom_init.

All done!

Python/Unix Calculator

2010 January 1
by David
david@second:~$ cat /home/david/.local/bin/=
#!/usr/bin/env python
__import__("sys").argv[1:] and __import__("subprocess").Popen(("bc","-lq"),↵
stdin=__import__("subprocess").PIPE).communicate(" ".join(__import__("sys")↵
.argv[1:]+["\n"])) or __import__("os").waitpid(__import__("subprocess")↵
.Popen(("bc","-lq")).pid,0)
david@second:~$ = '5*5 + 5'
30
david@second:~$ =
3+1
4
last*2
8
david@second:~$

Wait… what?

DIY aux input on Alpine car stereo (M-BUS)

2010 January 1
by David

If anything in this article is unclear or confusing, please let me know in the comments and I’ll do my best to clarify.

Disclaimer: by following the instructions below, you may end up destroying your stereo, car, MP3 player, interpersonal relationships, and everything else you hold dear. I am not responsible for any of this. That being said, it worked fine for me.

This method will work on any Alpine stereos with an 8-pin M-BUS connector in the back. (The stereo I performed this on was an Alpine CDM-9821.) The connector itself should look something like this:
2dj-0108psa2

After some searching around, I located the functions of each pin on this connector at pinouts.ru. The pins on interest are the bottom three:
2dj-0108psa2asdfasdf

This corresponds perfectly with the contacts on a 3.5mm headphone plug:
ak203mm

So all that’s left to do is make an adapter between the two. I ordered these parts from Digi-Key: CP-1080-ND, AE9918-ND, and CP1-3513-ND.

Gather up some solder, a soldering iron, and wire. Make the following connections:

  1. “Audio Ground” pin from the M-BUS connector goes to the pin closest to the hole on the 3.5mm audio jack
  2. “Right Audio Input” goes to the pin farthest from the hole
  3. “Left Audio Input” goes to the only remaining pin.

You should end up with an adapter cable like this:
sj1-3513

Plug the M-BUS connector into the back of your stereo and mount the audio jack somewhere on the dash.

Now turn on your car. If all went well, nothing will start on fire. Hold the “Setup” button on the stereo and enable aux input in the menu. Now hit the “Source” button until you get to AUX. Plug in your MP3 player and crank it.

SparkFun’s FTDI Basic Breakout as an AVR programmer

2009 December 20
by David

screenshot1

Start by following my instructions for setting up AVRDUDE 5.8 with FTDI bitbanging support.

Now open up avrdude.conf in a text editor. Add this entry by the other programmers:

# FTDI basic breakout
programmer
  id = "ftdi";
  desc = "FTDI Basic Breakout";
  type = ft245r;
  miso = 1; # RxD
  sck = 3; # CTS
  mosi = 0; # TxD
  reset = 4; # DTR
;

Now you can attach your FTDI Breakout to the target AVR like this:
FTDI -> MCU (ATmega168 PDIP pin)
DTR -> RESET (1)
RXI -> MISO (18)
TXO -> MOSI (17)
5V -> VCC (7 & 20)
CTS -> SCK (19)
GND -> GND (8 & 22)

With the 3×2 ISCP header on the Arduino, that would look like this:

        +----------------+
[RXI]--o| 1 MISO   +5V 2 |o--[5V]
[CTS]--o| 3 SCK   MOSI 4 |o--[TXO]
[DTR]--o| 5 RESET  GND 6 |o--[GND]
        +----------------+

Note that may need to supply the AVR with an external oscillator or clock source. For virgin ATmega168s, you won’t need to (because it initially uses the internal oscillator), but you’ll need an external crystal oscillator if you’re using one that came out of an Arduino.

From there you can use AVRDUDE like normal using the `-c ftdi` switch. For example, to read fuse bytes:

sudo ./avrdude -C avrdude.conf -c ftdi -p m168 -P ft0 -U hfuse:r:-:h -U lfuse:r:-:h -U efuse:r:-:h

AVRDUDE 5.8 with FTDI bitbang patch on Linux

2009 December 20
by David

Description: This is an adaptation of the work by Kimio Kosaka, Nate Phillips, and Massimo. It allows you to use AVRDUDE with an FTDI chip (like the one on the Arduino boards or SparkFun’s FTDI Basic Breakout). This can be useful if you manage to brick your Arduino and you have no programmer.

—————————

If you’re on Ubuntu or Debian, install the prerequisites with:

sudo apt-get install patch build-essential libreadline-dev libncurses-dev libusb-dev
sudo apt-get build-dep avrdude avrdude-doc

Start by grabbing a copy of AVRDUDE 5.8, untarring it in the directory, and switching to that directory:

wget http://download.savannah.gnu.org/releases-noredirect/avrdude/avrdude-5.8.tar.gz
tar xzf avrdude-5.8.tar.gz
cd avrdude-5.8

Now get a copy of the FTDI bitbang patch files:

for i in 8 7 6 5 4 3 2 1 0; do wget -O patch-$i.diff http://savannah.nongnu.org/patch/download.php?file_id=1851$i; done

Apply the patches:

for file in patch-*.diff; do patch -p0 < $file; done

Also get a copy of the FTDI driver. For 32-bit:

wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx0.4.16.tar.gz

For 64-bit:

wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx0.4.16_x86_64.tar.gz

Extract the FTDI driver and copy over the needed files:

tar xzf libftd2xx*.tar.gz
cp libftd2xx*/static_lib/* .
cp libftd2xx*/*.h .
cp libftd2xx*/*.cfg .

Generate your makefile:

./configure

Open Makefile in a text editor and perform the following operations:

  1. Find the line CFLAGS = -g -O2 and replace it with CFLAGS = -g -O2 -DHAVE_LIBUSB -DSUPPORT_FT245R.
  2. Find the line LIBS = -lreadline -lncurses -ltermcap and replace it with LIBS = -lreadline -lncurses -ltermcap ./libftd2xx.a.0.4.16 -lrt.

Now to actually compile it:

make

From here, you can follow the instructions at http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html starting at step 5. Note that you’ll need to modify the commands a little bit. Instead of:

avrdude -c diecimila -P ft0 -p m168

you should write:

sudo ./avrdude -C avrdude.conf -c duemilanove -P ft0 -p m168

(Note: you can still use it on a Diecimila, just specify the programmer as `-c duemilanove` and it should work.)

If you’d like to use SparkFun’s FTDI Basic Breakout as a programmer, try these instructions.

Accessing AVR GPIOs via bit fields

2009 December 8
by David

atmega328

I noticed that the TMS320F2809 examples accessed GPIOs by bits rather than as 32-bit ints. For example, it’s possible to set a GPIO like this on the TMS320F280x:

GpioDataRegs.GPADAT.bit.GPIO12 = 1; // Sets GPIO12 to high.

Normally when working with AVRs, I would set bits like this:

PORTB |= (1<<PB3); // Sets port b, bit 3 to high.

After a bit of tinkering, I came up with this (for AVRs):

portb.bit.b3 = HIGH; // Sets port b, bit 3 to high.

I personally think it looks a bit cleaner, so I’ll probably be using it in the future. If you’re interested in trying it out, you can download a full example here: bitfields.zip.



Side note: It is also possible to access GPIOs as 32-bit ints on the TMS320F280x like this:

GpioDataRegs.GPADAT.all |= (1<<12); // Sets GPIO12 to high.


Edit: Looks like I’m not alone.

pidgin-facebookchat on Ubuntu 9.04

2009 November 10
by David

First check if you’re using a 64-bit system or a 32-bit system:

uname -m

If you’re using a 64-bit system it will output “x86_64“. Otherwise you’re on 32-bit.

Install the required packages:

sudo apt-get install build-essential -y
sudo apt-get build-dep pidgin -y
sudo apt-get install libpurple-dev libjson-glib-dev

Download pidgin-facebookchat:

cd Desktop
wget http://pidgin-facebookchat.googlecode.com/files/pidgin-facebookchat-source-1.62.tar.bz2
tar xjf pidgin-facebookchat-source-1.62.tar.bz2
cd pidgin-facebookchat

Now open the file called “Makefile” in a text editor. Change the second and third lines to:

LINUX32_COMPILER = gcc
LINUX64_COMPILER = gcc

Save the file and go back to the terminal.

Now perform the build:

make libfacebook.so # FOR 32-BIT USERS
make libfacebook64.so # FOR 64-BIT USERS

Copy the files to the right places:

sudo cp libfacebook.so /usr/lib/purple-2/ # FOR 32-BIT USERS
sudo cp libfacebook64.so /usr/lib64/purple-2/ # FOR 64-BIT USERS
sudo cp facebook16.png /usr/share/pixmaps/pidgin/protocols/16/facebook.png
sudo cp facebook22.png /usr/share/pixmaps/pidgin/protocols/22/facebook.png
sudo cp facebook48.png /usr/share/pixmaps/pidgin/protocols/48/facebook.png

Arduino 0017 on 64-bit Ubuntu 9.04 and 9.10

2009 October 29
by David

arduino-64-bit

Update 2009-12-25: these instructions work on both 9.10 Karmic and 9.04 Jaunty.


  1. Install all dependencies:
    sudo apt-get install sun-java6-jre gcc-avr avr-libc ia32-libs librxtx-java
  2. Download 32-bit version of Arduino 0017: [download]
  3. Extract it and navigate to the lib/ directory. Delete RXTXcomm.jar and librxtxSerial.so.
  4. Go back to the main directory and open the arduino script in a text editor. Replace its contents with:
    #!/bin/sh
     
    APPDIR="$(dirname -- "${0}")"
     
    for LIB in \
        java/lib/rt.jar \
        java/lib/tools.jar \
        lib/*.jar \
        ;
    do
        CLASSPATH="${CLASSPATH}:${APPDIR}/${LIB}:/usr/share/java/RXTXcomm.jar"
    done
    export CLASSPATH
     
    LD_LIBRARY_PATH=/usr/lib:`pwd`/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH
     
    export PATH="${APPDIR}/java/bin:${PATH}"
     
    java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base

  5. Note:
    The Serial Monitor in the Arduino IDE doesn’t work. As a replacement, you can install screen with:

    sudo apt-get install screen

    To start screen for use with an Arduino, run this command:

    screen /dev/ttyUSB0 9600

    Replace /dev/ttyUSB0 with the location of your serial port and 9600 with the baud rate you’re using.

    To quit screen, press Ctrl-a then press k. You must quit screen before you can upload a program via the Arduino IDE.

Electronics Projects

2009 October 16
by David

Coming “soon”, in order of likelihood:

  1. External touchpad for Kaoss KPx similar to the Kaoss Guitar (watch about 30 seconds starting at 2:30 to get the basic idea).
  2. AVR-based MIDI controller.