Thursday, January 27, 2011

Thursday week 3

Today we spent class time working on programming and testing our vex bots.
We were given a maze and had to program the squarebot to navigate through it. The fisrt time, we simply used timing commands, and saw how inacurate it was. We were put into groups, given rotary encoders and did it again. Programming the robot with shaft encoders results in much more accurate results. The video shows the results of the encoders, and my code posted afterwards.

#pragma config(Sensor, in3,    eleft,  sensorRotation)
#pragma config(Sensor, in4,    eright, sensorRotation)
#pragma config(Motor,  port1,  right,   tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port2,  left,    tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define sec 10000
#define rev 12.56
#define inch 8 //counts
#define foot 105 //counts
//1 count = .1256

void reset()
{
  SensorValue[eleft]=0;
  SensorValue[eright]=0;
}

void goforward(int power, int dist)
{
  while((SensorValue[eleft] < dist*105-100)&& (SensorValue[eright] < dist*105-100))
  {
    motor[right] = 60;
    motor[left] = 60;
  }
  while((SensorValue[eleft] < dist*105)&& (SensorValue[eright] < dist*105))
  {
    motor[right] = 30;
    motor[left] = 30;
  }
  motor[right] = -1;
  motor[left] = -1;
  wait10Msec(10);
  motor[right] = 0;
  motor[left] = 0;

  wait1Msec(1000);
}

void turnleft()
{

  while((SensorValue[eright]<110) && (SensorValue[eleft]<110))
  {
    motor[right] = 50;
    motor[left] = -50;
  }
  motor[right] = 0;
  motor[left] = 0;

  wait1Msec(1000);

}

void turnright()
{
  while((SensorValue[eright]<110) && (SensorValue[eleft]<110))
  {
    motor[right] = -50;
    motor[left] = 50;
  }
  motor[right] = 0;
  motor[left] = 0;

  wait1Msec(1000);
}

task main()
{
  SensorValue[eleft]=0;
  SensorValue[eright]=0;

  while(true)
  {
    goforward(80,4.5);
    reset();
    turnright();
    reset();
    goforward(80,1.8);
    reset();
    turnright();
    reset();
    goforward(80, 3.5);
    reset();
    turnleft();
    reset();
    goforward(80,1.5);
    reset();
    turnleft();
    reset();
    goforward(80,3.5);
    reset();
    turnright();
    reset();
    goforward(80,1.5);
    reset();
    turnright();
    reset();
    goforward(80,5);
    reset();
    turnright();
    reset();
    goforward(80,1.8);


    wait10Msec(800);

    //goforward(100,1000);
  }
}

Wedneday week 3

Today we presented our projects and worked with the 555 timer and oscilloscope. The first thing i did was to build a simple 555 driver circuit to make an LED blink. The circuit is shown at right.
The two potentiometers fine tune the frequency and pulse width output by the 555, and the capacitors are the coarse adjustment. The larger the capacitor the lower the frequency.





I then replaced the LED with a piezo speaker and reduced the capacitance to increase the frequency to audio range. I played with it and viewed the output on the CRO, signal shown left A part of the class portion was to learn how to use an O-scope, but since I already knew how, I spend the time playing with more advanced functions for the 555.

I was partially successful in getting the 555 to control a servo position. I did some basic calculations to get values for resistance and capacitance to get the correct on and off time of the signal. By rotating the larger potentiometer, the position of the servo would change, but i couldn't get a full range of motion.

Wednesday, January 26, 2011

Tuesday week 3 - Hacking a Toy

Today I spent the class time working on hacking my toy. The first thing i wanted it to do was to move the head to the beat of a song. So I built a circuit that took an audio input, passed thru a low pass filter and into the PIC ADC. This way, everything but the kick drum would be filtered out. I wrote a simple program that triggered an output to the motors when the ADC voltage peaked from the kick so the fish would headbang to the beat. It worked quite well for the song I tweaked it to, but had to be tweaked for every song played. I only had 3 I/O pins on my PIC available and eventually disassembled the circuit in pursuit of more user interactive control.

I went back to my old code for moving the fish head around and added some sound capabilities. I wired up the outputs to a speaker and to a darlington transistor for motor control. The fish has 2 functions: "Talk" and "Spaz"
The talk sequence causes the fish to perk up, open it's mouth, and generate a series of random pitches. It's speaks binary! I first had the Pic simply driving a piezo element as a speaker but it simply wasn't loud enough. So I built a simple 1 transistor darlington audio amplifier and used the on-board speaker on the fish. I used the following schematic.



 The circuit:
The code:
main:
    serout 0,N2400,(10,13,"\nI are binary fish")
    serout 0,N2400,(10,13,"Press T for talk, ")
    serout 0,N2400,("Press S to spaz")
    serin 1,N2400,b1
    if b1="s" then spaz
    if b1="t" then talk
    pause 100
goto main
spaz:
    serout 0,N2400,(10,13,"\nHeRpA dErP!")
    for b6 = 1 to 15
        random w0
        w1 = b1/127
        w2 = b1/2
        high 4
        pause w2
        random w0
        w1 = b1/127
        w2 = b1/2
        low 4
        pause w2
    next b6
goto main

talk:
    serout 0,N2400,(10,13,"\n11001010 10011011!!!")
    for b7 = 1 to 50
        high 4      
        random w0
        w1 = b1+500
        sound B.2,(b1,7)
    next b7
    low 4
goto main


Thursday, January 20, 2011

thursday week 2



We talked about transistors and how they can only pass a limited amount of current because of their gain. We first built a circuit which uses a small transistor with low gain to turn on a incandescent 12v bulb. The light is unable to fully illuminate because of the limit of the small transistor. If we use a single larger transistor, the PICAXE is unable to provide enough current to fully "turn on" the transistor. The dimly lit bulb:We can use the small transistor to power the base of the larger transistor. This is the result:
As you can see, much more current gets to the bulb. However, this dual transistor arrangement is commonly used, so we can use an already manufactured transistor called a darlington transistor which is the same thing in a single transistor package.
I used this transistor along with the PIC to control the motors on my fish.

After that I looked at the PWM capabilities of the pic and then serial interfacing with the computer. I wrote a program that allows the computer key presses to send data to the pic which would return the data to the screen. This required building a circuit that could switch between program mode and serial interface mode:
To do that I just have to move the white serial wire between pins on the breadboard. I went home and programmed the pic to turn on and off an LED with a keystroke. And slept.

wednesday week 2

First off we learned some basics of serial communications and soldered together a RS-232 connector to interface the computer with our breadboard. We recieved a PICKAXE microcontroller and began construction of a basic programming circuit. The first program we wrote was to make a simple flashing LED. Here it is functioning with the logic probe showing the switching between high and low:


and the basic code used:
main:
high 1
pause 1000
low 1
pause 1000
goto main

For the next while I familiarized myself with the BASIC programming language, and wrote some other programs. I learned how to interface input sensors both analog (like a CdS cell) and digital (a momentary switch). The following video shows the program i wrote. It senses variable values from the cds cell between 0 and 255; if the values are above a specified threshold (bright), the one LED lights, if it's below a threshold the other LED will light, and if the values are in between, neither will light.

The last thing I did was to crack open a "Billy Bass" singing,talking toy. I cut the motor wires and rerouted them out of the device so i could acess them easily. I then made a simple program for the PIC to make a spazzing mouth movement. I had the signal from the PIC trigger the base of a larger transistor to switch on and off the motors:

Tuesday, January 18, 2011

Tuesday week 2

We started off by introducing the transistor, an electronic switch. The circuit i constructed applied voltage to the base of an NPN transistor, which switched it on, passing the voltage from collector to emitter and turned on the LED.We then replaced the Base resistor with two wires and held them in our fingers. We saw that as we varied the voltage going to the base by squeezing tighter, the LED grew brighter. A transistor amplifies any change in voltage applied to the base and applies it to the emitter as a change in current!

After that, I constructed a basic logic probe. The concept for the basic one is that when the probe is disconnected, the LED is dim, when it recieves a HIGH logic signal (~5v) it goes bright, and when it recieves a LOW (0v) it goes off. This is my basic logic probe receiving a high signal:
After i did that, I spent the rest of the evening working on building the advanced version. The difference is that it uses 2 LED's. When the probe is unconnected, both stay dim. When it receives a high signal, the green LED illuminates, and if it's low, the red LED lights. The circuit uses an NPN and PNP transistor, one for each signal type. The hardest part was choosing the correct value of resistor to match the gain of the transistors and get the correct brightness on the LEDs. The prototype on the breadboard, and the completed perfboard.

Saturday, January 15, 2011

Thursday, week 1

To start off, we talked about mechanical toggles and momentary switches. All switches were double throw switches. I first constructed a simple dual way "light switch" so no matter the state of the switches, flipping one will always change the state of the LED between on/off.

Next thing we did was learn about relays which are just electronic activated switches. I made a circuit which has an LED normally on, then when the relay is switched, it turns off and a different LED is turned on.


Finally we made a buzzer circuit so the relay switched itself off. When power was applied, the relay broke connection to the power, causing it to turn off. But when it turned off, connection was restored and this process repeated very rapidly causing a buzzing action.
The last thing we did was to finish building out vex squarebot and get it driving around. I souped mine up with extra large wheels
.

Thursday, January 13, 2011

Jan 12 - intro to breadboarding

Today we started off with learning how to use a multimeter to measure continuity, resistance, and AC & DC voltages. I tested my power supply and it worked.
Then we went over resistors and potentiometers and breadboarding. Our first circuit was to light an LED thru a resistorAfter that i played with a CdS cell which is basically a light sensitive resistor. The values ranged from roughly 1.0 kΩ to 20 kΩ when fully covered. When put in series with the LED, this was the results:
Uncovered vs Covered:
















Next we discussed schematics and how to interpret them. We then played with different values of resistors to power the LEDs. The lower the resistor value, the brighter the LED, however an LED always needs a resistor otherwise it goes POOF as we found out by blowing one up :-D
We then learned about Kircshoff's voltage law and Ohms law and used them to calculate the required resistor for an LED, given its datasheed and forward voltage. The optimum value for mine was 150Ω:














Finally, we recieved a vex kit and inventoried it and began construction on a squarebot.

Tuesday, January 11, 2011

Building 5v Power supply

Today we went over basic soldering techniques and lab safety. I helped some of the beginners with soldering and modified a phone charger to have a 2 prong solderless breadboard.