Kazu's class journal

ITP Spring 2006

Introduction to Physical Computing

H79.2301.02 Michael Schneider




week 07: Talking to a MIDI device


step 01

instructions: Connect a MIDI out circuit to your microcontroller.


step 02

instructions: Connect an analog sensor to one of the ADC pins of the Pic and use it to generate a value from 36 to 96. Put it in a variable called something useful like noteVar. Confirm that noteVar is actually changing reliably when you affect the sensor, using a debug statement. Connect your MIDI circuit to a MIDI synthesizer and hear what happens.


The MIDI was so fun. At first, I need some time to understand controlling input data from an analog sensor in a program for the MIDI. Finally, through my original device, I could get the data from an analog sensor, input it into the algorithm of the code correctly, and generate a sound.





week 06: DC Motor Control Using an H-Bridge


step 01

instructions: Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor.


step 02

instructions: Connect the motor to the H-bridge.


After checking the direction change by reversing the polarity of the motor, I put a H-bridge on the circuit and observed the direction. But, I still used my hands...




step 03

instructions: Program the microcontroller to run the motor through the H-bridge.


I controlled the motor direction through the microcontroller and the H-bridge instead of my hands.





week 05: Serial Output and Talking to Processing


step 01

instructions: Connect a serial cable between the appropriate pins of your microcontroller and ground. Program the microcontroller to send a string of serial information out reading a switch. See what comes up in the window.




step 02

instructions: Connect an analog sensor to one of your analog inputs. Read its value and send it out the serial port. Modify the program.


I confirmed the basic settings for the serial out.




step 03

instructions: Replace the mouse on your computer with a new device that you build. Make an application using at least two sensors, controlling two elements of a screen interface.


This step was so fun. However, since I forgot to turn off my circuit, there was something wrong with it. The power regulator became extremely hot. I needed to change the power regulator, resistors and capacitors. Although I had the minor problem, a Processing code was fine. An ellipse was moving on the screen depending on the input form potentiometers. After trying the simple code, I changed my more complex two drawing codes that I had written before. First, a curve is changed depending on two pods. Second, a creature like slime moves on the screen.



define OSC 4

define ADC_BITS 8
define ADC_CLOCK 3
define ADC_SAMPLEUS 20

ADCON1 = %00000010
TRISA = %11111111

redLed  var portd.1
blueLed var portd.0
txPin   var portc.6
rxPin   var portc.7

OUTPUT  redLed
OUTPUT  blueLed
OUTPUT  txPin
INPUT   rxPin

potVarX var byte
potVarY var byte
start   var byte
inbyte  var byte

for start = 0 to 5
    redLed = 1
    pause 200
    redLed = 0
    pause 400
next

main:
    serin2 rxPin, 16468, [inbyte]
    high blueLed
    if inbyte = 65 then 
        high redLed
        adcin 0, potVarX
        adcin 1, potVarY
        serout2 txPin, 16468, [potVarX, potVarY]
    endif
    low redLed
    Low blueLed

goto main

This code is for the serial. If you are interested in the codes for the curve and the slime, could you check the following links? But, they do not include codes for the serial.

* Slime

* Wind and Visibility of Cities




week 04: Analog Output


step 01

instructions: Connect a servomotor to your PIC. Program the PIC to control it using the code from the servo examples. Note that this code just moves the servo from one end to the other of its travel, then resets it and starts over.




step 02

instructions: Connect an analog sensor (potentiometer, variable resistor) to any of pins the analog pins of your microcontroller as shown in the analog input lab assignment. Program the microcontroller to convert its range into a value that you can use to control the servo. A few changes are needed.


The process of changing the code ran smoothly. The servo worked well.



define OSC 4
define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

start:
    arf var byte
    pulseWidth var byte         
    minPulse con 50
    maxPulse con 250
    refreshPeriod con 20
    pulseRange var word
    sensorValue var word 
    pulsewidth = minPulse
    pulseRange = maxPulse - minPulse

output portc.3
ADCON1 = %10000010  

for arf = 0 to 3
    high portc.3
    pause 100
    low portc.3
    pause 200  
next  

main:
    adcin 0, sensorValue
    low portc.3
    pwm portc.3, PulseWidth, 1
    pause refreshPeriod

    if pulseWidth > maxPulse then
        pulseWidth = minPulse
    else
        pulseWidth = minPulse + (pulseRange * (sensorValue/10))/100
    endif
	
goto main

step 03

instructions: PicBasic Pro have a command, freqout, that allows you to generate a tone from any of the I/O pins. When a speaker or amplifier is connected properly to the pins, the tone can be heard.


Although the code is fine, the servo control was difficult to figure out the changing analog output. I tried to make the tone generation circuit. This was more fun than the servo control. If the sound had been melodious, it would have been more attractive...



define OSC 4
define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

start:
    arf var byte
    freq var word      
    minfreq con 500
    maxfreq con 1500
    refreshPeriod con 20
    sensorValue var word       
    freq = minfreq

output portc.3
ADCON1 = %10000010    

for arf = 0 to 3
    high portc.3
    pause 100
    low portc.3
    pause 200  
next  
   
main:
    adcin 0, sensorValue
    low portc.3
    freqout portc.3, 1000, freq, freq
    pause refreshPeriod
    
    if freq > maxfreq then
        freq = minfreq
    else
        freq = minfreq + sensorValue
    endif

goto main



week 03: Variables and Analog Input


step 01

instructions: Connect a potentiometer up to pin RA0 of your PIC 18F452. On the PIC, you'll also need to connect wires to pins RC6 and RC7 to a DB9 serial connector, and connect it to the computer's serial port.


Since I did not know how to see the data from a serial port, I was at a loss in front of a computer for a while... But, after figuring out the way to see it, the fundamental rule of analog input was easily understandable because I could see the changing values on the computer.


DEFINE ADC_BITS     10
DEFINE ADC_CLOCK    3
DEFINE ADC_SAMPLEUS 50

ADCvar var word

TRISA = %11111111
ADCON1 = %10000010
pause 500

main:
    ADCIN 0, ADCvar
    SEROUT2 portc.6, 16468, [DEC ADCvar, 13, 10]
goto main



step 02

instructions: Connect another variable resistor RA0 or your PIC. Try differing values for the fixed resistor in the circuit. Note how they change the value returned by getADC(). Try using a potentiometer instead of the fixed resistor (the center pin and either one of the side pins will do)





step 03

instructions: Use an analog sensor (a pot or other variable resistor) in an application. Perhaps the changing value of a sensor affects how many lights or motors are turned on or off; perhaps a seven-segment LED display is used to generate numbers. Or a practical joke with the BX-24. Make a sensor that lights a series of LEDs only after you affect it beyond a certain threshold, or a step pad that lights up only after the user steps away. Use variables to keep track of the changes of the switches and analog sensors as the user interacts with the project.


I think monitoring the input data will be useful to identify errors if I have some problem with my projects.





week 02: First Pic Program


step 01

instructions: Connect an LED and a 220 ohm resistor in series with each of the eight pins on your microcontroller (5 to 12 on a BX-24, portd.0 to portd.7 on a PIC 18F452). Connect the end of the LED to ground.


This is my first code: turn on and off.


DEFINE OSC 4

start:
    output portd.1
    
main:
    high portd.1
    pause 1000
    low portd.1
    pause 1000
    
goto main



step 02

instructions: Connect a switch (or several switches) any of pins of your microcontroller.


I added "if then" statement to put a switch. Since my switch was a closed type switch(that means electricity flows when you turn it off), I needed to change the code I had written.




step 03

instructions: Combine switches and LED's to make a more complex application. Make a puzzle or a combination lock using your switches. Use the LED's to give the user visual feedback. Or think about incorporating ripple effects, where one switch affects many outputs.


1. Combination Switch: when pushing both switches, you can turn on LED's. In other case, you cannot.



DEFINE OSC 4

start:
    input portb.7
    input portb.5
    output portd.1
    
main:
    if portb.7 = 0 and portb.5 = 0 then
        high portd.1
        pause 1000
        low portd.1
        pause 1000
    endif
    
goto main

2. Ripple Effects: LED's blink successively.



DEFINE OSC 4

start:
    input portb.7
    output portd.1
    output portd.2
    output portd.3
    output portc.4   
    output portc.5
    
main:
    if portb.7 = 0 then
        high portd.1
        pause 100
        low portd.1
        pause 100
		
        high portd.2
        pause 100
        low portd.2
        pause 100
		
        high portd.3
        pause 100
        low portd.3
        pause 100
		
        high portc.4
        pause 100
        low portc.4
        pause 100
		
        high portc.5
        pause 100
        low portc.5
        pause 100
    endif
    
goto main 



week 01: Basic Electronics


step 01

instructions: Make a light that you control with a switch. Wire an LED in series with a switch, a resistor, and a 5V DC power supply, and make the switch turn on the LED.


This is my first circuit. Hmm...very simple.




step 02

instructions: Make a light that you control with a switch. Wire an LED in series with a switch, a resistor, and a 5V DC power supply, and make the switch turn on the LED.


Since LED's share voltage in a series circuit, the two LED's darker than the LED in the step 01. Of course, three LED's don't work because the power supply is not sufficient.

I tried other situation to reconfirm the rule just in case. I put six LED's in series with a 12V DC power supply. They work, and it makes sense.




step 03

instructions: Wire an LED in series with a variable resistor and a fixed resistor and a 5V DC power supply.


I put a photoresistor in the circuit instead of a flex sensor. The brightness changes depending to shade on the photoresistor.




step 04

instructions: Experiment with different combination of switches and pots in parallel and series with LED's. Come up with an interesting application of electronic pieces: a combination lock, a puzzle, a trip switch, or something of your own devising. Try making your own switch as well, using two conductors as the contacts.


Making a combination of switches and my original switches was not big deal...

Through making a parallel circuit, I could understand other rules: the input amount of current is the same as the output amount, but voltage is not changed.


It is the first time that I made Pcomp stuff. I could enjoy it even though LED's just blinked.