Squirreltech

March 4, 2012

Digi Pots 2!

Filed under: Electrical Engineering — Tags: , , — squirreltech @ 11:48 pm

I found this application called Fritzing that allow for easy schematic writing and image exporting…. So here is the schematic for the code in the last post.

 

Unfortunately, I realized I’ll need to go back to the drawing board… A speaker system has two “channels”, one for left and one for right. And so I’ll need each channel to go through two potentiometers….

March 1, 2012

Digi Pots!

Filed under: Electrical Engineering — squirreltech @ 1:15 am

So, I knew from school (high school I think) that a potentiometer allows for variable resistance. You see them when you turn a knob or a wheel to change the volume. My current project is to replace the volume knob on my nice speaker set with a device that will listen for the up/down volume control from my TV remote.

I broke this down into several phases:

  1. Read stuff from my tv remote
  2. Know which button was pressed on the remote and output something saying so
  3. Light a different LED based on the button pressed (i.e. red for up, yellow for down)
  4. Control a potentiometer via arduino
  5.  Put it all together

I manged to track down an IR Receiver and steps 1, 2, and 3 were relatively straight forward. The hard part came with the potentiometer. I managed to track down that what I needed was a “digital potentiometer”. Did some quick research, entered my credit card # and then I had three of them on their way. Sweet… er, now what? This thing has a lot more pins than an LED. 8 to be exact:

The MCP41X digital potentiometer

Well, many thanks to this post and specifically the notes about what pins they used:

  * All A pins  of AD5206 connected to +5V
  * All B pins of AD5206 connected to ground
  * An LED and a 220-ohm resisor in series connected from each W pin to ground
  * CS - to digital pin 10  (SS pin)
  * SDI - to digital pin 11 (MOSI pin)
  * CLK - to digital pin 13 (SCK pin)

So, I matched that description to the MCP41X data sheet and uploaded the code found in that example and lo and behold my LED got brighter and dimmer!!! Wooo!

The last step was to make it user controlled, so I added in some Serial.read stuff and took out the loops and here is the resulting code:

// From here:
// http://www.arduino.cc/en/Tutorial/SPIDigitalPot
/*
 Digital Pot Control

 This example controls an Analog Devices AD5206 digital potentiometer.
 The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
 A - connect this to voltage
 W - this is the pot's wiper, which changes when you set it
 B - connect this to ground.

 The AD5206 is SPI-compatible,and to command it, you send two bytes,
 one with the channel number (0 - 5) and one with the resistance value for the
 channel (0 - 255). 

 The circuit:
 * P0A connected to +5V
 * P0B connected to ground
 * An LED and a 220-ohm resisor in series connected from P0W to ground
 * CS - to digital ardunio pin 10 (SS pin)
 * SDI - to digital ardunio pin 11 (MOSI pin)
 * CLK - to digital ardunio pin 13 (SCK pin)

 * Vdd to +5V?
 created 10 Aug 2010
 by Tom Igoe

 Thanks to Heather Dewey-Hagborg for the original tutorial, 2005

 */

// inslude the SPI library:
#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
const int numChannels = 1;
const int initialLevel = 64;
const int interval = 8;
const int maxLevel = 128;
int incomingByte = 0;
int level = initialLevel;
const int D_KEY = 100;
const int U_KEY = 117;
void setup() {
 // set the slaveSelectPin as an output:
 pinMode (slaveSelectPin, OUTPUT);
 // initialize SPI:
 SPI.begin();
 Serial.begin(9600);
}
void loop() {

 // send data only when you receive data:
 if (Serial.available() > 0) {
 // read the incoming byte:
 incomingByte = Serial.read();
// say what you got:
 Serial.print("I received: ");
 Serial.print(incomingByte, DEC);
 Serial.print( ": " );
if( incomingByte == U_KEY ) {
 Serial.println( "up!" );
 level += interval;
 digitalPotWrite(0, level);
 }
 if( incomingByte == D_KEY ) {
 Serial.println( "down!" );
 level -= interval;
digitalPotWrite(0, level);
 }
level = (level > maxLevel ) ? maxLevel : level;
 level = (level < 0 ) ? 1 : level;
 }
 Serial.print( "level: " );
 Serial.println( level );
}
// address is the "channel" of the "P". In this case there
// is only one channel so this will always be 0.
int digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
 digitalWrite(slaveSelectPin,LOW);
 // send in the address and value via SPI:
 SPI.transfer(address);
 SPI.transfer(value);
 // take the SS pin high to de-select the chip:
 digitalWrite(slaveSelectPin,HIGH);
}

July 29, 2011

pianobar man!

Filed under: music, Ubuntu — squirreltech @ 4:16 am

Pianobar is a command line client for pandora… I am beginning to feel that it is a must have for any home automation directed squirrel, especially if he already has a pandora account.

I was searching for details on this mysterious “eventcmd” that I saw referenced somewhere as a way to get information out of pianobar when you did an action. Apparently people really want to post their current song to last.fm. Whatever. But I couldn’t find many details about the syntax and such, until this one that referenced a man page!! Duh. I somehow figured that since it didn’t have much documentation on the web site, there just wasn’t much at all.

Well, to help anyone else in this situation, i’ll paste it here for the google crawlers to find. I found it very useful, most especially the part about “ctl” as a command interface….. this means I can write some kind of gui front end to start, stop, change play from my phone. Awesome.

pianobar(1)                                                        pianobar(1)

NAME
       pianobar - console pandora.com music player

SYNOPSIS
       pianobar

DESCRIPTION
       pianobar  is  a  lightweight  console music player for the personalized
       online radio pandora.com.

FILES
       $XDG_CONFIG_HOME/pianobar/config or ~/.config/pianobar/config
              Per-user configuration file. See CONFIGURATION.

       /etc/libao.conf or ~/.libao
              Global/per-user audio output configuration. See libao documentaâ
              tion at http://xiph.org/ao/doc/config.html

CONFIGURATION
       The  configuration file consists of simple key = value lines. Each terâ
       minated with a newline (\n) character. Keys and values  are  both  case
       sensitive. act_*-keys control pianobar's key-bindings.

       act_help = ?
              Show keybindings.

       act_songlove = +
              Love currently played song.

       act_songban = -
              Ban  current  track.  It  will  not be played again and can only
              removed using the pandora.com web interface.

       act_stationaddmusic = a
              Add more music to current station.  You  will  be  asked  for  a
              search  string. Just follow the instructions. If you're clueless
              try '?' (without quotes).

       act_bookmark = b
              Bookmark current song or artist.

       act_stationcreate = c
              Create new station. You have to enter a search string and select
              the song or artist of your choice.

       act_stationdelete = d
              Delete current station.

       act_songexplain = e
              Explain why this song is played.

       act_stationaddbygenre = g
              Add genre station provided by pandora.

       act_history = h
              Show history.

       act_songinfo = i
              Print information about currently played song/station.

       act_addshared = j
              Add shared station by id. id is a very long integer without "sh"
              at the beginning.

       act_songmove = m
              Move current song to another station

       act_songnext = n
              Skip current song.

       act_songpause = p
              Pause/Continue

       act_quit = q
              Quit pianobar.

       act_stationrename = r
              Rename currently played station.

       act_stationchange = s
              Select another station.

       act_songtired = t
              Ban song for one month.

       act_upcoming = u
              Show next songs in playlist.

       act_stationselectquickmix = x
              Select quickmix stations.

       act_voldown = (
              Decrease volume.

       act_volup = )
              Increase volume.

       audio_format = {aacplus,mp3,mp3-hifi}
              Select audio format. aacplus is default if both libraries (faad,
              mad)  are  available. mp3-hifi is available for Pandora One cusâ
              tomers only.

       autostart_station = stationid
              Play this station when starting up. You can get the stationid by
              pressing i or the key you defined in act_songinfo.

       ban_icon = </3
              Icon for banned songs.

       control_proxy = http://host:port/
              Non-american  users  need  a  proxy to use pandora.com. Only the
              xmlrpc interface will use this  proxy.  The  music  is  streamed
              directly.

       event_command = path
              File that is executed when event occurs. See section EVENTCMD

       history = 5
              Keep a history of the last n songs (5, by default). You can rate
              these songs.

       love_icon = <3
              Icon for loved songs.

       password = plaintext_password
              Your pandora.com password. Plain-text.

       proxy = http://host:port/
              Use  a  http  proxy.  Note  that  this  setting  overrides   the
              http_proxy environment variable.

       sort  =  {name_az,  name_za,  quickmix_01_name_az, quickmix_01_name_za,
       quickmix_10_name_az, quickmix_10_name_za}
              Sort station list by  name  or  type  (is  quickmix)  and  name.
              name_az   for  example  sorts  by  name  from  a  to  z,  quickâ
              mix_01_name_za by type (quickmix at the bottom) and name from  z
              to a.

       user = your@user.name
              Your pandora.com username.

       volume = 0
              Initial volume correction in dB. Usually between -30 and +5.

REMOTE CONTROL
       pianobar  can be controlled through a fifo. You have to create it yourâ
       self by executing

        mkfifo ~/.config/pianobar/ctl

       Adjust the path if you set up a $XDG_CONFIG_HOME.  Afterwards  you  can
       write commands directly into the fifo. Example (next song):

        echo -n 'n' > ~/.config/pianobar/ctl

       n is the keybinding for "next song". If you customized your keybindings
       you have to use these characters to control pianobar.   This  behaviour
       may change in the future!

       Another example:

        while true; do;
           nc -l -p 12345 -s localhost localhost > ~/.config/pianobar/ctl;
           sleep 1;
        done

        echo -ne 'n\x1a' | nc -q 0 127.0.0.1 12345

EVENTCMD
       pianobar  can  report  certain "events" to an external application (see
       CONFIGURATION ). This application is started with  the  event  name  as
       it's  first  argument. More information (artist, title, album, stationâ
       Name, error code, error description, song length in milliseconds,  ratâ
       ing, album art url) is supplied through stdin.

       Currently  supported events are: artistbookmark, songban, songbookmark,
       songexplain, songfinish, songlove, songmove, songshelf, songstart, staâ
       tionaddmusic,  stationaddshared, stationcreate, stationdelete, stationâ
       fetchplaylist, stationquickmixtoggle, stationrename

       An example script can be found in the contrib/ directory of  pianobar's
       source distribution.

AUTHOR
       Lars-Dominik Braun <lars@6xq.net>

                                                                   pianobar(1)

July 17, 2011

The World Cup in a file

Filed under: Ubuntu — Tags: , , , — squirreltech @ 8:07 pm

Some family friends are staying at our place for a week or so and they really wanted to see the Women’s World Cup finals. Well, they were going to be out and about for the actual game, so they asked if it was possible to record it. We got rid of DVR last November (that’s like $800 saved!!) so I decided to see what my Ubuntu machine could do.

To test it first (game hasn’t started yet), I decided to try a current, live stream and I found this site that would give me a “sop” link, but putting that into VLC gave me this error:

Your input can't be opened:
VLC is unable to open the MRL 'sop://broker.sopcast.com:3912/111719'. Check the log for details.

So, some research brought me to kabology and how to install the sopcast player. I ran these commands in a term window:

echo "deb http://ppa.launchpad.net/jason-scheunemann/ppa/ubuntu `lsb_release -cs` main" | sudo tee -a /etc/apt/sources.list && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CD30EE56
sudo apt-get update && sudo apt-get install sopcast-player sp-auth

This created the “SopCast Player” in Applications -> Sound & Video. I fired that up and entered my test sop mrl (?) and I was then greeted with a man announcing a basketball game (I think) in some Eastern European language! I then fired up vlc (version 1.1.9)  and clicked Media > Streaming… I clicked on the Network tab and entered http://localhost:8902. (The 8902 port can be configured in the SopCast Player Edit > Preferences > Out-bound Port.) Clicking “Stream” brought me to a Stream Output wizard. I selected a File to stream to an MP4 and checked the Display Locally check box so I could check in on the game here and there. Then I hit Stream.

I was then presented with a black box with the audio, but then I realized I had been doing all this from TightNVC viewer on my win 7 laptop. I walked over to the machine itself, and noticed it was playing video too!

May 18, 2010

AR Finger Tracking

Filed under: Uncategorized — squirreltech @ 8:58 pm

Well, i’m back again. I am using the processing platform to play with this stuff, because it is so easy to make graphic applications and in very few lines, you can get something up and running.

So, I was very happy to find the SimpleARToolkit. This is a wrapper for the jARToolkit which it self it a wrapper for the ARToolkit. jARToolkit doesn’t seem to be in active development any more, which I think is a bummer because I really don’t want to go back to C/C++ to do coding. I like Java 😦 Sigh….

Anyway, I did have some good results with an AR marker. This is simply a black and white image that is not symmetrical left to right or top to bottom. The code knows the image as some kind of “patt” file, which is probably just short for pattern. This is really nice because the image can be generated and chances of it appearing in the background are very slim. Additionally, the application can assign “up”, which means I can turn my finger relative to the camera and the code recognizes this.

Check out the video below. Then the code afterward.

Code:

import JMyron.*;
import processing.opengl.*;
import pARToolKit.SimpleARToolKit.*;

JMyron m;
PImage img;
SimpleARToolKit hiro;
SimpleARToolKit ren;
int capWidth, capHeight;

void setup() {

  capWidth = 320;
  capHeight = 240;
  size(capWidth, capHeight, OPENGL);
  m = new JMyron();
  m.start(capWidth, capHeight);
  m.findGlobs(0);
  img = createImage(capWidth, capHeight, ARGB);
  hiro = new SimpleARToolKit(this, capWidth, capHeight);
  hiro.loadPattern("patt.kanji", 80, 0.0f, 0.0f);
  hiro.register("showBox");

  stroke( 0, 255, 0 );
}

void draw() {
  background(0);
  m.update();
  m.imageCopy(img.pixels);
  img.updatePixels();
  hint(DISABLE_DEPTH_TEST);
  image(img,0,0,width,height);
  hint(ENABLE_DEPTH_TEST);
  if (hiro.findMatch(img,100)) {
    hiro.showObject();
  }
}

void showBox(SimpleARToolKit _a) {
//  noFill();

  strokeWeight(4);
  line( 25, 0, 25, 50);
  line( 25, 50, 0, 25 );
  line( 25, 50, 50, 25 );
//  box(50);

}

May 6, 2010

Color tracking

Filed under: Uncategorized — squirreltech @ 9:03 pm

Well… I did get that code from my previous post working on my machine (Dell E6400 running win 7). I can click to change what color should be tracked. This has no filters, it just looks for the designated color (indicated by the circle in the upper left corner) and puts a new circle there.

Obviously, not realistic for mouse replacement, especially if I happen to be wearing a blueish shirt! I think we’ll have to keep looking.

April 29, 2010

Finger Tracking Options

Filed under: Uncategorized — squirreltech @ 10:13 pm

I did some looking on youtube of course, and found some pretty crazy stuff. That last one is my favorite, and ultimately something I would like to get to. I set an email to the poster guy but he’s a bum and didn’t email me back 😦

I discovered three plausible (for me) ways in which to do finger tracking.

  1. Tracking a color on my finger
  2. Tracking an AR marker
  3. HAAR like feature tracking.

HAAR sounded too much like I would need to learn a lot about computer vision to make it “learn” what a finger looks like. On the other hand, this doesn’t require any physical objects except my fingers, and I am suspecting would be more robust.

I don’t own a printer so tracking an AR marker would require heading to Kinko’s or more likely Emily’s to steal some paper and maybe a kiss. 🙂

So, color tracking seemed like the best idea… At least for now. It seemed that processing was a good platform to get the concepts worked out. I’ve never really worked with stuff like the camera before, and I had no idea how to manipulate an image to capture one color spot, but that is what the internet is for, no?

Eventually, I found this post in the processing forums and decided I had a winner.

April 28, 2010

Random stumble from B.

Filed under: Uncategorized — squirreltech @ 12:29 am

B. sent me this link. I think it has a lot of the same patterns as my CounterClock. Even still, it is just cool 🙂

April 26, 2010

Finger Tracking

Filed under: Uncategorized — squirreltech @ 2:12 pm

Well…. a while back I came across Johnny Lee’s wiimote finger tracking, here. So I bought a wiimote and sat down to get to work. After some searching, I found the proper reflective tape (infrared doesn’t just bounce off any ol’ reflector tape. I think I ended up finding it at an army supply store!)

The next step was to build an infrared LED array that would serve as a “light” source. In attempting to build this array, I truly appreciated the freedom of working in abstract worlds such as computer programming. For example, when I need a new variable I can just type it out and give it a type and a name and use it. The concrete world of electronics does not have such a luxury. If I want a new LED, I have to get in my car drive out to the electronics shop and purchase one. I can’t even freakin download it! Sheesh, how do these EE people get any thing done?

Well, then I had to move and fly off to strange places and all the little pieces and thoughts got packed into a(n abstract) tool box until I could get back to it…..

Until…. I got a new work laptop that came with a built in web cam. When I first heard about it, I wasn’t thrilled- “What the heck am I going to do to a web cam?” But then the wiimote finger tracking idea hit me. What if I could use the web cam to track my finger….. oooooooo. So, the next few posts will be about my research along those lines…

April 23, 2010

CounterClock

Filed under: Uncategorized — squirreltech @ 5:22 pm

Well, it wouldn’t be right if I didn’t start with this one. I was cruising around the internets one day, and I found an awesome flash called pelotas.swf, here for example. It looks only slightly interesting… until you wait for a few moments when everything lines up. Really really crazy stuff.

Sooo, I did some thinking and was able to figure out the algorithm used (some guessing and some pi and such) and came up with CounterClock. I added a few more spirals (variable number actually) and a whole page full of other parameters. Hit the ‘h’ key to see!

Some screen shots:

Older Posts »

Create a free website or blog at WordPress.com.