ICM w6: class notes

AJAX: Asynchronous Javascript and XML

Anything after a ? in a URL is data you’re sending to a server

Data sources:

  • https://itp.nyu.edu/ranch/api/projects-finder/arduino
  • https://github.com/ITPNYU/ICM-2017/wiki/Data-Sources
  • https://itp.nyu.edu/registration/alum/linkedInGetRawData.php


e-reader for the hard-of-seeing

For my sanity’s sake, this week I combined the pcomp and ICM assignments: for the former, we were to have three inputs send ASCII data to a p5 sketch; for the latter, we were to manipulate DOM elements.

I decided to make an e-reader of sorts for… people like my parents. People who still squint while wearing 2x magnification glasses and follow the words they’re reading with their fingers so as to not lose their place. So the e-reader should display one sentence of a text at a time, with a way to increase or decrease the font size easily.

I grabbed some random text from Project Gutenberg, but couldn’t figure out how to store a text file into a variable in p5 or javascript, so I just created a <p> tag into the <body> of my index.html file and dumped everything in there. When p5 selects an HTML element, it selects the tag itself, so I couldn’t store the text into an array and split by punctuation like I originally intended. Sooo I cheated by wrapping each sentence in a <p> tag and then containing the entire thing in a <div>. Then I selected all the<p> tags and displayed/hid them by their indexes.

Everything else went relatively smoothly. Arduino buttons would control the displaying of the paragraph tags, and a potentiometer would control the font-size style. Here’s the Arduino code:


And the p5 code: http://alpha.editor.p5js.org/xujenna/sketches/SJd9j9fTZ




pcomp help session: serial communication


  • Serial.write(65): sends one byte (encodes in binary)
    • sends 65
  • Serial.print(65): sends two bytes (sends as a string)
    • sends 54 53
  • serial monitor interprets everything as ASCII


  • callback functions need to be defined in draw()
  • Serial.read() with Serial.write()
  • Println() + readLine()
    • readLine() looks for println() to execute


  1. Serial print values from Arduino
  2. Run p5.serialcontrol app
  3. Include serial.js library in index.html of sketch
  4. create serial object in p5 and define callback functions


Arduino code


p5 code

LM W6: Class Notes

unsupervised learning

  • unsupervised learning is supervised learning, but the output is the same as the input


  • https://github.com/Hebali/learning_machines/tree/master/hyperparameter_hunt
  • main.py: choose hyperparameters that will beget the best accuracy
    • 700 > 600 will result in a more accurate reconstruction than 700 > 5
    • batch size: won’t have too much influence
    • think of value that you think is too small and too large, try both and middle, choose best two values and repeat
    • can layer RBM
    • continuous version allows probabilities; binary compares probability to random number between 1 and 0,  chooses between 1 and 0 based on whether the probability is less
  • Docker: virtual machine
  • launchbot: web interface for that
  • jupyter

Pcomp video notes

Asynchronous serial communication

  • Devices keep time independently, but transmit/receive at the same rate
  • Devices need to agree on:
    1. rate at which data is sent and read
    2. voltage levels (representing 1 or 0 bit)
    3. voltage logic (regular or inverted)
  • Devices connected by three connections:
    1. common ground (so devices have a common reference point to measure voltage by)
    2. one wire as transmit line, for the sender
    3. one wire as receive line, for the reader
  • Arduino transmits spikes in voltage (1 bit * 8 = 1 byte per character) that correspond to binary; binary translates to ASCII
    • two bytes for return and new line characters
  • DIY Protocol: Serial.available(): tells us how many bytes have been received by the Arduino (and stored in the buffer), but not processed
  • analogRead() is 10 bits (0-1023), needs to be divided by 4 inside Serial.write() because Arduino transmits one byte (8 bits, or 0-255) at a time
    • Serial.write() sends data as raw binary, serial monitor in Arduino interprets as ASCII values (interpretation is built-in, makes sending strings easier)
    • println() takes a string, converts it to ASCII
    • Serial.write() sends binary representation, serial monitor converts to ASCII
    • Dec value is base 10, Hex is base 16

Serial Output from Arduino to p5.js

  • control over transmission and reception (we are both sender and receiver)
    • can decide whether an incoming byte should be interpreted as a byte (numerical value), or convert it to ASCII (for a message)
  • Serial handshaking:
    • Arduino sends info 100x/second, which is faster than receiver is processing it
    • handshaking avoids filling up the buffer
    • receiver (p5) sends a byte to transmitter once it’s ready to receive more data: Serial.write('x');
    • transmitter (arduino) waits for the signal: Serial.available() > 0
      • has to send initial signal
  • Reading strings:
    • instead of using Serial.write (which sends raw binary; only holds a single byte so needs to be divided by 4, ie compressed), use print and println to send ASCII data and interpret the string received in p5 as a float

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