pcomp midterm

For the pcomp midterm, I agreed to help my friend Ilana make a jukebox for her boyfriend’s birthday. The jukebox would feature her boyfriend’s original music, each activated by a specific, sentimentally associated photograph. Each photograph would close their song’s switch via copper tape applied to its back. This project seemed like a challenging learning experience, so I was happy to work with her.

Because of time limitations, we ran over to Tinkersphere to buy an mp3 shield. This turned out to be an immediately regrettable decision, because there was very little documentation, the provided link to the datasheet was broken, and the library—incredibly—didn’t work.


Luckily, Aaron (our miracle-worker of a resident) was able to hack the Adafruit mp3 shield library (sorry Adafruit) to work with our questionable Tinkersphere purchase. Unfortunately, that only opened the floodgates of pain and suffering, as there was still a lot of crazy mp3 shield logic deal with (delays, booleans for each song, the concept of interrupts and how they apply to serial communication…). Eventually, many office hours (thanks Yuli and Chino) and even more if statements got the job done. However, we weren’t able to figure out how to get combinations of switch states to allow for more songs.

preview of the madness

So we hooked this up to push buttons to test the code, then threw together a rough prototype to test the technical concept:


With the circuit working, it was time to work on the enclosure. We bought a utensil tray from The Container Store (shout out to this video), and laser cut an interface, first with cardboard:

Then with acrylic:

To create a product independent from the computer, we hooked the circuit up to a battery, which was hooked up to an on/off switch. We had some trouble with the switch—we bought a strange 3-state one from Tinkersphere—and ended up borrowing one of Barak’s after completely ruining it (ie Ilana burning herself and melting the plastic after a short circuit!).

Transferring the circuit to the box was a struggle, and for the next iteration we have to switch to the multi-stranded wire, because as it is with the solid-core wiring, the box doesn’t close. But at least the circuit works:

Now for some sleep…

LM W6: Class Notes


(Adam optimizer helps avoid local minima)


  • sessions are run-time environments (what happens in your session, stays in your session)

convolutional neural network

  • https://en.wikipedia.org/wiki/Kernel_(image_processing)

recurrent neural network:

  • sequence to sequence


  • language in vector space; can perform algebra on concepts
    • king – man + woman = queen
  • https://en.wikipedia.org/wiki/Principal_component_analysis

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