pcomp w6 class notes

serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels.

smoothing: averages analog input to a smooth curve

asynchronous serial basics: for all serial connections, you need 1) physical connection, 2) logic level, 3) transmission rate, 4) interpretation

  • each device has its own “clock” (baud rate)
  • baud rate (transmit/receive rate): speed of bit transmission

*consistently 1023 reading = short circuit; erratic/inconsistent readings means bad connection to ground

*one byte value (2^8) = 255

pcomp video notes

prototyping tips:

  • wire wrapper for sensors not meant for soldering
  • drill to twist wires
  • solid core wire is rigid; stranded core wire is more flexible but needs to be soldered to a header pin
  • panel-mount components just screw-on


  • difference between wires (solid core, stranded, smaller wires for wrapping, ribbon cables, jumper wires)
  • ribbon cable to permaboard intermediary
  • panel-mounted vs board-mounted controls
  • how do arduino shields work (stacking)

pcomp help session: soldering

electrical tape to keep wires from touching

mouser, digikey for components; McMaster-Carr for ideas


  • can’t solder aluminum or steel (acid core soldering)
  • clamps
  • silver bearing vs lead solder
  • NASA student workbook for hand soldering: https://nepp.nasa.gov/docuploads/06AA01BA-FC7E-4094-AE829CE371A7B05D/NASA-STD-8739.3.pdf
  • three tools need: wire stripper, needle-nose pliers, wire cutters (copper only= soft metals only= silver, lead, aluminum)
    • consult components about how much insulation to strip from wire
  • Steps for splicing wires:
    1. strip wire of insulation, twist wires together (no twisting for lap joints)
    2. solder iron transfers heat (650-700F for the Wellers); flashing LED means at temperature
    3. melt silver bearing to tip to form a bead of solder, add to joint
    4. add solder to joint—move silver bearing, not solder
    5. pull tools away immediately
    6. clean solder iron tip regularly (needs to be shiny)
    7. add heat shrink tubing (yellow bin) over joint
  • add solder to take solder away (new hot solder flows the old solder)
  • stranded core wire will not go into a breadboard
  • perma-proto breadboard PCB for long-term projects
  • flux pens helps remove extra solder
  • pixel tape (some have direction)

pcomp: wk5 class notes


  • current: amps
  • charge potential: volts
  • resistance: ohms
  • frequency: hertz
  • duty cycle: %
  • pulse width: ms (time)

PWM: duty cycle changes, pulse width changes, frequency (tone() changes frequency)

Other microcontrollers

  • particle spark: wifi, javascript
  • arduino BT connects over bluetooth

analog conversion notes

Analog input:

  • analog to digital conversion: voltage to digital number at a resolution of 10 bits (2^10; ie takes 0-5 volts and breaks it into 0-1023 parts)
  • voltage = digital number * (5/1023)
    • smallest change it can read is 5/1023, or 0.048 volts
  • analogRead(pin);
    • pint is the analog input pin
    • reading will be between 0 and 1023

Analog “Output” (PWM):

  • analogWrite(pin, duty);
    • pin refers to the pin you’re pulsing
    • duty is a value from 0-255— 8 bits (2^8; corresponds to 0-5 volts)
    • every one-point change changes the voltage by 5/255, or  0.0196 volts

Pcomp: W4 HW pt 2

So my theremin from Friday basically ended up a keyboard, so I figured I might as well complete the thought. All I needed to do was remove the photoresistor and add a few more buttons, right? Here’s what I started with:

It worked! Kind of. So I attempted to create a full keyboard, but the eighth key didn’t fit in my breadboard…

Despite lining up the resistors in increasing order, the readings seemed to be all over the place (~970, ~8, ~510, ~698, ~930, ~970, ~1023)—hence the notes coming in at random when the keys are played in order. Hopefully it’s only a matter of replacing a few faulty resistors…

Here’s the code:

Update: DONE!

Okay not really, as the speaker makes it completely impossible to actually play the keys. But that’s nothing a trip to Tinkersphere can’t fix.

Final update:

pcomp w4 hw

For this week’s homework, I thought it would be cool to make a theremin. Since the only appropriate sensor I had for this endeavor was a photoresistor, it would have to be a light theremin. Here was the game plan:

Readings from the photoresistor would feed into the Arduino as an analog input, which would then map to digital output via PWM, causing the piezo to emit varying tones.

Well, it worked, but the theremin sounded god-awful and insufferably loud to boot, so I decided to add a potentiometer next to the piezo in order to adjust the voltage (ie, the volume).

Somewhat better, but the sound was still so grating that I also wanted to be able to turn it off. Lacking a slide switch, I added a button, which obviously is not the same thing.

Not a great solution, and I’m quickly growing tired of this theremin. I like the button though, so I’ll probably try to make some sort of keyboard instead.

pcomp help session notes

Pulse Width Modulation:

  • Digital microcontrollers can’t produce a varying (analog) voltage; can only produce high or low
    • PWM is a “fake” analog voltage produced by a series of voltage pulses at regular intervals
    • switch flips on and off (arduino does it 250x a second)
      • width of pulses is “on”: called pulse width
    • not actually lowering the voltage; it is pseudo-analog output
  • duty (output) 0 – 255; arduino voltage is 0-5
    • maps duty to voltage; every change of one point changes the output voltage by 5/255 (because 255 duty corresponds to 5 volts)
    • 50% duty cycle when on and off is the same; effective voltage is half the total voltage
      • pwm_50_percent
    • if duty cycle is less than 50% (ie, pulses for a shorter amount of time than it pauses), the effective voltage is lower
      • pwm_33_percent

Transistors are switches


Analog Output

pcomp office hours w/ chino

pulldown resistor

pulldown resistor

  • switch is after power supply; input pin goes HIGH when pressed because voltage from power source is able to flow through to input pin
    • digital input is path of least resistance after a switch > goes HIGH
  • “pulls” random inputs from digital/analog input to ground
  • stabilizes the input signal


pullup resistor with LED and code (reads a digital input and turns on an LED when input goes HIGH)

pull up resistor

  • pull up resistor equalizes voltage between digital input and power source
  • switch is before ground; when button is pressed, input pin goes LOW because current can then flow to ground

pcomp w4 class notes

Pulse width modulation:

  • voltage turns on and off, etc
  • pulse width: time that it’s on
  • duty cycle: proportion of time that it’s on or off
  • looks at duty cycle (amount that it’s on vs amount that it’s off over the length of the wave) and uses variation to communicate to some other device


Potentiometer: different values as it turns
Servo: uses the pulse width to determine the position; microchip looks at pulse width that comes in from arduino, changes the direction

Servo connected to a potentiometer 

When you have one frequency of sound, it’s one sound; if you’re able to change the frequency with pulse width modulation, you can make music