Latest posts.

electricalily

electric lilies

 

Having a smartphone can be a blessing and a curse. It’s ridiculously easy to get in the habit of relying on it for everything — from directions to weather reports to emails. I wanted a notifier that would show me information like weather and inbox status without distracting me with a beep or requiring me to carry my phone around. I also wanted it to be beautiful and look natural in our house. I designed the electricalily flowers to meet these goals.

 

 

The three flowers are made of origami lily petals attached to biodegradable straw stems. (these straws are opaque and diffuse light better without the ugly red-line down the side) I folded each flower from recycled typewritten todo lists or notes. Inside each flower/stem combination resides a pair of 5mm LEDs, one RGB and one green. The green LED illuminates the flower stem while the RGB LED colors the flower.

 

 

A computer controls each flower through a custom board I designed for the project in eaglecad. I ordered the board through advanced circuits (following this tutorial b/c it had been a while) and I got really good results. It was a challenge to make a board small enough to fit through the neck of the bottle populated with connectors, and to qualify for the advanced circuits education deal I couldn’t make it smaller than 1.25″ square. I ended up with these dimensions exactly. I didn’t know if it would even fit until I soldered everything up and tried it!

I’m still working out different schemes for presenting information through some predefined colors or maybe a change in color. (the two things I want to show are the weather and email notifications) It’s pretty easy to change things around at this point because I’m controlling the flowers through python and I don’t have to change the firmware.

 

 

This project is still a little bit of a work in progress as I play with how to present information more ‘smartly’, but hopefully it covers some useful bits for people doing AVR development or making their own boards. I put all the code (firmware and software) and circuits on github, and everything is GPL.

https://github.com/tylerwilliams/electricalily

Stringer

There’s been a kinect kicking around The Echo Nest office since they came out, and I’ve been dying for a chance to use it. Music Hack Day New York was that chance. I worked with Alex Chen and Aidan Feldman to create an invisible string instrument over the weekend.

Alex had ported the strings from his mta.me demo to processing, so we first interfaced a kinect using Daniel Shiffman’s kinect library. This worked really well for a proof of concept, but we wanted some better hand-tracking for our demo.

I setup OpenNI and NITE and got the PointTracker sample running with multiple hands. Everything went swimmingly, so I integrated an OSC library with the PointTracker to send OSC messages to Processing. (thanks Jason for the c++ help!) Every time a new hand is detected, a message is sent to Processing with the hand ID, and from then on its coordinates as it moves are also sent.

If you want to try it yourself, here’s how:

  1. Download/Install libusb according to the libfreenect directions
  2. Download/Install OpenNI
  3. Download/Install the kinect sensor module
  4. Download/Install NITE.
  5. git clone “git@github.com:tylerwilliams/strings.git”
  6. Download/Build/Run my hacked PointTracker

Wireless Atmega8 LED Display

After spending some time understanding how the Medea vodka LED display was wired, I really wanted to use it in some kind of project. I had some LINX wireless modules lying around, so I made a wireless scrolling LED marquee. I had never worked with a scrolling display before, so I had to start from scratch. This is how I made it…

The first thing I had to do was figure out how to control the LEDs. The way this LED display is driven (like most) is with shift registers. There are 4 shift registers, each with 8 outputs for up to 32 pins. Only 30 are used; they’re connected to the 25 columns and 5 rows of the LED matrix. Because an entire row or column must be illuminated at once, the traditional way to display arbitrary ‘stuff’ is:

  1. Turn on/off all columns for row i.
  2. Illuminate row i.
  3. Let row i = i+1 and repeat the procedure.

By doing this very quickly, thousands of times per second, the eye is fooled into thinking that all rows / columns are on/off at once. Before messing with any wireless hardware or PCBs, I connected an Attiny2313 in a breadboard to my display, and wrote some code to do just this. Here’s the gist of it:

void blit(void)
{
    uint8_t j;
    uint8_t one = 0b00000111;
    uint8_t two = 0b11111111;
    uint8_t thr = 0b11111111;
    uint8_t fou = 0b11111111;
    one |= (1<<(7-(blitrow)));
 
    for (j=0; j<25; j++)
    {
        if (pixels[j] & (1<<(blitrow+2)))
        {
            uint8_t col = j;
 
            if (col <= 2)
                one &= ~(1<<(2-col));
            else if (col <= 10)
                two &= ~(1<<(7-(col-3)));
            else if (col <= 18 )
                thr &= ~(1<<(7-(col-11)));
            else
                fou &= ~(1<<(7-(col-19)));
        }
    }
    shift_byte(fou);
    shift_byte(thr);
    shift_byte(two);
    shift_byte(one);
    latch();
    blitrow++;
    if (blitrow >= 5)
        blitrow = 0;
}

NOTE: There’s some BS in there like shifting by 2 and subtracting by the byte offset to get the right bit position…it’s ugly, ignore it!

It didn’t work the first time, but after figuring out the right offsets for each bit I was able to turn on and off any individual LED. I was still a ways from scrolling text though. In fact, before I could even display static text, I needed to get a font.

Luckily, on the Arduino Forum, someone had already created a 5×5 pixel font! Each letter in the font is an array of 8, but really 5 bytes, each byte made of 8, but really 5 relevant bits. So to display a letter you would write each successive byte to a successive column. I dropped this into my code as a PROGMEM array (so it gets stored in flash instead of SRAM) and had a sideways letter displayed in no time.

uint8_t a[8] PROGMEM = {0x00,0x7c,0x44,0x44,0x7c,0x44,0x00,0x00};    
uint8_t b[8] PROGMEM = {0x00,0x7c,0x44,0x78,0x44,0x7c,0x00,0x00};
// ...
uint8_t z[8] PROGMEM = {0x00,0x7c,0x08,0x10,0x20,0x7c,0x00,0x00};

It was at this point that I realized I wanted a new, better font with more symbols, just like the Medea vodka bottle comes with. I found a font here in .ttf format that was free for personal use, but I couldn’t figure out a simple way to convert a .ttf file into a numeric description of pixels. After wasting an hour looking for some kind of font converter, I stumbled across a great set of tools for designing symbols for LED displays. I modified it slightly to dump byte arrays in my font format, and then recreated each glyph in the font by hand.

The new font took up so much space that it didn’t fit on my Attiny2313, and I had to switch to an Atmega8. I also stopped at this point to make a PCB with a wireless module on it (while it’s possible to prototype wireless circuits on a breadboard, the breadboard’s crappy connections make it really tough to track down problems). The wireless part of the circuit is basically taken straight from the LINX RXM-433-LR datasheet. This is what it looks like:

I usually have to go through a couple revisions of PCB to work out the kinks, and this board was no exception. On the first iteration I left out the crystal, on the second I made the ISP pads too small and they lifted off, on the third I changed to a different regulator and on the fourth, I finally got it right! After connecting the display and porting the tiny2313 code, I was ready to make the characters on the display scroll.

There are probably more efficient ways to do this, but I made a buffer representing the state of all pixels which the interrupt routine uses to continuously update the LED states. The main loop of my program fetches one column of the current character, shifts the entire buffer one pixel left, and appends this last column. After it’s appended all the columns for a single character, it fetches the next character in the message.

Getting the wireless to work was the most finicky part of the project. I left two debug points on the circuit to connect a serial device directly for debugging, and I designed the communication protocol assuming I would talk to the device with serial over a wireless link. The wireless modules will basically pipe an input on the TX side to an output on the RX side, so I assumed I could just connect TX and RX to serial ports that I wanted to talk, but I soon found out that only about 1 in 20 messages would go through the link. The reason is that the serial data coming from an avr’s UART is not balanced — it doesn’t have the same number of on and off states per time. This can lead to the transmitter or receiver becoming biased and not decoding everything. The right way to deal with this is to use something like Manchester encoding, which has at least one transition per bit, and therefore no DC component. But this was more work than I was ready to do. A cheap way of doing Manchester encoding is to send two bytes instead of one, with each byte the complement of the other. This helps enough to make the transmission work >90% of the time, and is really simple to implement, so I used it. Here’s an example of sending a ‘manchester serial’ byte from Python.

def manchester_send_byte(serial_port, data):
    a = b = 0
    i = j = 7
    # Loop through the bits of the data
    while (i >= 4):
        # Set the bits of the encoded data where needed
		if (bitSet(data, i)):
			a |= (1<<j);
		else:
			a |= (1<<(j-1));
 
        # Set the bits of the encoded data where needed
		if (bitSet(data, i-4) != 0):
			b |= (1<<j);
		else:
			b |= (1<<(j-1))
		j-=2
		i-=1
    # Send the data out the UART
    send_byte(serial_port, 'U')
    send_byte(serial_port, chr(a))
    send_byte(serial_port, chr(b))

The last step was to get a box to hold the circuit and display. I found a 1.5″ deep 3″x5″ wood frame at my local art store that was perfect. To mount the display, I replaced the coin cell batteries with magnets, and then I also attached magnets to both inner edges of the frame. The magnets hold everything together securely and the LED display can still be rotated and removed to work on it.

This project took me about 3 weekends to finish, even though I had basic display functionality working after only a few hours. The little things take the most time. The final product still has a few bugs, for example the display will stop scrolling if left alone for 24 hours or so, and it will glitch while receiving data, but overall this project was a success and I learned some of the basic mechanics of a scrolling LED display! I hope you can pull something useful out of it. Check out the video below for the final product.

UPDATE: Code here.

Reverse Engineering the Medea Vodka LED Display

The Medea Vodka display is a really cool piece of technology. (Unfortunately its main purpose is advertising) If you haven’t seen it, it’s basically a 5 by 25 pixel LED display that you can program. Wrapped around a bottle of vodka.

I haven’t been able to find it for sale anywhere around Cambridge (supreme, libby’s), but for one glorious day a rep was selling it at the liquor store in Davis Sq., and I snagged a bottle. Apparently there are different colors, but blue was all that was available when I got mine.

The display itself is flexible pcb that fits into a specially formed channel in the side of the bottle and is held on by a translucent rubber band that covers it. There are little recesses in the bottle where the coin cell (cr2032) batteries fit.

The circuit itself is a really smart bit of engineering. The two CR2032 lithium batteries are connected in series to hit the necessary voltage for multiple blue LEDs. The PIC chip, which is always “on”, monitors the button states and drives the shift registers. The chip goes into a low power ‘sleep-mode’ when you press the off button. The 4 shift registers are cascaded together, so the PIC shifts in 4 bytes (32 bits), and then latches the shift registers simultaneously, which transfers the bytes from the storage buffer to the output side (LEDs).

The Atmel memory chip stores any saved messages (and possibly the font). I don’t have a PIC programmer, so I’m not sure if the PIC chip is locked  or if you can program it still. The most interesting thing to me is the lack of current limiting resistors; they are not necessary because the batteries can’t source enough current to burn out any LEDs, but this also saves a ton of space! A side effect of saturating the battery’s capacity is that the voltage fluctuates massively; from about 4.4V to 5.5V as a message scrolls by with more or fewer ‘pixels’ lit. But the microcontroller does not brown out!

Using a multimeter and Eagle CAD I tried to sketch out the circuit a little bit to help myself with programming an AVR to drive the display. This is what I came up with:

It’s not perfect, but it should convey the basic idea.

Hopefully this helps you get started playing with this display, if you can find one. It’s especially cool to find that a display like this that isn’t tamper proofed with gobs of epoxy. Props to Medea for that! In my next post I will show how I interfaced an atmega8 chip to this display and am controlling it wirelessly.

UPDATE: More here.

binaural beats

I put together a little Python script to hear what binaural beats sound like. Here’s an example (best appreciated with headphones):

binaural_440.0_450.0

and the code!

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# encoding: utf-8
 
"""
from: http://en.wikipedia.org/wiki/Binaural_beats
 
Binaural beats or binaural tones are auditory processing artifacts, or apparent sounds, 
the perception of which arises in the brain for specific physical stimuli. This effect 
was discovered in 1839 by Heinrich Wilhelm Dove.
 
The brain produces a phenomenon resulting in low-frequency pulsations in the loudness 
and sound localization of a perceived sound when two tones at slightly different frequencies 
are presented separately, one to each of a subject's ears, using stereo headphones. A 
beating tone will be perceived, as if the two tones mixed naturally, out of the brain. 
The frequency of the tones must be below about 1,000 to 1,500 hertz for the beating to 
be heard. The difference between the two frequencies must be small (below about 30 Hz) 
for the effect to occur; otherwise, the two tones will be heard separately and no beat 
will be perceived.
 
Binaural beats are of interest to neurophysiologists investigating the sense of hearing. 
Second, binaural beats reportedly influence the brain in more subtle ways through the 
entrainment of brainwaves[1][2] and can be used to reduce anxiety[3] and provide other 
health benefits such as control over pain.[4]
 
props to:
1) http://mail.python.org/pipermail/python-list/2009-June/1207339.html
2) http://www.daniweb.com/code/snippet263775.html
"""
 
import math
import wave
import struct
import array
 
def make_soundfile(left_freq=440, right_freq=460, data_size=10000, fname="test.wav"):
    """
    create a synthetic 'sine wave' wave file with frequency freq
    file fname has a length of about data_size * 2
    """
    frate = 11025.0  # framerate as a float
    amp = 8000.0     # multiplier for amplitude
 
    # make a sine list ...
    sine_list = []
    for x in range(data_size):
        left = math.sin(2*math.pi*left_freq*(x/frate))
        right = math.sin(2*math.pi*right_freq*(x/frate))
        sine_list.append((left,right))
 
    # get ready for the wave file to be saved ...
    wav_file = wave.open(fname, "w")
    # give required parameters
    nchannels = 2
    sampwidth = 2
    framerate = int(frate)
    nframes = data_size
    comptype = "NONE"
    compname = "not compressed"
    # set all the parameters at once
    wav_file.setparams((nchannels, sampwidth, framerate, nframes,
        comptype, compname))
    # now write out the file ...
    print( "may take a moment ..." )
    for s in sine_list:
        data = array.array('h')
        data.append(int(s[0]*amp/2)) # left channel
        data.append(int(s[1]*amp/2)) # write channel
        # write the audio frames to file
        wav_file.writeframes(data.tostring())
    wav_file.close()
    print( "%s written" % fname )
 
 
# set some variables ...
left_freq = 440.0
right_freq = 450.0
# data size, file size will be about 2 times that
# duration is about 4 seconds for a data_size of 40000
data_size = 60000
 
# write the synthetic wave file to ...
fname = "binaural_%s_%s.wav" % (left_freq, right_freq)
 
make_soundfile(left_freq, right_freq, data_size, fname)
 

lightning over the P.O. tonight

Lightning over the P.O.

electroconvulsive therapy

A paper origami lily + a pink LED.

pink glory

echo:play

San Francisco Music Hack Day was 2 weeks ago, and even though I couldn’t be there, I was able to submit a remote hack. Echo:play (wow, such a creative name…) is a minimalist html5 song player powered by the Echo Nest‘s similarity and image data coupled with Play.me‘s audio.

Features:

  • Search for songs (with hot but slow autocompletion)
  • Listen to 30 second samples
  • Login (with OAuth) to listen to the full songs.

My favorite part is the design, which I’m slowly getting better at after cranking out a couple of monstrosities.

night sky


I made a time lapse video of the sky from my deck. I used a D90, (F2.8, 30s, ISO200) controlled by an app called sofortbild, which can trigger the camera at set intervals and capture the pictures directly to the computer. This video is made from 125 frames at 25 frames per second, assembled using iStopMotion. I wanted to capture more but the cold stunted the camera’s battery life.


update

Upgraded the old blag to 2.8.4 from 2.7.1 after reading this bad boy. Keeping stuff current is a full time job.

Today I setup a WRT45G to repeat the coffee shop’s wireless from downstairs, but after 12 hours they banned the router’s MAC address. My solution is a cron job that runs every 10 hours and switches the MAC between one of two addresses.

In dd-wrt, put this in Administration -> Management -> Cron -> Additional Cron Jobs

* */10 * * * root MAC1=00:90:4D:83:AB:03; MAC2=00:90:4D:83:CD:03; if [ `ifconfig eth1 | grep HWaddr | awk \{print $5}\` == $MAC1 ]; then nvram set def_hwaddr=$MAC2; else nvram set def_hwaddr=$MAC1; fi; nvram commit; reboot;