“Funny fact: lolcats cannot be put in a Schroedinger state, because quantum rules don’t work on a macro level.” – qvantamon on MetaFilter
Categories
Linky
Archives
Meta
“Funny fact: lolcats cannot be put in a Schroedinger state, because quantum rules don’t work on a macro level.” – qvantamon on MetaFilter
For a while, a friend and I have been planning to build a specialized MIDI controller into a guitar to control a Korg Kaoss Pad KP2. The idea came from the guitar used by Matt Bellamy of Muse (check out a video of it).
We ordered the electronics for the guitar from SparkFun Electronics and Digi-Key. When the project is over, I plan to add up the total cost and post a bill of materials. I suspect it will total to around $100.
Today we tested out the 4.3″ touchpad from SparkFun using an Arduino. I have just finished setting up an ATmega328P on a breadboard and got a basic blink program running. The final product will be running on a plain AVR without the Arduino libraries/bootloader.
One problem I ran into using my FTDI programmer was the clock rate. A fresh ATmega328P comes running at 1 MHz, significantly lower than the default 16 MHz on Arduino-prepared ATmegas. As a result, I kept getting errors like this:
david@second:~$ avrdude -c ftdi -p atmega168 -P ft0 avrdude: BitBang OK avrdude: pin assign miso 1 sck 3 mosi 0 reset 4 avrdude: drain OK ft245r: bitclk 230400 -> ft baud 115200 avrdude: ft245r_program_enable: failed avrdude: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check. avrdude done. Thank you.
Eventually I found AVRDUDE’s -B option. It adjusts the clock rate that’s fed into the SCK pin on the AVR. I found that a value of -B 76800 works well, but if you’re running into this problem, I recommend starting with -B 1 and going up until it stops working. To be explicit, this is the command that I found works:
david@second:~$ avrdude -c ftdi -p atmega168 -P ft0 -B 76800
I was reading about client-side prediction in the context of video game physics today and thought of an idea: client-side prediction on streamed video (e.g. on Skype or similar video chats). Each pixel could be assigned a velocity and “color velocity” (
,
,
). A velocity grid method like the one described in Practical Fluid Dynamics 1 and 2 comes to mind.
This is a method of using Cairo with Pygame. It works by sharing the same block of memory for the Cairo drawing surface and the Pygame image surface. The only trick to it is making sure that Cairo and Pygame use the same format to store the pixel data in.
#!/usr/bin/env python import cairo import pygame import math size = 400, 400 # Initialize pygame with 32-bit colors. This setting stores the pixels # in the format 0x00rrggbb. pygame.init() screen = pygame.display.set_mode(size, 0, 32) # Get a reference to the memory block storing the pixel data. pixels = pygame.surfarray.pixels2d(screen) # Set up a Cairo surface using the same memory block and the same pixel # format (Cairo's RGB24 format means that the pixels are stored as # 0x00rrggbb; i.e. only 24 bits are used and the upper 16 are 0). cairo_surface = cairo.ImageSurface.create_for_data( pixels.data, cairo.FORMAT_RGB24, size[0], size[1]) # Draw a white circle to the screen using pygame. radius = int(min(size)/2*0.7) pos = [int(a/2) for a in size] pygame.draw.circle(screen, (255,255,255), pos, radius) # Draw a smaller black circle to the screen using Cairo. context = cairo.Context(cairo_surface) context.set_source_rgb(0, 0, 0) context.arc(size[0]/2, size[1]/2, min(size)/2*0.5, 0, 2*math.pi) context.fill() # Flip the changes into view. pygame.display.flip() # Wait for the user to quit. while pygame.QUIT not in [e.type for e in pygame.event.get()]: pass
Tested on Python 2.6.4, pycairo 1.8.6, Cairo 1.8.8, pygame 1.8.1, numpy 1.3.0.
).
).Details and derivation here: motor.pdf.
My Wacom Bamboo Fun tablet has been exceptionally jittery on my Lenovo ThinkPad. I assume this is probably caused by EM noise from the computer (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):

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 --listNow, 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!
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:~$
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:

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:

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

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:
You should end up with an adapter cable like this:

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. At this point, you should be able to plug in an MP3 player and have the audio routed to your car’s speakers.
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
Edit 2010-04-18:
I just found out that new AVRs need to have the clock rate adjusted before this will work. This is because AVRs come with the internal clock set to 1 MHz (actually, 8 MHz with the CKDIV8 fuse bit set) instead of the Arduino default 16 MHz. This can be done with AVRDUDE’s -B option. This option determines what clock is fed into the AVR’s SCK pin. I recommend starting with a value of -B 1 and working your way up to a reasonable clock speed. Here is the adjusted command for new AVRs:
sudo ./avrdude -C avrdude.conf -c ftdi -p m168 -P ft0 -U hfuse:r:-:h -U lfuse:r:-:h -U efuse:r:-:h -B 1
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:
CFLAGS = -g -O2 and replace it with CFLAGS = -g -O2 -DHAVE_LIBUSB -DSUPPORT_FT245R.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.