I have been thinking about designing, coding, and building a quad copter for a long time. I think I am finally at a level of experience and financial security to give it a run. In the mean time, I got a Silverlit x-ufo off with a broken mechanical gyro off ebay and did a plottermeier mod. I just wanted to start fooling around with a quadrotor to get used to some of the controls and terminologies. I got the electronic gyros from two WarioWare Twisted games : http://en.wikipedia.org/wiki/WarioWare_Twisted!. Here’s a video.
WarioWare Twisted + QTAR
July 2nd, 2009 — Hardware, hack
Calculate drop down resistors for LEDs
May 12th, 2009 — Hardware
As I was learning about electronics, the use of the drop down/pull up resistor came up a lot. Too often instructors neglect to explain how to properly calculate the value of the resistor. Either they would not explain anything at all or they would leave out the effects of the voltage drop of the component. It is really pretty easy and it eventually becomes important; so, you should know this. This is most often used when hooking up an LED so we are going to use that as an example.
Here is the most bare-bones circuit you would use to light an LED:
Now, if you actually hook this up, you are going to have a problem. Without any kind of significant resistance in the circuit, the LED is going to run free and draw a lot of current in a small amount of time. In most cases, it will burn out and will never light to it’s full potential again. Remember that 0 Ohms of resistance in a circuit is a bad thing! In order to supply the right amount of current to the LED, we need a circuit like this:
The value of the resistor depends on a number of things.
- How much current the LED needs (can be different for all LEDs)
- The voltage drop of the LED (can also be different for all LEDs)
- Your actual supply voltage (should be measured with a multimeter and verified as stable to be sure)
Let’s say you have a small red LED. According to the specs, it needs 20 milliamps (0.02 Amps) and has a voltage drop of 1.7 V. To calculate the needed resistance, we need Ohm’s Law. In as simple of terms as possible, it says that Voltage [V] in (Volts) = Current [I] (in Amps) times Resistance [R] (in Ohms). Or more appropriately for our scenario,
R = V/I
In order to calculate this correctly, you need to obtain V by subtracting the LED voltage drop from the supply voltage [I often hear instructors ignore this part and just use the supply voltage for V, FAIL]. So, if we have a supply of 5V and a drop of 1.7V, V should be 5-1.7 or 3.3V. Since I is 0.02 Amps, R becomes 3.3/0.02 or 165 Ohms. See, this is first grade mathematics! If you can’t find the exact value resistor on the market, you generally want to round it up to be safe. It is always better to supply less current to the component than it is to let the component pull more than it needs. The closest I could find for this scenario was 180 Ohms.
One more thing you may want to consider is the the amount of current you actually wish to supply to the LED. Your datasheet might tell you it needs 20 mA, but you may often find that giving it about 75% of it’s recommended current usually produces no visible difference from full saturation. Do some experimenting to see how much current you actually want to give your LED. You will quickly find that the ratio of brightness to current is not directly proportional and not a ratio at all. So, assuming you want to power this LED at 15 mA, your new resistance value is 220 Ohms. The more LEDs you have, the more important it is to get these values right. If I get the chance, my next post will explain different configurations for hooking up multiple LEDs.
Creating a remote seedbox / mediabox / webserver from an old PC
May 5th, 2009 — Hardware, Software, hack
I know a lot of people have covered this, but I thought I would share my process behind creating my little multifunctional webserver. I had an old tower that I wasn’t really using. It has an Intel chip (Celeron possibly?), 2G of memory, and 2 hard drives [50GB and 500GB]. I also have a decent Nvidia video card with DVI output. I originally just used it as a mediabox. I had it hooked up to my TV, I ripped Netflix movies on my OS X machine using handbrake into an AVI format, then I put them on this system [which is running Ubuntu] and played them using VLC. This was all well and good, but I didn’t like the idea of having a mouse and keyboard hanging around all the time. So I turned to VLC’s command line interface. After playing around for a while, I was able to get the http interface working. I created an alias in my ~/.bashrc as a little macro :
alias vlcrc='export DISPLAY=:0 ; vlc -I http --no-media-library'
** The DISPLAY=:0 may or may not be necessary to get your video card to display to the attached monitor or TV **
After this, I setup SSH for Ubuntu. Then I gave the Ubuntu machine a static ip address [192.168.0.100] through my router’s admin interface [instructions depend on router, GIYF]. Now, from my laptop connected to the same network over Wifi, I am able to SSH into the mediabox, and run something like this:
vlcrc There_Will_Be_Blood.avi
Then I can open up Firefox and go to this URL:
http://192.168.0.100:8080/
and I am presented with this beautiful javascript interface:
It allows you to control everything in your VLC instance like volume, position, fullscreen, pause/play, and etc just like a remote control. The coolest thing for me was that I could control this with my G1 :) If you try this and get a 403 error, you need to configure your .hosts file. Look here : http://www.videolan.org/developers/vlc/NEWS and do a browser search for ‘.hosts’ to see the instructions. You just need to add IPs of computers that want access to the http interface to a whitelist. I just added a bunch of IPs between 192.168.0.101 and 110 b/c I knew my laptops would never get assigned anything out of that range. By this point, I was able to hide the PC behind my TV and not worry about connecting a mouse and keyboard to it. I was able to pick up a DVI to HDMI cable for 10 dollars at Optimized Cable. They are cheap, but adhere to the HDMI 1.3b standard and as long as they are 6 feet or under, you shouldn’t be able to tell the difference between these and the expensive Monster cables.
From here I started to setup the Torrent side of the box. Ubuntu now comes with Transmission which is arguably one of the best clients around. To save yourself from problems later on, make sure it is upgraded to something over 1.5. If you need to update, go to getdeb.net and get transmission-common and transmission-gtk. Download and install them in that order. After you run it, you can go to Preferences –> Web and setup the web interface. I set mine up on port 9091 and then went to this URL from my laptop:
http://192.168.0.100:9091
You are then presented with a cool interface for uploading, controlling, and monitoring your torrents:
This was really helpful but I soon wanted a little more functionality. Wouldn’t it be cool if I could control this from anywhere on the net? Of course. For that, I needed to make this computer visible to net.
The thing that makes this part difficult is the way in which most residential users access the internet. As you may know, accessing a domain name, like datasingularity.com, requires a DNS lookup to find the IP address that the domain is referring to. The problem is that most people don’t keep the same IP address for very long. Much like DHCP on your router, your ISP often assigns you different IPs when you connect to their network. This is called having a dynamic IP as opposed to having a static ‘non-changing’ IP. Since your IP is not always the same, registering a domain for your current IP in some nameservers may not last long. If you are not on a business network and don’t know if you have a static or dynamic IP, we can just assume that you have a dynamic IP. That is why you need the DynDNS service. They constantly update your DNS information for you. You just install a client on your webserver and it tells their service when your IP changes. Kick ass.
You can get a free domain like mydomainname.homelinux.net, or you can pay for a custom one. I went ahead and signed up then registered a free domain. I then followed the instructions at this informative link : http://mexpolk.wordpress.com/2008/01/29/ubuntu-gutsy-dyndns-client-setup/.Then I went to this link :
http://www.portforward.com/routers.htm to set up port forwarding on my DLink DI-604 ethernet router. The first port I set up was port 22. This now allows me to SSH and SFTP to my home computer. Yessss. Then I forwarded the 9091 port to get to my Transmission web interface. If your router supports it, you can forward from port external 80 to port 9091 internal, that way, you can just go here:
http://mydomain.homelinux.net
and it takes you straight to the interface! Otherwise, you need to forward 9091 external to 9091 internal and go here:
http://mydomain.homelinux.net:9091
If you want this to be a regular webserver at the same time, it is best to leave port 80 clear and just use 9091. You have to ensure a few things in your Transmission client. Make sure that you go to Preferences –> Web tab and set it up to require a username and password. You don’t want anyone on the net to just go in and mess with your torrents! Then make sure you disable the IP whitelist so any IP can access it. I think it is just a checkbox somewhere in the Preferences –> Web tab.
I am currently in the process of creating a Rails web application to be served locally. It basically holds all the metadata for my media [tied to imdb web service] and lets me browse my system from another web browser on the same network. I can then click a movie or TV show to play it. It launches a VLC process and the HTTP javascript interface in a new browser window! Not done yet but will keep anyone interested updated.
I am somewhat of an idiot when it comes to security, so anyone please chime in if you see any obvious problems here. Any comments, tips, or criticisms are appreciated.
IRC and Arduino
May 2nd, 2009 — Arduino, Code, Hardware, Java, Leopard, Processing, Python, Software, hack
A while back, I wrote a small python script to act as a proxy between IRC and an Arduino. This video illustrates some of the details.
Here is a zip file with everything to download.
The basic idea was this, the python IRC bot sits in the chat room and waits until someone addresses it’s nick like so:
{NICK}: {command} {arg1} {arg2} ... {etc}
The bot parses the response into a command and a series of arguments. Originally, all this was hardcoded, but through python’s powers of introspection, I realized I could make this way more dynamic. The end result is a framework of sorts. The user can edit the Commands.py file adding functions and settings to his/her specification. The example in the video would be written like this:
#
# module for configuration and commands
#
from Arduinos import Arduino
# Program Settings
DEBUG = True
# IRC Settings
NICK = "arduino"
SERVER = "irc.paraphysics.net"
CHANNEL = "#arduinoroom"
PORT = 6667
# Arduino Settings
USB_PATH = '/dev/tty.usbserial-A7006Qe8'
BAUD = 9600
# define methods
def lightLed(arduino, args):
arduino.send('~') # header
arduino.send(args[0])
arduino.send('~') # terminating
return arduino.read(4) # read 4 bytes from arduino
def readPot(arduino):
arduino.send('}}') # header
return arduino.read(4) # read 4 bytes from arduino
Obviously, you can change the constants to what you need and the daemon picks up on these when it is started. The nice thing about this ‘framework’ is the second half of the script. When you define a method, the IRC bot automagically “understands” it. This is because every time it receives a message directed to it, it calls
reload(Commands)
and reads the function names. So you don’t have to restart the server while developing your functions [An idea stolen from Rails]! Then it parses the message coming in and tries to call the first word as a method and parses the rest of the message into a list. There is no need to worry about the details, what you do need to know to use it is that there are two types of functions, ones with and ones without arguments. The above example illustrates both. Let’s say we define 2 functions:
# define methods
def function1(arduino, args):
print "function1"
print args
def function2(arduino):
print "function 2"
print "no args"
Now, we go into the IRC chat room and issue a command like this:
arduino: function2
The output would be this:
function 2 no arguments
Then lets say we send this:
arduino: function1 hello world!
The bot would parse it and you would see this output:
function1 ['hello', 'world!']
so args becomes a list by splitting the rest of the statement between whitespaces. Your function always needs to have the ‘arduino’ argument. This argument is a custom class I created which looks like this:
import serial class Arduino(): def __init__(self, path='/dev/tty.usbserial', baud=9600): self.ser = serial.Serial(path, baud) def send(self, data): self.ser.write(data) def read(self, bytes): while (1): if (self.ser.inWaiting() > bytes-1): return self.ser.read(bytes) def flush(): self.ser.flushInput()
It is pretty simple, send() sends a string. read() waits for the defined number of bytes to come in and returns the results. To better understand how the example Commands.py script works, take a look at the arduino sketch:
#define LED 13
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (nextByte() == 126) { // header byte ('~' character) led command
char args[] = {0,0,0,0,0,0,0,0,0,0};
char charIn = 0;
byte i = 0;
while (charIn != 126) { // wait for header byte again
charIn = nextByte();
args[i] = charIn;
i += 1;
}
if ((args[0] == 'o') && (args[1] == 'n')) {
digitalWrite(LED, HIGH);
Serial.print("on ");
}
else if ((args[0] == 'o') && (args[1] == 'f')) {
digitalWrite(LED, LOW);
Serial.print("off ");
}
delay(10);
Serial.flush();
}
else if (nextByte() == 125) { // header byte pot command
int val = analogRead(0);
if (val < 10) {
Serial.print(val);
Serial.print(" ");
}
else if (val < 100) {
Serial.print(val);
Serial.print(" ");
}
else if (val < 1000) {
Serial.print(val);
Serial.print(" ");
}
else {
Serial.print(val);
}
}
delay(10);
//if(Serial.available() > 0) {
Serial.flush();
//}
}
byte nextByte() {
while(1) {
if(Serial.available() > 0) {
byte b = Serial.read();
return b;
}
}
}
Yeah, not the cleanest code but hopefully you get the idea. I am not releasing a whole lot of detail on how to use this because I figure If you are using it, then you already know enough about python and Arduino to get by. I have created this to allow for support for firmata but have yet to implement it and probably never will until/if people beg. To run, first get pyserial and irclib.py. Upload the sketch to your arduino and run:
python Main.py
Face detection in Processing
May 1st, 2009 — Code, Java, Processing, Software
Here is a simple sketch I wrote as a joke for a friend. Don’t make fun of the code, I wrote it quick!! Download it here. Download the zip for everything. Probably app only works for os x with iSight. srry.



