Tuesday, September 27, 2011

Check one two...

Testing blogspot's mobile update feature. This should be nifty since i already use my phone to take the pictures. Btw, the included picture is from Example 6A, which isn't quite working right, I'm guessing because I've got the wrong resistor hooked up to the sensor. This would be much easier if I weren't red/green colorblind...

Monday, September 26, 2011

The Evolution Will Not Be Televised...

...but it will show up on your blogroll. CSCI 4560 (Evolutionary Computing) has been taking up a lot of my time lately. And it's been fairly kicking my butt. But I will persevere, and it will be well worth my time. Why? Because it could be instrumental in the final design of the pedal powered video game controller.

In case you don't know, the term "Evolutionary Computing" is a lot more like it sounds like than it sounds like. When I first heard about the class, I assumed it was either a history-like class, or dynamic programming of some sort. Most people I've told about the class think it must be something other than the obvious -- computing which mimics evolution and genetics. Think about it: If you need to solve a problem that involves a large number of variables and a complex goal, searching through the possible combinations can be a nearly impossible task. Even designers can be wrong about where to optimize.

But if you think of each variable as a "gene" which can have a range of values and think of an individual as the result of a combination of these variables, you can create a population of "individuals" which compete, breed, and mutate, and improve.

For example, if I were to design a bike and I wanted to maximize power output and minimize cost and weight, given various combinations of wheel size, materials used, resistance, etc., those various variables (genes) would make up the individual which is the bike, and the "fitness" of the bike could increase when power output increases and decrease when cost or weight increases. You can look for individuals within a given range or which break a record or... well, anything you want. This is a typical example of a "knapsack problem" (maximizing value while minimizing cost), which happen to be one of the prime uses for evolutionary computing.

Of course, more research is in order to determine where to start, but it's possible that this could design a controller which outputs power enough to rival other methods while being cheap enough to rival with other video game peripherals...

Sunday, September 18, 2011

Fade in, Fade out

Example 4 showed us how to fade an LED in and out (like a Macbook while it's sleeping, I hesitate to exemplify). This is essentially simple. The Arduino's analog outputs allow you to send an integer between 0 and 255 which corresponds to pulse-width modulation, which in turn corresponds to the brightness of the LED. So looping an integer variable from 0 to 255 and back with a 10ms delay allows the LED to fade in and out every half second or so. I have no pictures because I got ahead of myself and started building the next circuit, but luckily the circuit necessary for Example 5 happens to combine the circuits from Examples 4 and 3. Let's take a look:

Rather a quintopus of a circuit
Though it's hard to distinguish given the quality of my cell phone's camera (Dirty South), the button circuit from the last example has basically been pushed to the right and connected to an LED circuit. This is an example of how basic elements can be joined together to make a more complex whole.

So now, when you press the button, it turns on or off. When you hold the button while turning it on, the brightness changes. This is done by checking to see whether the button has been held for longer than 500ms and whether the light is currently on.

Next time, we control the LED based on some more continuous analog input: a light-dependent resistor.

And after that, we connect a few LEDs to the internet and alter them based on RSS info... and then on to the meat -- the Vitamaster itself.

Monday, September 5, 2011

More Pushbutton Action

Moving right along, Exercise 3 involves a button that stays on after you let go of the button. Sounds simple enough, but the exercise is a three-step trial and error process:

In trial one, if the button is pressed down, you change the state of the light from on to off or vice versa:

void loop(){
    val = digitalRead(BUTTON); //read input value and store it

    if (val == HIGH){ //if there is voltage coming in from the button
        state = 1 - state; //change the state, which later is used to
    }                      //turn the light on or off 

    //...etc...
}


But since instructions are executed so rapidly, if the button is held for more than a split second, the "state" of the light will change as many hundreds of a second as you held it. The next example attempts to fix this by making sure there has actually been a transition:

void loop(){
    val = digitalRead(BUTTON); //read input value and store it

    if ((val == HIGH) && (old_val == LOW){ //check for transition
        state = 1 - state;
    }                     

    
    old_val = val; //now remember whether the button was pressed
    //...etc...
}



This works to some extent, but there is still a problem: when you press a button, the spring within it bounces and contact is made and broken a few (short) times in a fraction of a second. The final revision of Example 3 includes "simple debouncing" by including a delay of between 10 and 50 ms (I used 25) after the state change. The result is a working pushbutton light.

Push button (and release), receive light!

Example 3 complete!

Thursday, September 1, 2011

Getting Started with the Arduino

In order to use the Arduino, I must first learn it. Luckily, Make Magazine and the cofounder of Arduino put out a nifty book entitled Getting Started with the Arduino. And someone was also nice enough to put a parts package together on Amazon, containing everything you'll need to go through the book.

A nifty starter pack
The first exercise went by so fast I forgot to take a picture. It was basically the "Hello World" of the circuit world: make an LED blink once per second. Exercise 2 would be nearly just as simple, as long as you're not color deficient. I understand that resistors are color coded because they were too tiny to print numbers on, but trying to differentiate between brown, red, and green paint on a 2mm surface under lamp light at night (and on a beige table no less) is no easy task for a red/green colorblind like myself. But I made it work. I'll have to get a second opinion on the rest of my resistors, and keep them sorted and labeled. 

Anyway, Exercise 2 implements a pushbutton for the light, which stays on as long as the button is held. Welcome to your keychain penlight. Mystery solved. 

Light off...

Light on!
That's all for now! Join us next time, when we look into the guts of the Vitamaster itself.


Hacking the Vitamaster: Introduction

Throughout this semester, I will be turning a 15+ year old Vitamaster exercise bike into a videogame controller. In particular, I will be measuring the rotational speed of the wheel and using that data (via an Arduino Uno) to control some aspect of a videogame. If time permits, more control aspects will be added to the bike. It would be nice to do more than control forward motion, after all.

[image: the Vitamaster in all its haggard glory]

This blog will act as my research journal, a semiformal confidant through the good times and bad, tracking my progress and/or struggles, and possibly acting as a guide to others in some fashion.