November 10, 2005

MIDI

The midi plug that goes into the circuit.

IMG_0540.JPG
IMG_0354.JPG

Thanks to Todd H, I was able to get hold of the 20Mhz Clock. This clock needs to be powered. The square corner pin, has nothing connected to it. The pin on the top right has power going to it, pin on the bottom right is the pin for clock IN. The pin on the bottom left is ground.

Overall the connections were easy to make, the midi cable needs to be connected to the TX pin of the PIC, which is the PortC.6

IMG_0355.JPG

I attempted to use 3 different pots to control the volume, the tones and the speed of the tones being generated by the midi. Code here


HSEROUT [Item {,Item...}]

Send one or more Items to the hardware serial port on devices that support asynchronous serial communications in hardware.
HSEROUT is one of several built-in asynchronous serial functions. It can only be used with devices that have a hardware USART. See the device data sheet for information on the serial output pin and other parameters. The serial parameters and baud rate are specified using DEFINEs:

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h

' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25

IMG_0357.JPG
IMG_0359.JPG


I had a few glitches with some MIDI Synths but overall, I was able to get what I wanted out of this lab.

IMG_0360.JPG
IMG_0361.JPG

What a big mess.

IMG_0362.JPG

Posted by min at 01:24 AM | Comments (0)

November 02, 2005

Motor Lab

Controlling high-current devices from a microcontroller
All about motors
DC Motors
Stepper Motors

The Lab.
DC Motor Control Using an H-Bridge


More of my notes on motors, relay, transistors.

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. With any H-bridge, you will have certain elements:

  • Pins for logic input

  • Pins for Supply voltage

  • Pins for Logic voltage

  • Pins for Supply output

  • Pins for ground

  • I have to admit, I thought I'd have a pretty solid idea of running the motor since i had experienc with making our mid-term that used fans. WRONG. The H-bridge was hard to control as well. The circuit was correct but the motor would not change directions. I hooked up all the wires according to the schematic, programmed and found out the code on Tom's site is a little from from the wiring diamgram. Here's the code that I used for my circuit.Download file
    I also put 2 different LEDs on the pins that connected to the H bridge to confirm that the pins were doing the HIGH and LOW accordingly. However, I saw the LEDs blinking at times and they did not alternate as they were supposed to...

    After reading the lab more carefully, I found out that most motors take a great deal more current than a microprocessor, and hence, need their own supply. I attached a new breadboard for the motor to get its power from, sharing the common ground with the microcontroller.

    IMG_0167.JPG
    IMG_0168.JPG

    Using the transistor was little more easy. Just that the connections got a bit confusing. The important part is that the motor has its external power going to its power pin and that they all share a common ground. The diode should have its white stripe pointing towards the collector.

    IMG_0171.JPG
    IMG_0170.JPG
    IMG_0174.JPG

    I also tried using the pot to control the speed of the motor, instead of the "enable" connection that goes into the first pin of the H-bridge. I don't know if this is possible. Or even safe but the motor did slow down and speed up accordingly. Was I just lucky?

    IMG_0169.JPG


    Posted by min at 10:09 PM | Comments (0)

    October 30, 2005

    Labs

    Tomorrow.
    Crunch-time for pcomp labbing!

    Transistors, relays, midi (will be working on it with Todd M) and the H bridge. Thank you Todd H. You ROCK!

    Transistor schematic

    transistor.jpg

    The relay

    IMG_0130.JPG

    A relay is a switch that's controlled by a small electric current. Relays take advantage of the fact that when you pass an electric current through a wire, a magnetic field is generated surrounding the wire as well. When you place an iron shaft inside a coil of wire and pass current through the wire, the magnetic field moves the iron shaft. If that iron shaft is part of a switch, the switch can be turned on and off by putting current through the coil, which moves the shaft, closing the contact

    H bridge, SN754410NE to control the direction of the DC motor

    IMG_0122.JPG

    DC motor

    IMG_0128.JPG

    There are two terminals, and when you apply direct current to one terminal and ground the other, the motor spins in one direction. When you apply current to the other terminal and ground the first terminal, the motor spins in the opposite direction. By switching the polarity of the terminals, you reverse the direction of the motor. By varying the current supplied to the motor, you vary the speed of the motor.

    H bridge, ULN2004KN for the stepper motor

    IMG_0121.JPG

    The stepper motor. The stepper motor is different from a regular DC motor in that the user could have control over its rotation angle.

    IMG_0126.JPG

    The stepper motor bought from James' garage sale a while ago... 3 dollars! :)

    A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.

    This design allows for very precise control of the motor: by proper pulsing, it can be turned in very accurate steps of set degree increments (for example, two-degree increments, half-degree increments, etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is necessary.

    Posted by min at 01:55 AM | Comments (0)

    October 13, 2005

    Whisker switches doing serial out

    Alice and I have been working on this prototype for a board using whisker switches. We finally got it to work tonight! We just tested out 5 inputs and 5 outs, but we plan on making a 5 by 5 matrix system. We have to plan this out carefully for the final, but essentially, the whiskers (guitar strings) hit the washers on the plexi and act as a switch. We have red LEDs that light up accordingly and red circles that appear on screen (processing).

    We have to think more about the material we use. But today we got the whole three parts working. I will post more about this later on when we have this finally made with a matrix of LEDs and these whisker switches.

    Detail of the washers on the plexi. We had to get a laser cut with counter sinks for these.

    IMG_0002dd.JPG

    Detail of the how the switches work. You simply brush your hand across this plexi.

    IMG_0001.JPG
    IMG_0003ww.JPG
    5555.JPG
    IMG_0007gg.JPG
    e.JPG


    Posted by min at 01:51 AM | Comments (0)

    October 11, 2005

    Serial

    Serial Communication

    In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated circuit, we need a method of communication and an agreed-upon language. The most common form of communication between electronic devices is serial communication. Communicating serially involves sending a series of digital pulses back and forth between devices at a mutually agreed-upon rate. The sender sends pulses representing the data to be sent at the agreed-upon data rate, and the receiver listens for pulses at that same rate.


    Two devices are to exchange data at a rate of 9600 bits per second. First, we would make three connections between the two devices:

    - a common ground connection, so both devices have a common reference point to measure voltage by

    -one wire for the sender to send data to the receiver on (transmit line for the sender)

    -one wire for the receiver to send date to the sender on (receive line)


    The ASCII table
    Serial to Processing
    Serial Output Lab
    Talking to Processing

    Basics, talking to the Pic to convert the ascii into readable numbers.Download file

    Ascii, call and response. In the communicator, only when an "A" (ascii=65) is inputted, it will show "you got me" otherwise, the else goes. Download file

    Here the values of the analog in (ex. pots) gets read and out put as readable values. Download file

    It's funny. We've had this weird problem in the firmware lab. Certain machines simply wouldn't process the codes on the PICBASIC. Instead, I had a problem with PROCESSING. I was getting serial communication when I opened up the Serial Communicator, getting values as I inputted "A" (65 ASCII). The lab was full and I had no choice but to try to figure out what was happening with my code. I tried on someone else's machine and it worked fine! Ah the frustration...

    Here are some pics.

    sp1.JPG

    The analog inputs (pots, flex sensors, pressure sensors, photocells go on the left) A ports. And the communication is done on the C ports 6(Send out, transmit) and 7 (In, receive).

    sp2.JPG

    After compiling, opening up the processing code, pops up this window with the circle. Using the different analog inputs, you can change it's transparancy, xpos and ypos. Cool!
    Here's the code for the pic to talk to processing.Download file

    And this is what you see on the screen.

    sp3.JPG

    The processing code.Download file


    There are so many ways to go further with this. Alice and I had built on my very first electronic assignment.

    We have LEDs, switches and we'd like to have this happen on the screen as well, in processing. Hope we can get this done. The laser cutter cuts so clean! :) We have the coding done, the board is ready, all we need is the plexi now! Getting this done tomorrow! Hopefully, I'll have this done by Thursday.

    Posted by min at 12:14 AM | Comments (0)

    October 06, 2005

    Analog Out

    Analog Output
    We might want to control the brightness of a lamp, for example, or the turn of a pointer on a dial, or the height of something hanging from a rope. In those cases, we need to make an analog output.
    Note: I should really get myself some of those tri-colored LEDs to get the different colorsDownload file .

    Analog output: Servo Control
    Controlling the rotation of the servo using an analog input, such as the pot.


    My board producing frequencies from the pic chip. I programmed the pic so that depending on the force sensor, the LEDs light up accordingly and the FreqOuts vary. I attempted to output two differnent frequencies (like an instrument) from the pic and failed. Todd H advised that this is impossible on a pic, since the pic will only send out one FreqOut...

    IMG_0021n.JPG

    IMG_0024.JPG

    IMG_0024s.JPG

    To amplify the sound from the pic chip, I attached a female stereo mini jack. FAB!

    IMG_0035.JPG
    IMG_0033a.JPG

    The connection into the PIC

    IMG_0036.JPG


    Using the servo. Controlling the servo.Download file

    IMG_0028.JPG

    Now, using a variable resistor to control the servo. Download file

    Using pot to control servo.

    More fun with FreqOuts!
    Pot controls the volume and the force sensor controls the LEDs. Download file

    Posted by min at 01:26 AM | Comments (0)

    September 29, 2005

    Analog In

    Variables
    Variables are places in computer memory for storing changing information.

    Analog In
    When we want to measure variably changing conditions like this, we need analog inputs.

    Lab

    Digital = on or off, 1 or 0 (things such as a switch)
    Analog = the range between on and off (we can get all the different ranges between 1 and 0, such as the wall clock)
    All analog inputs are on the upper left pins of the PIC.


    Since we are using analog ins (variable resistors such as the pot, flex sensors, force senors etc, we need to know what the ranges are)
    To see that, I connected a serial cable to the board and the computer and had the computer print out the values.
    Download file

    The beginning part of the code is to set the chip so that it does the analog ins.

    Serial cable connected the board and you see the 10K potentiometer on the upper left on the analog pins.

    0929 013.jpg
    You can have the pic printout whatever you tell it to. Pretty cool.

    0929 011.jpg

    Also, depending on the variable resistor (see here for different resistors that could be used) that you are using, you may need a pull down resistor. I used the 10K for certain variable resistors.

    IMG_0016a.JPG


    I got tired of having to cram everything onto one board, so I connected another to make more space for my LEDs and other outputs.

    0929 027.jpg

    There go my lights!

    0929 026.jpg

    Using Force Sensors.

    0929 029.jpg


    I got the range from my pot and linked them up accordingly with the LEDs.Download file


    Posted by min at 03:43 PM | Comments (0)

    September 25, 2005

    Different variable resistors

    Carly brought a long some interesting variable resistors on Friday. Here are some examples.


    Picture 028.jpg
    Small pressure sensors.

    Picture 026.jpg
    Picture 025.jpg
    Sliding variable resistors.

    Picture 031.jpg
    Picture 037.jpg

    360 degrees potentiometer. There is a piece of metal that blocks the potentiometer from turning all the way. If you were to remove this, it will become a 360 potentiometer ( a must try).

    Posted by min at 11:08 PM | Comments (0)

    September 21, 2005

    Switches, using body parts

    IMG_0030.JPG
    IMG_0020.JPG
    When the 2 metal sheets are pressed, the lights light up! :)

    And lastly, here are my two switches, involving a body part. The first one is a piece of metal wrapped around my finger with the inner part covered with plastic. As I swipe this switch up and down the bottom part of the breadboard, the LEDs light up accordingly.
    The second switch is my own pressure/ push sensor. I put a piece of sticky foam between two sheets of metal and as the pieces come together, the LEDs will light up.

    I want to experiment with another kind of switch, involving the motion of squeezing. The material I will use is wire mesh. I will post this up once I have it made.

    I realized that wire mesh isn't the best material to work with, if I'm making a squeeze switch. However, I found a cool toy in the junk box. Pic to come soon.


    Posted by min at 04:21 PM | Comments (0)

    September 20, 2005

    Digital Input and output using the microcontroller

    First PIC program

    Second week of pcomp and we've moved on from the basic electronics.
    Half way through Luck's explanation of Programming the PIC, the PicBasic Pro, we had a fire drill at TSOA... My first at NYU. And it was a drill... we didn't see any smoke~

    We covered the following

    Microcontrollers : what they are, different types, levels.
    Intro to PIC and PIC programming
    Digital Input and Output

    For programming the chip, you need the board set up with your Pic Chip and the EPIC. hardware programmer. The programmer will talk to the chip and program the chip.

    IMG_0002.JPG
    This is what the EPIC programmer looks like.

    Basically, after you set up your board, there are two parts to programming. You first write all the programming on the MCS and then using this code, the Epic compiler will send the code into the chip.



    I got my 18F452 way in advance and ordered extras from microchip.com. Free Pic microcontrollers! ^^ Order early in advance. People say it takes about 3-5 business days.


    With programming, we can now make our own codes, use variables (similar to Lingo to execute certain loops)and to control the outputs on the board (the LEDs). I also found out that the best way to keep track of your codes is to forward them to your gmail account and keep them as separate codes.

    So here goes my try... the lab assignment for this week



    LED blinking

    The code:

    Define OSC 4 'clock speed at 4mHz

    output portd.1 'output at pin, portd.1 electricity out

    main:

    low portd.1 'set pin RD1 low
    pause 500
    high portd.1 'set RD1 high
    pause 500

    goto main

    First, since this is not a BX, with a built in clock, we need to define the crystal clock on the board (OSC). It's speed is at 4Mhz.
    So, basically, whatever happens between "main:" and "goto main" loops in the program. This keeps the LED blinking.


    Next step
    connecting a switch into the board to control the LED.

    \

    The layout of the board.
    IMG_0014.JPG

    IMG_0016.JPG

    Between the switch and the microchip and 10k resistor is needed to prevent a short circuit. The switch becomes the input in this system since it will either allow or prevent the flow of electricity into the board.

    Code:


    Define OSC 4 'clock speed at 4mHz

    input portb.0 'this is the switch
    output portd.1 'output at pin, portd.0 electricity out

    main:

    IF portb.0=1 then 'if the switch is closed on pin RB0
    low portd.1 'set pin RD1 low
    else
    high portd.1 'set RD1 high

    endif

    goto main


    Using the IF statments, we are giving conditions to the program. In the condition that the swich is closed, it will either light up or turn off the LED in portd.1

    I googled a few Picbasic Pro codes and saw some interesting ones... This makes a computer-like sound from a buzzer or speaker.

    ' SOUND Command
    '
    ' Make random computer-like noises. More refinement might make sound effects
    ' realistic enough to convince your boss you're working when you're really
    ' just playing Doom!!!


    Define OSC 4

    output portb.7

    Include "bs1defs.bas" ' Include BS1 variables

    SND CON 7 ' Define speaker pin

    loop: 'Random W0 ' Randomize W0
    B2 = (B0 & 31) + 100 ' Generate notes [64..95]
    If B2 >= 50 Then beep ' Make [64..68] silence
    B2 = 40
    beep: Sound SND,[B2,1] ' Generate sound
    Goto loop ' Forever


    ' SLEEP Command
    '
    ' Slowly Blink LED Using Low Power Mode Delay

    define OSC 4

    output portb.2 ' LED Pin

    loop: Toggle portb.2 ' Toggle LED
    Sleep 10 ' Sleep for 10 Seconds (or so)
    Goto loop ' Forever


    LEDs lighting up and down.


    I went onto creating a variable in the code and creating a sequence of lights turning on and off, up and down the line of LEDs.
    The code:

    'using a switch, lights flickering up and down repeatedly

    Define OSC 4

    'this is my switch
    Input portd.1

    TRISB = %00000000 'all the pins on portb OUTPUT

    pauseTime VAR WORD
    pauseTime = 40


    main:

    if portd.1 = 0 then 'if the switch is closed on this pin


    HIGH portb.2
    pause pauseTime
    low portb.2


    HIGH portb.3
    pause pauseTime
    low portb.3

    HIGH portb.4
    pause pauseTime
    low portb.4

    HIGH portb.5
    pause pauseTime
    low portb.5

    HIGH portb.6
    pause pauseTime
    low portb.6

    HIGH portb.7
    pause pauseTime
    low portb.7

    HIGH portb.6
    pause pauseTime
    low portb.6

    HIGH portb.5
    pause pauseTime
    low portb.5

    HIGH portb.4
    pause pauseTime
    low portb.4

    HIGH portb.3
    pause pauseTime
    low portb.3

    HIGH portb.2
    pause pauseTime
    low portb.2




    endif


    goto main


    Here, I've used a variable and declared it before the main:.
    pauseTime VAR WORD
    pauseTime = 40


    TRISB = %00000000 refers to all outputs on portb.

    Posted by min at 10:12 PM | Comments (0)

    September 17, 2005

    First PIC program

    Microchips

    Posted by min at 12:40 AM | Comments (0)

    September 16, 2005

    Intro to Electronics

    First week of Pcomp was definitely intense and nerve wrecking to say the least for me.

    I am so thankful to Carlie, who spared 2 hours out of her busy schedule to go over the material on Friday afternoon. It really helped me in the sense that it was a good review of our Thursday's class. I was able to confirm the ideas learned in class and was able to openly ask questions on site. I strongly recommend this class to everyone. It's like our little pcomp "study group" at ITP! :) The schedule for these mini workshops can be found here

    So here it goes...

    One LED

    The important part here is the voltage regulator. Our power supplies are 12Vs. We are sending 5Vs throughout the breadboard. There are 3 pins in the bottom part of the regulator (IGO).
    It's lit!!! I'm thrilled. :)

    IMG_0102(6596).jpg

    IMG_0089(6405).jpg
    Using a variable resistor, the photocell, this controlled the brightness of the LED. The more the photocell was exposed, the brighter the LED.

    LEDs in parallel
    The brightness of the LEDs are the same. Same amount of voltage going into all the LEDs, when placed parallel.

    IMG_0110(6405).jpg

    Parallel and series on one board
    Todd H helped me out in the lab one day and suggested that I use capacitors before the voltage regulator to smooth out the flow of the electricity. I used the 10uf before the regulator and 1uf that goes into the power of the board. Also, on the other end of the board, I put a single LED to confirm that the board is flowing with electricity. The black things are 2 buzzers that I tested out. Thanks Todd! :)

    IMG_0007(4467).jpg

    IMG_0011(6405).jpg
    Board lit! weeee


    The switch
    I am still working on this. Switch = 2 conductors that allow / stop the flow of electricity. I found this breadboard stripped in the garbage bin, so I decided to use it. (Thanks again Todd!)The bare wires from the board are in contact with the stripped board. When you swipe the metal bolt up and down, the LEDs light up accordingly. I intend to push this idea a little further for our week 002 assignment. I will look into other forms of switches as well.

    IMG_0008(6405).jpg


    In action

    Posted by min at 05:20 PM | Comments (0)