Wednesday, April 25, 2012

the end :)

So I spent my whole weekend on writing my instructable. I didn't work on any other class's work because this took so long. You dont realize how many steps went into it til you sit and try to write it out. But it took me more time than it would have because I drew some diagrams in photoshop for steps that I didnt have good pictures for and I linked videos on youtube on how to solder and how a breadboard works so when people like me, or like I was before this class, can do it easily. I published it late Monday night.

I was pretty excited to see that I had 43 views the next morning, so you can imagine how psyched I was when I got an email that my instructable was chosen by the editor to be featured!!! Then I got another email saying the it would be on the homepage! THE HOMEPAGE! Wicked Awesomeness!

I'm so glad its all said and done, but I had a blast! This is my favorite class of my college career :)

Thursday, April 19, 2012

instructables update 4/19

Took the doll to the mall today. Went to show it to all the employees at all the stores that asked for me to come show them when it was done but most of them werent at work today so i will have to go back. I had fun though. I was holding the doll as I walked through the mall and as i passed by people I had the doll turn and look them. I got a few reactions but not many. The fun part came when my kids and I stopped at the food court to eat lunch and i sat the doll on a table a little distance away and followed people as they walked by. That Was GREAT FUN! People walking by in singles barely glanced at it, but people in groups had great reactions. Some jumped, some stopped dead in their tracks and stared. i tried to get a video but everytime i recorded, nothing good happened and when I stopped, there was a great reaction, go figure.

When we passed by a jewerly store some employees noticed the doll and asked me to come show them. They were great and made my day. They loved it and had never ending streams of compliments to give. :)

instructables update 4/17

So i spent all day saturday and most of the day sunday at my parents' house working on this project. My step dad graciously agreed to help me put everything in the doll. He didn't like me taking pictures though so that was a battle, but I got some. It took forever and lots of trial and error but we got it working. It doesnt work to my expectations and Im kida disappointed but no way am I going to fool with it and chance messing it up.

The head only turns from side to side and that motion is limited, it doesnt have the full 180 degree range I was hoping for, but it does move so good enough.












Saturday, April 7, 2012

wireless kama chuk code


#include <Wire.h>
#include <string.h>
#include <stdio.h>
uint8_t outbuf[6];
int cnt = 0;
int ledPin = 13;
int servoPin = 5;
int servoPin2 = 6;
int pulseWidth = 0;
int pulseWidth2 = 0;
long lastPulse = 0;
long lastPulse2 = 0;
int z_button = 0;
int c_button = 0;
int refreshTime = 20;
int minPulse = 1000;
int minPulse2 = 500;
int dtime=10;
#define pwbuffsize 10
long pwbuff[pwbuffsize];
long pwbuffpos = 0;
long pwbuff2[pwbuffsize];
long pwbuffpos2 = 0;
void setup()
{
    Serial.begin (19200);
    Wire.begin ();
    nunchuck_init ();
    pinMode(servoPin, OUTPUT);
    pinMode(servoPin2, OUTPUT);
    pulseWidth = minPulse;
    pulseWidth2 = minPulse2;
    Serial.print ("Finished setup\n");
}
void nunchuck_init()
{
    Wire.beginTransmission (0x52);
    Wire.send (0xF0);
    Wire.send (0x55); 
    Wire.endTransmission ();
    delay(30);
   
    Wire.beginTransmission(0x52);
    Wire.send (0xFA);
    Wire.endTransmission();
    delay(30);
 
    Wire.requestFrom(0x52, 6);
    delay(30);
}
void send_zero()
{
    Wire.beginTransmission (0x52);
    Wire.send (0x00);
    Wire.endTransmission ();
}
int t = 0;
void loop()
{
    t++;
    long last = millis();
    if( t == 1) {
        t = 0;
        Wire.requestFrom (0x52, 6);
        while (Wire.available ()) {
            outbuf[cnt] = nunchuk_decode_byte (Wire.receive ());
            digitalWrite (ledPin, HIGH);
            cnt++;
        }
        if (cnt >= 5) {
            //            printNunchuckData();
            int z_button = 0;
            int c_button = 0;
            if ((outbuf[5] >> 0) & 1)
                z_button = 1;
            if ((outbuf[5] >> 1) & 1)
                c_button = 1;
            switch (c_button) {
            case 1:
                switch (z_button) {
                case 0:
                    break;
                case 1:
                    muovi();
                    break;
                }
                break;
            case 0:
                switch (z_button) {
                case 0:
                    delay(10000);
                    break;
                case 1:
                    delay(3000);
                    break;
                }
                break;
            }
        }
        cnt = 0;
        send_zero();
    } // if(t==)
    updateServo();
    delay(dtime);
}

void updateServo() {
    if (millis() - lastPulse >= refreshTime) {
        digitalWrite(servoPin, HIGH);
        delayMicroseconds(pulseWidth);
        digitalWrite(servoPin, LOW);
        digitalWrite(servoPin2, HIGH);
        delayMicroseconds(pulseWidth2);
        digitalWrite(servoPin2, LOW);
        lastPulse = millis();
    }
}
int i=0;
void printNunchuckData()
{
    int joy_x_axis = outbuf[0];
    int joy_y_axis = outbuf[1];
    int accel_x_axis = outbuf[2]*2*2; // * 2 * 2;
    int accel_y_axis = outbuf[3]*2*2; // * 2 * 2;
    int accel_z_axis = outbuf[4]*2*2; // * 2 * 2;
    int z_button = 0;
    int c_button = 0;
    if ((outbuf[5] >> 0) & 1)
        z_button = 1;
    if ((outbuf[5] >> 1) & 1)
        c_button = 1;
    if ((outbuf[5] >> 2) & 1)
        accel_x_axis += 2;
    if ((outbuf[5] >> 3) & 1)
        accel_x_axis += 1;
    if ((outbuf[5] >> 4) & 1)
        accel_y_axis += 2;
    if ((outbuf[5] >> 5) & 1)
        accel_y_axis += 1;
    if ((outbuf[5] >> 6) & 1)
        accel_z_axis += 2;
    if ((outbuf[5] >> 7) & 1)
        accel_z_axis += 1;
    Serial.print (i,DEC);
    Serial.print ("\t");
    Serial.print ("X: ");
    Serial.print (joy_x_axis, DEC);
    Serial.print ("\t");
    Serial.print ("Y: ");
    Serial.print (joy_y_axis, DEC);
    Serial.print ("\t");
    Serial.print ("AccX: ");
    Serial.print (accel_x_axis, DEC);
    Serial.print ("\t");
    Serial.print ("AccY: ");
    Serial.print (accel_y_axis, DEC);
    Serial.print ("\t");
    Serial.print ("AccZ: ");
    Serial.print (accel_z_axis, DEC);
    Serial.print ("\t");
    Serial.print (z_button, DEC);
    Serial.print (" ");
    Serial.print (c_button, DEC);
    Serial.print ("\r\n");
    i++;
}
char nunchuk_decode_byte (char x)
{
    x = (x ^ 0x17) + 0x17;
    return x;
}
void muovi (){
    float tilt = (700 - outbuf[3]*2*2);
    float tilt2 = outbuf[2]*2*2;
    tilt = (tilt);
    pulseWidth = (tilt * 5) + minPulse;
    tilt2 = (tilt2-288);
    pulseWidth2 = (tilt2 * 5) + minPulse2;
    pwbuff[pwbuffpos] = pulseWidth;
    pwbuff2[pwbuffpos2] = pulseWidth2;
   
    if( ++pwbuffpos == pwbuffsize ) pwbuffpos = 0;
    if( ++pwbuffpos2 == pwbuffsize ) pwbuffpos2 = 0;

    pulseWidth=0;
    pulseWidth2=0;
    for( int p=0; p<pwbuffsize; p++ ){
        pulseWidth += pwbuff[p];
        pulseWidth2 += pwbuff2[p];
    }
    pulseWidth /= pwbuffsize;
    pulseWidth2 /= pwbuffsize;
}

solder plan

instructables update April 5

So I played around the code again and again and I got it working for the forth time. I wasnt getting my hopes up though since the other 3 times it worked, it stopped. After loading different code and reloading the working code it still worked and after powering down and back up it still worked!!! FINALLY! So Willie drew out a solder plan and I helped him solder wires to the breadboard. When it was test time....... it didnt work. We checked all the wiring and it was fine and we reset the arduino and still it didnt work. I was about to give up on this code again when Willie figured it out. When he held down the reset button and connected the wireless nunchuk before releasing the reset button it worked just fine. So, the nunchuk must be initiated before the program starts running.

With this information, its clear that I need a momentary push button switch for a reset button and a toggle switch for an on/off button. I also need something to make the doll more rigid to mount the servo.

Next step is to get the new materials I need and start puting the hardware in the doll.

instructables catch up April 3

Worked the whole class with Thomas and Willie trying to figure out the problem with the code. Nothing we tried would work and we were all feeling frustrated and miffed so we stopped for the day.